当前位置:   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博客】
推荐阅读
相关标签
  

闽ICP备14008679号