You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MMDetection训练YOLOv3模型时遇维度不匹配ValueError报错

MMDetection训练YOLOv3报错:ValueError: operands could not be broadcast together with shapes (0,) (4,)

报错详情

训练时触发如下错误:

ValueError: operands could not be broadcast together with shapes (0,) (4,)

训练代码

# Build dataset
datasets = [build_dataset(cfg.data.train)]
# Build the detector
model = build_detector(cfg.model)
# Add an attribute for visualization convenience
model.CLASSES = datasets[0].CLASSES
# Create work_dir
mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))
train_detector(model, datasets, cfg, distributed=False, validate=True)

数据集样本标注情况

调用datasets[0].get_ann_info(1)查看样本标注,结果显示该样本的bboxes为空数组(形状为(0,4)),无有效检测框标注。

问题原因及解决方法

原因

报错源于训练过程中遇到了无检测框标注的样本,YOLOv3的训练逻辑在处理空标注时,张量维度不匹配导致广播操作失败。

解决方法

  • 过滤空标注样本:在数据集配置文件的train配置中添加filter_empty_gt=True,确保只保留带有有效检测框的样本参与训练。
  • 检查标注格式:确认所有标注的bbox符合MMDetection要求,格式为[x1, y1, x2, y2],且坐标数值在图像范围内。
  • 保留空样本的处理方案:若业务需要保留无标注样本,需修改数据处理管道,为空标注样本生成占位张量(如全零的(0,4) bbox配合空标签),避免维度冲突。

内容的提问来源于stack exchange,提问作者LinhVo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 12:18:10