详细的警告如下:
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)
其实就是在将某个变量转成tensor过程中指定变量类型警告!
如果在转为tensor时需要改变变量类型需要用下面的语句
torch.as_tensor(torch.from_numpy(feature), dtype

这篇博客讨论了在PyTorch中将变量转换为tensor时遇到的一个UserWarning,推荐使用`.clone().detach()`或`.clone().detach().requires_grad_(True)`而不是直接使用`torch.tensor()`。作者提醒,当需要改变变量类型时,应当使用`torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)`。博客内容主要针对深度学习初学者,旨在帮助他们避免常见的编程陷阱。
最低0.47元/天 解锁文章
4393





