1、AttributeError: ‘numpy.float64’ object has no attribute ‘backward’
自定义的loss需要转成tensor形式
loss = torch.tensor(loss)
2、RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
不在一个设备
poses = poses.to(device=torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
3、RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
参数丢失了 requires_grad属性,所以导致没能梯度更新。
loss = torch.tensor(loss, requires_grad=True)
4、AttributeError: ‘list’ object has no attribute ‘cuda’
列表list没有cuda属性,要转为tensor
target = np.array(target) # list转numpy.array
target = torch.from_numpy(target)
5、TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <U104
for idx, sample in enumerate(train_loader):
发现是__getitem__函数设计的时候存在一个变量是字符串,改成array即可