0.介绍
GroundingDINO是最新发布的zero-shot目标检测器,在多个数据集上取得了很好的结果。在该方法的基础上,本人修复该方法自动标注的bug,并增加VOC格式。
1.安装GroundingDINO
根据github提供的源码和说明,配置环境和下载权重文件。链接如下:
https://github.com/IDEA-Research/GroundingDINO
2.修改bug
直接运行:
python demo/create_coco_dataset.py
当图片中没有检测到目标时将会报错:
File "/media/vv/detection/GroundingDINO/groundingdino/util/inference.py", line 84, in predict
return boxes, logits.max(dim=1)[0], phrases
RuntimeError: cannot perform reduction function max on tensor with no elements because the operation does not have an identity
这是因为当没有检测到目标时,boxes的输出上tensor([ ]),但是logits和phrases上完全没有输出的,所以无法return回来。
我们对该代码进行简单修改,在83行后,将return替换:
if len(logits) == 0:
logits = []
phrases = []
return boxes, logits, phrases
else:
return boxes, logits.max(dim=1)[0], phrases
综上,我们就可以直接运行代码了。
3.增加VOC格式
将create_coco_dataset.py复制一份,命名为create_voc_dataset.py,将68行
if export_dataset:
dataset.export(
'coco_dataset',
dataset_type=fo.types.COCODetectionDataset,
)
修改为:
if export_dataset:
dataset.export(
'voc_dataset',
dataset_type=fo.types.VOCDetectionDataset,
)
4.注意事项
4.1超参数设置
(1)源代码box_threshold设置为0.15,在生成数据集时有大量误报,建议设置为0.4以上
(2) text_prompt设置的类别越多,检测效果会下降;
(3)export_dataset默认上false,需要设置为true;
4.2数据清洗
该算法标注的数据集包括大量无目标标注数据,如果使用VOC格式,可以参考本人另一篇博客,删除无目标标注数据。