当前位置:网站首页>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)
边栏推荐
猜你喜欢
![[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)](/img/a1/ec038eeb6c98c871eb31d92569533d.png)
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)

Postman 批量测试接口详细教程

进行交互或动画时如何选择Visibility, Display, and Opacity

Imitation cattle forum project

MySQL语法基础

98.嵌入式控制器EC实战 EC开发板开发完成

【nn.Parameter()】生成和为什么要初始化

【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)

用户身份标识与账号体系实践

To promote energy conservation institute 】 【 the opinions of the agricultural water price reform
随机推荐
基于FPGA的任意字节数(单字节、多字节)的串口(UART)发送(含源码工程)
【Untitled】
idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换
What is the difference between a utility model patent and an invention patent?Understand in seconds!
Application of Acrel-5010 online monitoring system for key energy consumption unit energy consumption in Hunan Sanli Group
任务调度线程池-应用定时任务
【个人作品】无线网络图传模块
瀚高数据导入
useful website
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
Goroutine Leaks - The Forgotten Sender
Debug一个ECC的ODP数据源
Redis does check-in statistics
通俗解释:什么是临床预测模型
tiup mirror init
StringTable详解 串池 性能调优 字符串拼接
【torch】张量乘法:matmul,einsum
面试突击70:什么是粘包和半包?怎么解决?
[Personal work] Wireless network image transmission module
AQS原理和介绍