zoukankan      html  css  js  c++  java
  • 记录下pytorch代码从0.3版本迁移到0.4版本要做的一些更改。

    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())  

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

    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 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
      test_loss += F.nll_loss(output, target, size_average=False).data[0]
    
    解决方法:把data[0]改为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函数的定义:

  • 相关阅读:
    phpmyadmin设置密码,不用登录直接进入
    如何将本地文件复制到远程服务器听语音
    win7 64位wamp2.5无法启动MSVCR110.DLL丢失听语音
    最大连接数:60 iops:150 什么概念?
    北京可以备案什么域名
    远程桌面命令是什么 如何使用命令连接远程桌面
    如何知道电脑是几核?
    nohup命令与&区别,jobs,fg,bg,Ctrl-Z、Ctrl-C、Ctrl-D
    Shell 文件包含
    Shell 输入/输出重定向
  • 原文地址:https://www.cnblogs.com/www-caiyin-com/p/9953833.html
Copyright © 2011-2022 走看看