Traceback (most recent call last): File "C:\Users\sxq\PycharmProjects\pythonProject\main.py", line 99, in <module> img_transformed = apply(img, torchvision.transforms.RandomErasing(p=0.9, scale=(0.2, 0.33), ratio=(0.3, 3.3), value='random'),"zg10_") File "C:\Users\sxq\PycharmProjects\pythonProject\main.py", line 38, in apply Y = [aug(img) for _ in range(num_rows * num_cols)] File "C:\Users\sxq\PycharmProjects\pythonProject\main.py", line 38, in <listcomp> Y = [aug(img) for _ in range(num_rows * num_cols)] File "C:\Users\sxq\AppData\Roaming\Python\Python310\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "C:\Users\sxq\AppData\Roaming\Python\Python310\site-packages\torchvision\transforms\transforms.py", line 1748, in forward x, y, h, w, v = self.get_params(img, scale=self.scale, ratio=self.ratio, value=value) File "C:\Users\sxq\AppData\Roaming\Python\Python310\site-packages\torchvision\transforms\transforms.py", line 1697, in get_params img_c, img_h, img_w = img.shape[-3], img.shape[-2], img.shape[-1] File "C:\ProgramData\anaconda3\lib\site-packages\PIL\Image.py", line 529, in __getattr__ raise AttributeError(name) AttributeError: shape. Did you mean: 'save'?
时间: 2023-06-30 18:19:01 浏览: 193
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
根据报错信息,出现了 AttributeError: shape,意味着程序试图在一个没有 shape 属性的对象上调用该属性。根据代码,这个错误可能是因为 img 不是一个 Numpy 数组或 PyTorch 张量,而是一个 PIL 图像对象。PIL 图像对象没有 shape 属性,而应该使用 size 属性。你可以更改代码,将 img.shape 改为 img.size 或者将 PIL 图像对象转换为 Numpy 数组或 PyTorch 张量。
阅读全文