当前位置:网站首页>Pytorch框架学习记录13——利用GPU训练
Pytorch框架学习记录13——利用GPU训练
2022-08-01 20:36:00 【柚子Roo】
Pytorch框架学习记录13——利用GPU训练
使用GPU训练的两种方法
- 方法1
数据(输入、标注) 损失函数 模型 .cuda()
# 创建网络模型
test = Test()
test = test.cuda()
# 定义损失函数
loss_fn = torch.nn.CrossEntropyLoss()
loss_fn = loss_fn.cuda()
imgs, target = train_data
imgs = imgs.cuda()
target = target.cuda()
imgs, target = test_data
imgs = imgs.cuda()
target = target.cuda()
output = test(imgs)
- 方法2
.to(device)
Device = torch.device("cpu")
或 torch.device("cuda")
torch.device("cuda:0")
指定第一张显卡
# 定义训练的设备
device = torch.device("cuda:0")
# 创建网络模型
test = Test()
test = test.to(device)
# 定义损失函数
loss_fn = torch.nn.CrossEntropyLoss()
loss_fn = loss_fn.to(device)
for train_data in train_loader:
imgs, target = train_data
imgs = imgs.to(device)
target = target.to(device)
for test_data in test_loader:
imgs, target = test_data
imgs = imgs.to(device)
target = target.to(device)
边栏推荐
- Redis does check-in statistics
- [Personal work] Wireless network image transmission module
- 自定义指令,获取焦点
- [Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
- Buttons with good user experience should not have hover state on mobile phones
- 大神经验:软件测试的自我发展规划
- 9月备考PMP,应该从哪里备考?
- Little data on how to learn?Jida latest small learning data review, 26 PDF page covers the 269 - page document small data learning theory, method and application are expounded
- 【无标题】
- 扣减库存方案
猜你喜欢
随机推荐
研究生新同学,牛人看英文文献的经验,值得你收藏
To promote energy conservation institute 】 【 the opinions of the agricultural water price reform
tiup mirror clone
myid file is missing
Use WeChat official account to send information to designated WeChat users
我的驾照考试笔记(4)
【Dart】dart构造函数学习记录(含dart单例模式写法)
Acrel-5010重点用能单位能耗在线监测系统在湖南三立集团的应用
myid file is missing
[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)
SIPp installation and use
Which websites are commonly used for patent searches?
Batch get protein .pdb files based on Uniprot ID/PDB ID
解除360对默认浏览器的检测与修改
自定义指令,获取焦点
Does LabVIEW really close the COM port using VISA Close?
【Untitled】
Different operating with different locks, rounding
The configuration manual for the secondary development of the XE training system of the missing moment document system
Addition, Subtraction, Multiplication of Large Integers, Multiplication and Division of Large Integers and Ordinary Integers