pytorch 属性错误:模块"torch.utils"没有属性"data"

icnyk63a  于 2023-02-22  发布在  其他
关注(0)|答案(2)|浏览(512)

我正试图在Ubuntu服务器上运行我的PyTorch代码,它在我自己的电脑上运行得很好,但是在服务器上运行失败了。
这是因为PyTorch版本相关的东西吗?
这个问题看起来很典型,但没有有效的解决方案。

Traceback (most recent call last):
  File "train.py", line 12, in <module>
    from data_manager import *
  File "/data1/lijun/cross_modal_reid_bigma/transformer/data_manager.py", line 7, in <module>
    from util.data_loader import DataLoader
  File "/data1/lijun/cross_modal_reid_bigma/transformer/util/data_loader.py", line 6, in <module>
    from torchtext.legacy.data import Field, BucketIterator
  File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/__init__.py", line 3, in <module>
    from . import datasets
  File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/datasets/__init__.py", line 2, in <module>
    from .ag_news import AG_NEWS
  File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/datasets/ag_news.py", line 2, in <module>
    from torchtext.data.datasets_utils import _RawTextIterableDataset
  File "/usr/local/anaconda3/lib/python3.6/site-packages/torchtext/data/datasets_utils.py", line 205, in <module>
    class _RawTextIterableDataset(torch.utils.data.IterableDataset):
AttributeError: module 'torch.utils' has no attribute 'data'
n3ipq98p

n3ipq98p1#

这对我很有效...请确保您使用的是1.7 + pytorch版本

dced5bon

dced5bon2#

当使用Pytorch 1.1时,您可以通过添加以下导入来简单地解决这个问题:

import torch.utils.data

而Pytorch 1.7+已经修复了这个bug。

相关问题