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)