【PyTorch】Pytorch踩坑记


pytorch踩坑记


错误1: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).

# bug :
feature = torch.tensor(torch.from_numpy(feature), dtype=torch.float32)
# debug :
# 改为:
feature = torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)

错误2:RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 ‘mat1’ in call to _th_addmm

# debug :
feature = torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)

错误3:UserWarning: Using a target size (torch.Size([64])) that is different to the input size (torch.Size([64,1]))

# debug :
# 在forward(self, x)函数体中,在return x之前,加一句
x = x.squeeze(-1)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM