使用自制数据集,格式为coco格式,数据集只有一类stone
训练的时候没问题,测试的时候有问题
报错提示如下
File "tools/test.py", line 231, in main
metric = dataset.evaluate(outputs, **eval_kwargs)
File "/home/ubuntu/xy/mmdetection/mmdet/datasets/coco.py", line 414, in evaluate
result_files, tmp_dir = self.format_results(results, jsonfile_prefix)
File "/home/ubuntu/xy/mmdetection/mmdet/datasets/coco.py", line 359, in format_results
result_files = self.results2json(results, jsonfile_prefix)
File "/home/ubuntu/xy/mmdetection/mmdet/datasets/coco.py", line 291, in results2json
json_results = self._det2json(results)
File "/home/ubuntu/xy/mmdetection/mmdet/datasets/coco.py", line 228, in _det2json
data['category_id'] = self.cat_ids[label]
IndexError: list index out of range
最主要的原因是coco中为80类,而数据集只有一类,修改mmdet/datasets/coco.py,将其中的80类改为自己的一类,我的修改示例如下
class CocoDataset(CustomDataset):
CLASSES = ('stone')
# CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
# 'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
# 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
# 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
# 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
# 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat',
# 'baseball glove', 'skateboard', 'surfboard', 'tennis racket',
# 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
# 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
# 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
# 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop',
# 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
# 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock',
# 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush')
修改之后可以正常测试
如有其他问题可以参考github issue:
https://github.com/open-mmlab/mmdetection/issues/4243
版权声明:本文为CSDN博主「有的放矢的子江」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_38018994/article/details/122320888
暂无评论