文章目录
- mmcv1.x版本
- FAQ文档
- open-mmlab
- 卸载环境中的mmcv
- ImportError: cannot import name 'Config' from 'mmcv' (unknown location)
- problem description
- 解决
- ImportError: cannot import name 'mkdir_or_exist' from 'mmcv.utils' (unknown location)
- 解决
- AttributeError: module 'mmcv' has no attribute 'ProgressBar'
- 解决
- ImportError: cannot import name 'IS_MLU_AVAILABLE' from 'mmcv.utils' (unknown location)
- 解决
- ImportError: cannot import name 'get_git_hash' from 'mmcv.utils'
- 解决
- ImportError: cannot import name 'print_log' from 'mmcv' (unknown location)
- 解决
- ImportError: cannot import name 'TORCH_VERSION' from 'mmcv.utils' (unknown location)
- 解决
- 其余以此为参考查阅FAQ文档即可
- 上述也可直接在utils中新建个init文件即可
- ImportError: cannot import name '_InstanceNorm' ,'_BatchNorm' from mmcv.utils
- 解决
- ModuleNotFoundError: No module named 'mmcv._ext'
- 解决
mmcv1.x版本
FAQ文档
嘻嘻
open-mmlab
哈哈
卸载环境中的mmcv
重新下载
ImportError: cannot import name ‘Config’ from ‘mmcv’ (unknown location)
problem description
解决
在mmcv 2.0.0中,Config已移动到mmengine,进行如下修改即可:
from mmengine.config import Config
MMCV官网
参考链接
参考
ImportError: cannot import name ‘mkdir_or_exist’ from ‘mmcv.utils’ (unknown location)
解决
很简单,改为
from mmcv.utils.path import mkdir_or_exist
即可,mkdir_or_exist在utils.path中定义的
AttributeError: module ‘mmcv’ has no attribute ‘ProgressBar’
简单来说就是mmcv中没有这个函数,我的版本为mmcv-full 1.7
好吧,查看了下文档实际上有
from mmcv.utils import progressbar
然后直接用progressbar函数即可
很棒,报错
受不了了,一个没啥用的还一直报错。。。
解决
直接用tqdm替代了
# 获取目录下文件的数量
total_files = len(os.listdir(origin_label_path))
# 使用tqdm创建进度条对象
with tqdm(total=total_files) as pbar:
for label_name in os.listdir(origin_label_path):
image_objects = wwtool.simpletxt_parse(os.path.join(origin_label_path, label_name))
filtered_objects = []
for image_object in image_objects:
if convert_classes[image_object['label']] == None:
filter_count += 1
continue
else:
image_object['label'] = convert_classes[image_object['label']]
filtered_objects.append(image_object)
if len(filtered_objects) > 0:
img = cv2.imread(os.path.join(origin_image_path, os.path.splitext(label_name)[0] + image_format2))
save_image_file = os.path.join(filtered_image_path, os.path.splitext(label_name)[0] + '.png')
# print("Save image file: ", save_image_file)
cv2.imwrite(save_image_file, img)
wwtool.simpletxt_dump(filtered_objects, os.path.join(filtered_label_path, os.path.splitext(label_name)[0] + '.txt'))
pbar.update()
ImportError: cannot import name ‘IS_MLU_AVAILABLE’ from ‘mmcv.utils’ (unknown location)
然而。。。
解决
直接扒源码了,mmcv.utils中直接新建一个device_type.py
# Copyright (c) OpenMMLab. All rights reserved.
def is_ipu_available() -> bool:
try:
import poptorch
return poptorch.ipuHardwareIsAvailable()
except ImportError:
return False
IS_IPU_AVAILABLE = is_ipu_available()
def is_mlu_available() -> bool:
try:
import torch
return (hasattr(torch, 'is_mlu_available')
and torch.is_mlu_available())
except Exception:
return False
IS_MLU_AVAILABLE = is_mlu_available()
def is_mps_available() -> bool:
"""Return True if mps devices exist.
It's specialized for mac m1 chips and require torch version 1.12 or higher.
"""
try:
import torch
return hasattr(torch.backends,
'mps') and torch.backends.mps.is_available()
except Exception:
return False
IS_MPS_AVAILABLE = is_mps_available()
def is_npu_available() -> bool:
"""Return True if npu devices exist."""
try:
import torch
import torch_npu
return (hasattr(torch, 'npu') and torch_npu.npu.is_available())
except Exception:
return False
IS_NPU_AVAILABLE = is_npu_available()
ImportError: cannot import name ‘get_git_hash’ from ‘mmcv.utils’
查阅了FAQ文档后发现,get_git_hash位于mmcv.utils.version_utils
解决
from mmcv.utils.version_utils import get_git_hash
ImportError: cannot import name ‘print_log’ from ‘mmcv’ (unknown location)
解决
from mmcv.utils.logging import print_log
ImportError: cannot import name ‘TORCH_VERSION’ from ‘mmcv.utils’ (unknown location)
解决
from mmcv.utils.parrots_wrapper import TORCH_VERSION
其余以此为参考查阅FAQ文档即可
上述也可直接在utils中新建个init文件即可
ImportError: cannot import name ‘_InstanceNorm’ ,‘_BatchNorm’ from mmcv.utils
在FAQ文档中搜索无果
解决
from torch.nn.modules.instancenorm import _InstanceNorm
from torch.nn.modules.batchnorm import _BatchNorm
ModuleNotFoundError: No module named ‘mmcv._ext’
解决
这个问题简直绝了,前仆后继的遇到,,最终我也是把mmcv-full的版本改为了1.4.0