OpenGVLab / InternImage

[CVPR 2023 Highlight] InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions
https://arxiv.org/abs/2211.05778
MIT License
2.49k stars 232 forks source link

cannot import name 'print_log' from 'mmcv' #91

Open kym-y-Ninomiya opened 1 year ago

kym-y-Ninomiya commented 1 year ago

Hi.

When I try to run the segmentation Image Demo codes, It requires me of mmcv>=2.0.0rc4 , but I mim install mmcv==2.0.0rc4 to just see that mmcv 2.0.0rc4 cannot import name "prinr_log". What can I do for compliting the Demo? If anyone so kind help me I thank a lot.

czczup commented 1 year ago

Do you mean https://github.com/OpenGVLab/InternImage/blob/master/segmentation/image_demo.py?

kym-y-Ninomiya commented 1 year ago

Yes. I 'm trying this: CUDA_VISIBLE_DEVICES=0 python image_demo.py \ data/ade/ADEChallengeData2016/images/validation/ADE_val_00000591.jpg \ configs/ade20k/upernet_internimage_t_512_160k_ade20k.py \ checkpoint_dir/seg/upernet_internimage_t_512_160k_ade20k.pth \ --palette ade20k

kym-y-Ninomiya commented 1 year ago

Honestly I do this becasuse I have a windows PC without GPU. set CUDA_VISIBLE_DEVICES=-1 python image_demo.py C:\Users\XXXX\Downloads\InternImage-master\InternImage-master\segmentation\data\a95bbb23a27d5679fd048c38359811fb.jpg configs/ade20k/upernet_internimage_t_512_160k_ade20k.py checkpoint_dir/seg/upernet_internimage_t_512_160k_ade20k.pth --palette ade20k

gmy-gm commented 1 year ago

I met the same error ,I want to know how solve it,thank you so much.

AliceShynie commented 1 year ago

I am having the same error, I was wondering if it's been solved too?

pythonlover22 commented 1 year ago

I am having the same error on cpu only installation:

The Torch version:  2.0.0 
CUDA installation:  False
MMDetection version:  3.0.0
The version and installation of nvcc or CUDA compiler :  not available
The available compiler and the version:  MSVC 192829924
Operating System: Windows 11
python=3.8

I was wondering if it's been solved too?

gmy-gm commented 1 year ago

You can see the version of your pillow, I found my pillow is 9.x, then I chaged it 6.2.1

aymanaboghonim commented 1 year ago

I have the same error , is there any way to resolve it ??

LadSha commented 1 year ago

Rather than importing print_log, copy and use the function from the old version of mmcv:

def print_log(msg, logger=None, level=logging.INFO): """Print a log message.

Args:
    msg (str): The message to be logged.
    logger (logging.Logger | str | None): The logger to be used.
        Some special loggers are:
        - "silent": no message will be printed.
        - other str: the logger obtained with `get_root_logger(logger)`.
        - None: The `print()` method will be used to print log messages.
    level (int): Logging level. Only available when `logger` is a Logger
        object or "root".
"""
if logger is None:
    print(msg)
elif isinstance(logger, logging.Logger):
    logger.log(level, msg)
elif logger == 'silent':
    pass
elif isinstance(logger, str):
    _logger = get_logger(logger)
    _logger.log(level, msg)
else:
    raise TypeError(
        'logger should be either a logging.Logger object, str, '
        f'"silent" or None, but got {type(logger)}')
tvishnu1990 commented 1 year ago

mmcv=>2.0.0 version "print_log" function is implemented in "mmengine".

/mmcv/parallel/distributed.py file modify the line 8.

Instead : from mmcv import print_log Replace: from mmengine import print_log

ishipachev commented 1 year ago

I my case issue was that config file mask2former_r50_lsj_8x2_50e_coco-panoptic.py

Where you can see it refers to COCO dataset defenition class in coco_panoptic.py which tried to import print log from mmcv, not from mmengine (as @tvishnu1990 have mentioned already).

Check your config files. Incompatibility may come from the fact that your config for some reason refers to dataset class definition incompatible with your package version/installation as it was in my case.

EthanAbitbol3 commented 1 year ago

i still got the next issue : image anyone have an idea ?

azuryl commented 1 year ago

i still got the next issue : image anyone have an idea ?

me2

feliyur commented 1 year ago

