简体   繁体   中英

Error with _DataLoaderIter in torch.utils.data.dataloader

I want to run a code which needs to import _DataLoaderIter from torch.utils.data.dataloader . By checking the source code for dataloader class, that method exist. However, I get the error:

Traceback (most recent call last):

File "main.py", line 4, in

import data

File "D:\\Hyperspectral Data\\RCAN\\RCAN_TrainCode\\code\\data\\__init__.py", line 3, in module

from dataloader import MSDataLoader

File "D:\\Hyperspectral Data\\RCAN\\RCAN_TrainCode\\code\\dataloader.py", line 14, in module

from torch.utils.data.dataloader import _DataLoaderIter

ImportError: cannot import name '_DataLoaderIter'

Why is this happening?

Your comment answers the question: the _DataLoaderIter is there in 1.0.0 (for which you are linking documentation) but not in 0.3.1 , as you can check here - its name has no preceding _ .

This is a textbook example why it is a bad idea to access other packages' private classes/functions (customarily prefixed with an underscore) - you have zero guarantees on the stability of their implementation and behavior. If you need their code, it's usually better to copy-paste the code to your own file, because there it is at least guaranteed to not change between updates and bug fixes to torch .

Create a new virtual environment and install Torch0.4.0 for this specific repo. I had the same problem and reinstalling Torch v0.4.0 did the trick for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM