【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