FPD icon indicating copy to clipboard operation
FPD copied to clipboard

ImportError: cannot import name 'DistributedSampler' from 'mmcls.datasets.builder'

Open ylrccc opened this issue 1 year ago • 4 comments
trafficstars

Hello, excuse me! I'm having this problem at runtime, but I'm almost following the steps in the readme to run the configuration, so I'd like to ask how to solve this problem? Traceback (most recent call last): File "train.py", line 18, in <module> import mmfewshot # noqa: F401, F403 File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/__init__.py", line 6, in <module> from .classification import * # noqa: F401, F403 File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/__init__.py", line 2, in <module> from .apis import * # noqa: F401,F403 File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/apis/__init__.py", line 2, in <module> from .inference import (inference_classifier, init_classifier, File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/apis/inference.py", line 14, in <module> from mmfewshot.classification.models import BaseMetricClassifier File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/models/__init__.py", line 5, in <module> from .classifiers import * # noqa: F401,F403 File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/models/classifiers/__init__.py", line 8, in <module> from .maml import MAML File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/models/classifiers/maml.py", line 10, in <module> from mmfewshot.classification.datasets import label_wrapper File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/datasets/__init__.py", line 5, in <module> from .builder import (build_dataloader, build_dataset, File "/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmfewshot/classification/datasets/builder.py", line 7, in <module> from mmcls.datasets.builder import DATASETS, DistributedSampler, worker_init_fn ImportError: cannot import name 'DistributedSampler' from 'mmcls.datasets.builder' (/home/ubuntu/anaconda3/envs/fpd01/lib/python3.8/site-packages/mmcls/datasets/builder.py)

ylrccc avatar Mar 04 '24 02:03 ylrccc

Hello, it seems that your mmfewshot didn't install correctly. Please make sure to follow the steps below:

# install mmfewshot
pip install git+https://github.com/open-mmlab/mmfewshot.git
# or manually download the code, then
# cd mmfewshot
# pip install .

Do not use mim to install it:

mim install mmfewshot  # bugs

Feel free to ask if you still have any questions.

wangchen1801 avatar Mar 04 '24 03:03 wangchen1801

非常感谢你的回复! 我是按照步骤一步一步运行的,但是到mmdet的安装时,使用

mim install mmdet==2.24.0

就会出现下面图片中的问题 微信图片_20240304152117

所以我就只把这句换成了清华镜像 pip install mmdet==2.24.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

其他的语句都是没变的,但后面还是出现了一个新问题 Traceback (most recent call last): File "train.py", line 242, in <module> main() File "train.py", line 159, in main cfg.dump(osp.join(cfg.work_dir, osp.basename(args.config))) File "/home/ubuntu/anaconda3/envs/fpd02/lib/python3.8/site-packages/mmcv/utils/config.py", line 596, in dump f.write(self.pretty_text) File "/home/ubuntu/anaconda3/envs/fpd02/lib/python3.8/site-packages/mmcv/utils/config.py", line 508, in pretty_text text, _ = FormatCode(text, style_config=yapf_style, verify=True) TypeError: FormatCode() got an unexpected keyword argument 'verify'

ylrccc avatar Mar 04 '24 07:03 ylrccc

Please try this:

pip install yapf==0.40.1

it can solve the problem in my evironment~

wangchen1801 avatar Mar 04 '24 07:03 wangchen1801

Thank you very much! The problem has been solved! Thank you thank you thank you!

ylrccc avatar Mar 04 '24 07:03 ylrccc