open-mmlab / mmcv

OpenMMLab Computer Vision Foundation
https://mmcv.readthedocs.io/en/latest/
Apache License 2.0
5.92k stars 1.66k forks source link

[Bug] ImportError: cannot import name 'is_list_of' from 'mmcv.utils' #2882

Open lizhyuxi opened 1 year ago

lizhyuxi commented 1 year ago

Prerequisite

Environment

Python 3.8 PyTorch 1.7.1 mmcv 2.0.0rc4 mmcv-full 1.5.3

Reproduces the problem - code sample

File "/users/k20103423/.conda/envs/CGFormer/lib/python3.8/site-packages/mmcv/fileio/io.py", line 6, in from ..utils import is_list_of

Reproduces the problem - command or script

none

Reproduces the problem - error message

Traceback (most recent call last): File "test.py", line 13, in from model import build_segmenter File "/scratch/users/k20103423/zhiyu/CGFormer/model/init.py", line 4, in from .backbone import MultiModalSwinTransformer File "/scratch/users/k20103423/zhiyu/CGFormer/model/backbone.py", line 9, in from .mmcv_custom import load_checkpoint File "/scratch/users/k20103423/zhiyu/CGFormer/model/mmcv_custom/init.py", line 3, in from .checkpoint import load_checkpoint File "/scratch/users/k20103423/zhiyu/CGFormer/model/mmcv_custom/checkpoint.py", line 19, in from mmcv.fileio import FileClient File "/users/k20103423/.conda/envs/CGFormer/lib/python3.8/site-packages/mmcv/fileio/init.py", line 4, in from .io import dump, load, register_handler File "/users/k20103423/.conda/envs/CGFormer/lib/python3.8/site-packages/mmcv/fileio/io.py", line 6, in from ..utils import is_list_of ImportError: cannot import name 'is_list_of' from 'mmcv.utils' (/users/k20103423/.conda/envs/CGFormer/lib/python3.8/site-packages/mmcv/utils/init.py)

Additional information

'is_list_of' do not exist in this init file image

fanqiNO1 commented 1 year ago

It seems that it's because you use mmcv>=2.0, but the original project uses mmcv<2.0. mmcv.utils.is_list_of has been moved to mmengine.utils with mmcv=2.0. So you can try to install mmcv<2.0.

https://github.com/open-mmlab/mmengine/blob/53474ef1ba0b166508c231fa525b55b580adf20f/mmengine/utils/__init__.py#L23