zoukankan      html  css  js  c++  java
  • 关于Pytorch报警告:Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead

    在使用Pytorch的时候,遇到警告的日志打印:

    [W IndexingUtils.h:20] Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead. (function expandTensors)
    [W ..atensrcATen ativecudaLegacyDefinitions.cpp:55] Warning: masked_scatter_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead. (func
    tion masked_scatter__cuda)

    虽然不影响使用,但是由于满屏的警告,使得覆盖了重要的输出信息。

    解决办法:

    在StackOverflow上,看到有回答:

     在自己的代码中,找到 mask 将其 .byte( ) 改为 .bool( ) 即可。

    mask = autograd.Variable(torch.zeros((a, b))).byte()  

    改为:

    mask = autograd.Variable(torch.zeros((a, b))).bool()  

    一般问题都是出现在对 loss的自动求导上。

    修改完后,发现训练速度都快很多:

    Before:

     After:

    可以看到,因为不需要每一步都打印警告日志,训练速度比之前快很多。



  • 相关阅读:
    python 登录与注册
    python 深浅拷贝
    列表|字典|集合推导式
    正则表达式——笔记
    Python thread
    allure报告自定义logo和名称
    回归测试用例编写思路
    测试用例规范【如何编写测试用例】
    git与pycharm的使用详解(git+gitlab+pycham)
    接口自动化
  • 原文地址:https://www.cnblogs.com/luo-c/p/14320991.html
Copyright © 2011-2022 走看看