PyTorch奇奇怪怪的问题(一)

报错:

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).
  target = torch.tensor(target, dtype=torch.long)

报错语句

target = torch.tensor(target, dtype=torch.long)

修改为

target = torch.as_tensor(target, dtype=torch.long)

你可能感兴趣的:(python)