InternImage icon indicating copy to clipboard operation
InternImage copied to clipboard

cannot import name 'print_log' from 'mmcv'

Open kym-y-Ninomiya opened this issue 2 years ago • 25 comments

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.

kym-y-Ninomiya avatar Apr 12 '23 06:04 kym-y-Ninomiya

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

czczup avatar Apr 13 '23 07:04 czczup

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 avatar Apr 14 '23 04:04 kym-y-Ninomiya

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

kym-y-Ninomiya avatar Apr 14 '23 04:04 kym-y-Ninomiya

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

gmy-gm avatar Apr 21 '23 01:04 gmy-gm

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

AliceShynie avatar Apr 22 '23 12:04 AliceShynie

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?

pythonlover22 avatar Apr 26 '23 14:04 pythonlover22

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

gmy-gm avatar Apr 27 '23 01:04 gmy-gm

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

aymanaboghonim avatar Apr 27 '23 20:04 aymanaboghonim

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)}')

LadSha avatar Apr 27 '23 23:04 LadSha

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

tvishnu1990 avatar May 02 '23 05:05 tvishnu1990

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.

ishipachev avatar May 26 '23 13:05 ishipachev

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

EthanAbitbol3 avatar Jun 06 '23 10:06 EthanAbitbol3

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

me2

azuryl avatar Jul 05 '23 01:07 azuryl

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.

feliyur avatar Aug 23 '23 10:08 feliyur

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?

adithi-guardianrfid avatar Aug 31 '23 03:08 adithi-guardianrfid

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?

LittleFay2 avatar Oct 07 '23 02:10 LittleFay2

@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

suzauddola avatar Oct 25 '23 03:10 suzauddola

@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

vetsasai avatar Feb 12 '24 11:02 vetsasai

downgrading to mmcv-full==1.5.0 worked for me

ulmasovjafarbek avatar Feb 18 '24 17:02 ulmasovjafarbek

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

jeantirole avatar Apr 22 '24 05:04 jeantirole

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.

JoyLinWQ avatar May 21 '24 15:05 JoyLinWQ

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.

pkyzh2006 avatar Jun 18 '24 19:06 pkyzh2006

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.

pythonlover22 avatar Jun 18 '24 20:06 pythonlover22

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

pkyzh2006 avatar Jun 19 '24 01:06 pkyzh2006

same issue under mmcv-full 1.7.2

harryprince avatar Sep 10 '24 06:09 harryprince