MMdetection 报错集合

本文分析并解决了Python编程中遇到的错误,包括类型错误、文件找不到、运行时错误以及导入错误。针对这些问题,提出了针对性的解决方案,如检查json数据格式、校验配置文件、调整模型配置以适应GPU资源以及处理模型加载时的设备不匹配问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 TypeError: Argument 'bb' has incorrect type (expected numpy.ndarray, got list)

分析:

报错原因是json文件里面的“segmentation”中的数据不对。“segmentation”:[[x,y,x,y,x,y.....x,y]] 是按顺序排列的点序列,点序列个数要求是偶数,同时点的个数至少要大于2个,因为要构成一个polygon,也就是说segmentation列表的长度必须是偶数且大于4。

解决方法:

遍历json文件中的所有"annotations"的"segmentation",如果segmentation列表的长度不是偶数或者小于8(确保有4个点以上最好),就把这个annotation丢弃。

2 FileNotFoundError: [Errno 2] No such file or directory:  '/tmp/tmp06mpclev/tmp6hqrztqc.py' 

分析:

通常是配置文件有问题,比如数据集的配置文件coco_instance.py中的数据集路径错了,就会报此错误。

解决方法:

检测数据集,模型等的配置文件

3  RuntimeError: Default process group has not been initialized, please make sure to call init_process_

分析:

在跑基于mmdetection的 Swin-Transformer-Object-Detection 的代码时,报此错误。

因为模型用到了SyncBN,而SyncBN是一定要用多张GPU的,只用一张GPU就会报错。

解决办法:

Swin-Transformer模型的配置文件,比如‘cascade_mask_rcnn_swin_base_patch4_window7_mstrain_480-800_giou_4conv1f_adamw_3x_coco.py’ 中的“SyncBN” 全部改为“BN”,或者使用两张以上GPU进行训练

4 RuntimeError: Attempting to deserialize object on CUDA device 7 but torch.cuda.device_count() is 1. Please use torch.load with map_location to map your storages to an existing device.

 分析:

在调用训练好的模型进行预测时报的错误,原因是原来的模型是在GUP7上面训练的,而现在只能找到一块GPU,即设备对不上

 解决办法:

方法一:

将mmdetection 的模型初始化函数的输入device改为cpu, 即:

init_detector(config_file, checkpoint_file, device='cpu')

方法二:

修改源代码 mmdet\apis\inference.py 中的函数 init_detector()

函数加入一个参数 map_loc 方便以后修改,再将 代码里面的“map_loc = 'cpu' if device == 'cpu' else None ” 修改为 “map_loc = 'cpu' if device == 'cpu' else map_loc”, 即:

def init_detector(config, checkpoint=None, device='cuda:0', cfg_options=None, map_loc=None):
    ******
    map_loc = 'cpu' if device == 'cpu' else map_loc

    ******

然后调用函数的时候就可以修改map_loc,来改变使用的设备。

比如原来是在GPU7上面训练的,现在要在GPU0上面用:

model = init_detector(config_file, checkpoint_file, device='cuda:0', map_loc={'cuda:7':'cuda:0'})

5  ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /data/liyq/Anaconda/lib/python3.8/site-packages/matplotlib/ft2font.cpython-38-x86_64-linux-gnu.so)

分析:

libstdc++.so.6版本过低

解决办法:

 命令行输入

vim  ~/.bash_profile

在文件中添加

LD_LIBRARY_PATH=/data/***/Anaconda/lib:$LD_LIBRARY_PATH   # (anaconda3 安装的位置)
export LD_LIBRARY_PATH

然后再在命令行输入

source  ~/.bash_profile
报错 (ultralytics) D:\DL\yolo11>C:/Users/w7417427/miniconda3/envs/ultralytics/python.exe d:/DL/yolo11/validate_camp_models-3.py C:\Users\w7417427\miniconda3\envs\ultralytics\lib\site-packages\timm\models\layers\__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning) 开始执行检测... Traceback (most recent call last): File "d:\DL\yolo11\validate_camp_models-3.py", line 172, in <module> "model_a_color": run_detection(MODEL_A, DATASET_COLOR, gt_color, BATCH_SIZE, IOU_THRESHOLD), File "d:\DL\yolo11\validate_camp_models-3.py", line 77, in run_detection results = model.predict( File "d:\DL\yolo11\ultralytics\engine\model.py", line 560, in predict return self.predictor.predict_cli(source=source) if is_cli else self.predictor(source=source, stream=stream) File "d:\DL\yolo11\ultralytics\engine\predictor.py", line 175, in __call__ return list(self.stream_inference(source, model, *args, **kwargs)) # merge list of Result into one File "C:\Users\w7417427\miniconda3\envs\ultralytics\lib\site-packages\torch\utils\_contextlib.py", line 36, in generator_context response = gen.send(None) File "d:\DL\yolo11\ultralytics\engine\predictor.py", line 257, in stream_inference im = self.preprocess(im0s) File "d:\DL\yolo11\ultralytics\engine\predictor.py", line 127, in preprocess im = np.stack(self.pre_transform(im)) File "C:\Users\w7417427\miniconda3\envs\ultralytics\lib\site-packages\numpy\core\shape_base.py", line 445, in stack raise ValueError('need at least one array to stack') ValueError: need at least one array to stack
06-04
根据引用,当进行多GPU训练时报错,可能是由于并行运算产生的问题或者代码中的错误导致的。一些可能的错误包括通道数不对、没有正确使用所有通道、更新损失时出现问题等。 然而,根据引用,当使用单个GPU运行时没有发现报错。这表明修改网络结构不是问题的原因,而可能是某处的配置没有正确设置。在进行长时间的调试后,发现没有设置`find_unused_parameters=True`。 为了解决这个问题,根据引用中Github上的建议,可以在`torch.nn.parallel.DistributedDataParallel`包装模型时使用`find_unused_parameters=True`选项。具体的修改可以在`mmdet/apis/train.py`文件的第114行进行,将原来的代码`find_unused_parameters = cfg.get('find_unused_parameters', False)`修改为`find_unused_parameters = True`。 这样,模型将使用`torch.nn.parallel.DistributedDataParallel`进行并行训练,并将`find_unused_parameters`参数设置为`True`。这个修改可以避免报错的发生。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [mmdetection学习记录之报错解决汇总](https://blog.csdn.net/qq_42642142/article/details/123032091)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [mmdetection3d报错问题解决汇总](https://blog.csdn.net/QLeelq/article/details/130404416)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值