-
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(torch.from_numpy(feature), dtype=torch.float32)
改为:
feature = torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)
- RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 ‘mat1’ in call to _th_addmm
解决方法:
feature = torch.tensor(torch.from_numpy(feature))加上, dtype=torch.float32
feature = torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)
或者
#在代码前添加一行,将输入的数据转成是dtype=torch.float32的。
#X= torch.tensor(X, dtype=torch.float32)
output = net(X)
3.TypeError: ‘