首页 技术 正文
技术 2022年11月13日
0 收藏 621 点赞 4,697 浏览 1616 个字

1.

UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
return F.log_softmax(x)

解决方法:把 F.log_softmax(x)改为F.log_softmax(x,dim=0) , 而且我发现改为F.log_softmax(x,dim=1),这个到底哪个更合理需要进一步确认。

2.

UserWarning: invalid index of a -dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a -dim tensor to a Python number  train_loss += loss.data[]  

解决方法:把 train_loss+=loss.data[0]  修改为 train_loss+= loss.item()

3.

UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
label = Variable(label.cuda(), volatile=True)

解决方法:把 label = Variable(label.cuda(), volatile=True)  修改为   label = Variable(label.cuda())

   接下来的几个问题是我真实的代码中产生的,并且按如上的方法解决了

4.

遇到的警告:
UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
data, target = Variable(data, volatile=True), Variable(target)解决方法:把data, target = Variable(data, volatile=True), Variable(target)修改为
data, target = Variable(data), Variable(target)

5.

遇到的警告:
UserWarning: invalid index of a -dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a -dim tensor to a Python number
test_loss += F.nll_loss(output, target, size_average=False).data[]解决方法:把data[]改为item()
test_loss += F.nll_loss(output, target, size_average=False).item()重新运行,报了另一个警告,
UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.
warnings.warn(warning.format(ret))
看了警告中的提示信息,意思size_average这个参数和reduce这个参数都将会将被不赞成。请使用reduction='sum',
所以我就把test_loss += F.nll_loss(output, target, size_average=False).item()改为
test_loss += F.nll_loss(output, target, reduction='sum').item()
这样运行后就没有报警告了。其实我用pycharm右键去找nll_loss这个函数的定义的地方会发现。警告中的提示信息提示的
非常到位。以下展示下nll_loss函数的定义:

记录下pytorch代码从0.3版本迁移到0.4版本要做的一些更改。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,961
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,485
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,330
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,113
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,746
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,780