DataLoader 模块“numpy”中的迭代错误没有属性“expand_dim”

问题描述 投票:0回答:1

我想迭代抛出火车装载机,但我面临这个问题,对此错误有任何帮助吗。

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'
python numpy pytorch dataloader pytorch-dataloader
1个回答
0
投票

看起来您试图重写 PyTorch 中的 Dataloader 类并实例化一个名为“trainloader”的类。当您重写 Dataloader 类时,您犯了一个拼写错误。你有expand_dim,单数,它应该是expand_dims,复数。

返回 trainloader 所基于的类定义,并将该行更新为“expand_dims”

© www.soinside.com 2019 - 2024. All rights reserved.