当前位置:   article > 正文

Pytorch报警告UserWarning: To copy construct from a tensor_userwarning: to copy construct from a tensor, it i

userwarning: to copy construct from a tensor, it is recommended to use sourc

详细的警告如下:
  UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).

feature = torch.tensor(    , dtype=torch.float32)
  • 1

  其实就是在将某个变量转成tensor过程中指定变量类型警告!
  如果在转为tensor时需要改变变量类型需要用下面的语句

torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)
  • 1

参考文献

[1]pytorch神经网络的小问题
[2]使用新版PyTorch运行《动手学深度学习》中的代码

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/272285
推荐阅读
相关标签
  

闽ICP备14008679号