1. 算术运算报错 can’t multiply sequence by non-int of type ‘float’
原因:用了float数据进行数乘,需要用iny型数据
根本原因:python2中 A/B 返回int型数据,而python3中 A/B 返回float型数据
解决方案:把 A/B 改为 A//B 即可
2. IndexError: invalid index of a 0-dim tensor. Use tensor.item()
in Python or tensor.item<T>()
in C++ to convert a 0-dim tensor to a number
原因:使用了loss.data[0]
解决方案:loss.data[0] 更改为loss.item() ;如果是其他tensor提示,改成tensor.item()
3. TypeError: Caught TypeError in DataLoader worker process 0.错误
原因:dataloader的num_workers出现错误
解决方案:修改dataloader的num_worker为0即可