当前位置:网站首页>Variable与Tensor合并后,关于训练、验证的相关变化
Variable与Tensor合并后,关于训练、验证的相关变化
2022-04-21 17:52:00 【燃烧吧哥们】
Variable与Tensor合并后,关于训练、验证的相关变化
原本是打算自己写一下的,但后来发现有篇文章写的很全,这里给出合并前与合并后的代码对比,并在结尾处给出文章的链接
0.4.0 版本以前
model = Net()
if use_cuda:
model = model.cuda()
# train
total_loss = 0
for input, target in train_loader:
input, target = Variable(input), Variable(target)
if use_cuda:
input, target = input.cuda(), target.cuda()
outputs= model(input)
loss = criterion(outputs,target)
total_loss += loss.data[0]
# evaluate
for input, target in test_loader:
input = Variable(input, volatile=True)
if use_cuda:
...
...
0.4.0 版本及以后:
device = torch.device("cuda" if use_cuda else "cpu")
model = Net().to(device)
# train
total_loss = 0
for input, target in train_loader:
input, target = input.to(device), target.to(device)
outputs= model(input)
loss = criterion(outputs,target)
total_loss += loss.item()
# evaluate
with torch.no_grad():
for input, target in test_loader:
...
简单来说就是去掉了Variable操作和.data.
Variable和Tensor合并后,PyTorch的代码要怎么改?
.data在pytorch中仍然有用吗?
版权声明
本文为[燃烧吧哥们]所创,转载请带上原文链接,感谢
https://blog.csdn.net/hjkdh/article/details/124225482
边栏推荐
- 来自TMDB的5000部电影数据集
- C ODBC loads the files of one folder into the blob column of PostgreSQL database and downloads the blob column to another folder
- 为什么基础设施工程师更喜欢MySQL?
- 有奖征文 | 重奖5000元,邀您投稿
- Fonctions communes pour MySQL Advanced
- How to get the map value is not so low. There are three ways to get the map parameters
- Brief introduction of common methods of wireless DoS attack
- STM32 learning notes - sub second value calibration of RTC
- 百度地图、腾讯地图、高德地图经纬度转换
- VS2019 visual studio 终端调试乱码问题
猜你喜欢
本田北美产品规划发布!Insight混动停产,CR-V、雅阁即将发布

漏洞检测与防御:Redis未授权访问漏洞复现

5000 movie datasets from tmdb

看完这篇教程,你将拥有自己的一个卫星(diy全程详解)

终于有人讲明白了!原来这才是全球低时延一张网技术

Zhongang Mining: a new and active application field of fluorite resources

MP40N120-ASEMI场效应管MP40N120

Addition, deletion, modification and query of MySQL advanced table

Dynamic programming: coin topic summary

单片机diy作品鉴赏,初学者进来膜拜
随机推荐
Longitude and latitude conversion of Baidu map, Tencent map and Gaode map
ASE35P03-ASEMI场效应管35P03
MySQL数据库常识之储存引擎
谷歌投放手机端一直收集不到转化目标怎么回事?
Addition, deletion, modification and query of MySQL advanced table
SQL命令 DELETE(一)
怎么获取map值才不那么low,获取map参数的三种方式
林肯Z对比奥迪A4L:产品力差距,其实是两个时代的缩影
Akismet插件教程WordPress阻止过滤垃圾邮件插件
LogStash~LogStash的执行模型
手机日期插件 (转加上自己喜欢的)
启牛理财课有用嘛?安全靠谱嘛?
Why do infrastructure engineers prefer MySQL?
Thesis | attention based bidirectional long short term memory networks for relation classification
Query the employee information of non business department employees who joined in 2021. Comrades, how to write SQL statements and solve them
Logstash ~ logstash one-stop tutorial (continuously updated)
直播app源码,在无法显示图片的基础上添加图片显示功能
华为URPF
Akismet plugin tutorial WordPress prevent spam filtering plugin
头条自媒体运营秘籍,坚持下去你就可以打败90%的人