当前位置:网站首页>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)
边栏推荐
猜你喜欢

【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)

Debug一个ECC的ODP数据源

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
![[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)](/img/7d/f8f150ad13f4cacc143491fcd8420b.png)
[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)

卷积神经网络(CNN)mnist数字识别-Tensorflow

面试突击70:什么是粘包和半包?怎么解决?
![[Personal work] Wireless network image transmission module](/img/64/c0cec74692df7ca05c1a5317e21c9d.png)
[Personal work] Wireless network image transmission module

【节能学院】智能操控装置在高压开关柜的应用

Interview Blitz 70: What are sticky packs and half packs?How to deal with it?

Where should I prepare for the PMP exam in September?
随机推荐
WhatsApp group sending actual combat sharing - WhatsApp Business API account
如何用Chrome编辑以及调试代码
多线程之生产者与消费者
idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换
What is the difference between a utility model patent and an invention patent?Understand in seconds!
1374. 生成每种字符都是奇数个的字符串 : 简单构造模拟题
AQS原理和介绍
Godaddy domain name resolution is slow and how to use DNSPod resolution to solve it
Zheng Xiangling, Chairman of Tide Pharmaceuticals, won the "2022 Outstanding Influential Entrepreneur Award" Tide Pharmaceuticals won the "Corporate Social Responsibility Model Award"
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)
LinkedList源码分享
Use WeChat official account to send information to designated WeChat users
Redis does check-in statistics
Interpretation of the meaning of each dimension of two-dimensional, three-dimensional, and four-dimensional matrices
StringTable Detailed String Pool Performance Tuning String Concatenation
泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
字符串
MySQL语法基础
Failed to re-init queues : Illegal queue capacity setting (abs-capacity=0.6) > (abs-maximum-capacity