AttributeError
一、‘Upsample’ object has no attribute ‘recompute_scale_factor’
进入upsampling.py文件,找到对应的forward()函数

直接把最后一个属性recompute_scale_factor删除即可
二、‘Hardswish’ object has no attribute ‘inplace’
进入activation.py文件,找到forward()函数,将reuturn语句中的self.inplace删除即可

TypeError
can’t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
进入报错的文件 _tensor.py,找到 array(self, dtype=None)函数

将两个return语句后面的self.numpy() 改成 self.cpu().numpy()即可

因为GPU中的tensor得先放在CPU中才能转换成numpy数据,因为numpy是cpu only。
本文档介绍了在使用PyTorch时遇到的两种常见错误:'Upsample'对象没有'recompute_scale_factor'属性和'Hardswish'对象没有'inplace'属性。解决方案分别是在upsampling.py和activation.py文件中删除相应属性,以及在_tensor.py文件中修改将CUDA tensor转为numpy数据的方法。确保在将GPU上的tensor转换为numpy数组前先将其移到CPU上。
2548

被折叠的 条评论
为什么被折叠?