I was able to solve by downgrading to mmcv-full==1.5.0 and mim installing the corresponding version of mmsegmentation==0.27.0 (described here https://github.com/OpenGVLab/InternImage/issues/208)

mim uninstall mmcv mmcv-full
mim install mmcv-full==1.5.0
mim install mmsegmentation==0.27.0

Figured this out after taking a look at mmcv, looks like there was a change in mmcv.utils.init between version 1.x (which is expected by InternImage) and version 2.x. Also mmsegmentation is missing from InternImage installation instructions.

adithi-guardianrfid commented 1 year ago

I am getting this same error while trying to run mmfewshot.

ImportError: cannot import name 'print_log' from 'mmcv'

My dockerfile has mmcv-full, mmcls and mmdet installs. Anyone else with the same issue?

LittleFay2 commented 12 months ago

I am getting this same error while trying to run mmfewshot.

ImportError: cannot import name 'print_log' from 'mmcv'

My dockerfile has mmcv-full, mmcls and mmdet installs. Anyone else with the same issue?

Now I have the same problem, is there any way to resolve it?

suzauddola commented 11 months ago

@LittleFay2 Try to follow @tvishnu1990

Instead : from mmcv import print_log Replace: from mmengine import print_log

============= && =================== First, uninstall all: mim uninstall mmcv mim uninstall mmcv-full

then:

mim install mmcv mim install mmcv-full

It's working for me, and my current versions are:

Package Version Source


mmcv 2.1.0 https://github.com/open-mmlab/mmcv mmcv-full 1.7.1 https://github.com/open-mmlab/mmcv mmdet 2.27.0 https://github.com/open-mmlab/mmdetection mmengine 0.8.4 https://github.com/open-mmlab/mmengine

vetsasai commented 7 months ago

@LittleFay2 Try to follow @tvishnu1990

Instead : from mmcv import print_log Replace: from mmengine import print_log

============= && =================== First, uninstall all: mim uninstall mmcv mim uninstall mmcv-full

then:

mim install mmcv mim install mmcv-full

It's working for me, and my current versions are:

Package Version Source

mmcv 2.1.0 https://github.com/open-mmlab/mmcv mmcv-full 1.7.1 https://github.com/open-mmlab/mmcv mmdet 2.27.0 https://github.com/open-mmlab/mmdetection mmengine 0.8.4 https://github.com/open-mmlab/mmengine

It worked for me also! Thanks

ulmasovjafarbek commented 7 months ago

downgrading to mmcv-full==1.5.0 worked for me

jeantirole commented 5 months ago

i still got the next issue : image anyone have an idea ?

me2

i solved with these lines , mmcv > parallel > distributed.py

from mmengine.utils.dl_utils import TORCH_VERSION
from mmengine.utils.version_utils import digit_version
JoyLinWQ commented 4 months ago

i still got the next issue : image anyone have an idea ?

me2

i solved with these lines , mmcv > parallel > distributed.py

from mmengine.utils.dl_utils import TORCH_VERSION
from mmengine.utils.version_utils import digit_version

Nice! Followed all the fixes above, then it led to (more) never-ending series of similar import fixes... :(

Has anyone figured out the correct set of mmcv or mmcv-full packages to use? I'm trying to run bash scripts/train_prototypes_bbox.sh from https://github.com/xavibou/ovdsat/tree/main and this is giving me a headache.

I'm stuck at current import fix - unable to find any resources:

  File "C:\Users\XXX\anaconda3\envs\ovdsat\lib\site-packages\mmcv\device\ipu\__init__.py", line 3, in <module>
    from mmcv.utils.device_type import IS_IPU_AVAILABLE
ImportError: cannot import name 'IS_IPU_AVAILABLE' from 'mmcv.utils.device_type'

while trying to fix

  File "C:\Users\XXX\anaconda3\envs\ovdsat\lib\site-packages\mmcv\device\ipu\__init__.py", line 3, in <module>
    from mmcv.utils import IS_IPU_AVAILABLE
ImportError: cannot import name 'IS_IPU_AVAILABLE' from 'mmcv.utils'

Currently having mmcv-full==1.7.2, mmdet==2.28.2, mmengine==0.10.4, mmrotate==0.3.4 and torch=2.2.2+cu121, torchaudio=2.2.2+cu121, torchvision=0.17.2+cu121 on python=3.9.19.

pkyzh2006 commented 3 months ago

I have solved this problem. The core of this problem is version mismatch. Interimage is in mmcv1.x.x. This will cause confusion between mmcv and mmengine when using higher versions of mmdet. Use the recommended version such as mmdet on 2.28 can solve the problem.

pythonlover22 commented 3 months ago

It is recommended to avoid this poor package and use Detectron2 instead. Even if you solve an issue after a long effort, you will struggle again with another issue next time. This package lacks technical support. Finally, Detectron2 is more accurate.

pkyzh2006 commented 3 months ago

It is recommended to avoid this poor package and use Detectron2 instead. Even if you solve an issue after a long effort, you will struggle again with another issue next time. This package lacks technical support. Finally, Detectron2 is more accurate.

That is correct. But internimage is kidnapped within this framework

harryprince commented 2 weeks ago

same issue under mmcv-full 1.7.2