我想迭代抛出火车装载机,但我面临这个问题,对此错误有任何帮助吗。
for imgs, mask in trainloader:
print(imags.shape)
print(masks.shape)
break
AttributeError Traceback (most recent call last)
<ipython-input-31-22799795e016> in <module>()
----> 1 for imgs, mask in trainloader:
2 print(imags.shape)
3 print(masks.shape)
4 break
5 frames
/usr/local/lib/python3.7/dist-packages/numpy/__init__.py in __getattr__(attr)
312
313 raise AttributeError("module {!r} has no attribute "
--> 314 "{!r}".format(__name__, attr))
315
316 def __dir__():
AttributeError: module 'numpy' has no attribute 'expand_dim'
看起来您试图重写 PyTorch 中的 Dataloader 类并实例化一个名为“trainloader”的类。当您重写 Dataloader 类时,您犯了一个拼写错误。你有expand_dim,单数,它应该是expand_dims,复数。
返回 trainloader 所基于的类定义,并将该行更新为“expand_dims”