参考博客
【精选】python 中各类型介绍及相互转换 - list, array, tensor, dict, tuple, DataFrame_dict转tensor-CSDN博客
1 # list -> numpy
scores = np.array(scores) # list -> numpy
2 # numpy -> tensor
scores = torch.tensor(scores) # numpy -> tensor
遇到问题
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
RuntimeError:期望所有张量都在同一设备上,但发现至少有两个设备,cuda:0和cpu!
这说明上面list->np->tensor的数据还是在CPU上面
3 scores.cuda()
遇到问题
RuntimeError: Found dtype Double but expected Float
运行时错误:发现dtype Double但期望Float
输出dis
标签是双浮点型float64,期待是float32
4
scores.to(dis.dtype)
scores.to(torch.float32)