当前位置:网站首页>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)
边栏推荐
猜你喜欢
泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
我的驾照考试笔记(2)
KDD2022 | 自监督超图Transformer推荐系统
WeChat applet cloud development | personal blog applet
仿牛客论坛项目
STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障
Buttons with good user experience should not have hover state on mobile phones
【节能学院】数据机房中智能小母线与列头柜方案的对比分析
【节能学院】推进农业水价综合改革的意见解读
【节能学院】智能操控装置在高压开关柜的应用
随机推荐
[Personal Work] Remember - Serial Logging Tool
Debug一个ECC的ODP数据源
Determine a binary tree given inorder traversal and another traversal method
【Social Media Marketing】How to know if your WhatsApp is blocked?
tiup mirror merge
Acrel-5010重点用能单位能耗在线监测系统在湖南三立集团的应用
】 【 nn. The Parameter () to generate and why do you want to initialize
专利检索常用的网站有哪些?
【无标题】
1374. 生成每种字符都是奇数个的字符串 : 简单构造模拟题
Buttons with good user experience should not have hover state on mobile phones
我的驾照考试笔记(4)
大神经验:软件测试的自我发展规划
Multithreaded producers and consumers
Custom command to get focus
Common pits in the Go language
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
To promote energy conservation institute 】 【 the opinions of the agricultural water price reform
仿牛客论坛项目
【无标题】