loss训练记录

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即可

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值