Scene-Graph-Benchmark.pytorch icon indicating copy to clipboard operation
Scene-Graph-Benchmark.pytorch copied to clipboard

AttributeError: module 'torchvision' has no attribute 'datasets'

Open PrimoWW opened this issue 2 years ago • 10 comments

❓ Questions and Help

hello, thank you for the great job. when i run the command bash train.sh Language_VG_Uniter a problem happened below:

Traceback (most recent call last):
  File "tools/relation_train_net.py", line 19, in <module>
    from maskrcnn_benchmark.data import make_data_loader
  File "/home/liujingwei/icme/sgg_from_nls/maskrcnn_benchmark/data/__init__.py", line 2, in <module>
    from .build import make_data_loader, get_dataset_statistics
  File "/home/liujingwei/icme/sgg_from_nls/maskrcnn_benchmark/data/build.py", line 14, in <module>
    from . import datasets as D
  File "/home/liujingwei/icme/sgg_from_nls/maskrcnn_benchmark/data/datasets/__init__.py", line 2, in <module>
    from .coco import COCODataset
  File "/home/liujingwei/icme/sgg_from_nls/maskrcnn_benchmark/data/datasets/coco.py", line 39, in <module>
    class COCODataset(torchvision.datasets.coco.CocoDetection):
AttributeError: module 'torchvision' has no attribute 'datasets'

I dont know if the torchvision is wrong or something happened.

PrimoWW avatar Oct 17 '22 09:10 PrimoWW

Hi, have you managed to fix this problem? I have the same issue here.

Infinitywxh avatar Dec 05 '22 14:12 Infinitywxh

I have the same problem, did you find a solution?

farahFif avatar Jan 25 '23 10:01 farahFif

I have the same problem, I had tried many versions of torchvisions, but the problem remains. Did you find a solution?

explorer-shy avatar Feb 05 '23 13:02 explorer-shy

I solved this problem, first by having the right torch, torchvision and torch audio. Then the mistake I made is to put all repos in one folder which created some sort of conflict. So make sure that apex and cocoapi are cloned in different folder than scene graph.

farahFif avatar Feb 08 '23 08:02 farahFif

I solved this problem, first by having the right torch, torchvision and torch audio. Then the mistake I made is to put all repos in one folder which created some sort of conflict. So make sure that apex and cocoapi are cloned in different folder than scene graph.

Can you tell me more about how you solved it

David1-git avatar Mar 07 '23 11:03 David1-git

I solved this problem, in the file https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch/blob/master/INSTALL.md,the author wrote down this code

# install PyTorch Detection
cd $INSTALL_DIR
git clone https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch.git
cd scene-graph-benchmark

# the following will install the lib with
# symbolic links, so that you can modify
# the files if you want and won't need to
# re-build it
python setup.py build develop

However, I misunderstood it. I mistakenly thought that it didn't matter to the project whether or not to run the code python setup.py build develop.

So, if you meet the problem "AttributeError: module 'torchvision' has no attribute 'datasets'" , just don't forget to run this code python setup.py build develop and you will solve it.

Also, if you change GPU after you build this project ,you need to delete the directory build and file maskrcnn_benchmark/***.so, and then re-build it to develop these files.

By the way, I also sovled a problem I met. The problem is "ImportError: cannot import name 'amp' from 'apex' (unknown location)" , you can follow this guide https://stackoverflow.com/questions/70547501/importerror-cannot-import-name-amp-from-apex-unknown-location-jupyter-la to solve this problem I mentioned.

explorer-shy avatar Apr 11 '23 09:04 explorer-shy

Recently I have the same problem. I have tried the methods mentioned above and still cannot solve it. It seems that the codes import the wrong torchvision package: <module 'torchvision' from '/home/xxx/.cache/torch_extensions/py39_cu116/torchvision/torchvision.so'>. Could someone share some useful solutions? I would deeply appreciate it.

zhangce01 avatar Sep 12 '23 01:09 zhangce01

Recently I have the same problem. I have tried the methods mentioned above and still cannot solve it. It seems that the codes import the wrong torchvision package: <module 'torchvision' from '/home/xxx/.cache/torch_extensions/py39_cu116/torchvision/torchvision.so'>. Could someone share some useful solutions? I would deeply appreciate it.

hi, I have met the same problem. Have you solved it?

lalalisa666 avatar Oct 16 '23 06:10 lalalisa666

I solved this problem, in the file https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch/blob/master/INSTALL.md,the author wrote down this code

# install PyTorch Detection
cd $INSTALL_DIR
git clone https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch.git
cd scene-graph-benchmark

# the following will install the lib with
# symbolic links, so that you can modify
# the files if you want and won't need to
# re-build it
python setup.py build develop

However, I misunderstood it. I mistakenly thought that it didn't matter to the project whether or not to run the code python setup.py build develop.

So, if you meet the problem "AttributeError: module 'torchvision' has no attribute 'datasets'" , just don't forget to run this code python setup.py build develop and you will solve it.

Also, if you change GPU after you build this project ,you need to delete the directory build and file maskrcnn_benchmark/***.so, and then re-build it to develop these files.

By the way, I also sovled a problem I met. The problem is "ImportError: cannot import name 'amp' from 'apex' (unknown location)" , you can follow this guide https://stackoverflow.com/questions/70547501/importerror-cannot-import-name-amp-from-apex-unknown-location-jupyter-la to solve this problem I mentioned.

I did this, but the problem still happened. This made me crazy.

draym28 avatar Apr 02 '24 13:04 draym28