首页 > 其他 > 详细

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

时间:2018-11-13 18:53:40      阅读:323      评论:0      收藏:0      [点我收藏+]

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 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number  

train_loss += loss.data[0]  

解决方法:把 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())  

 

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

原文:https://www.cnblogs.com/www-caiyin-com/p/9953833.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!