1、resulits do not correspond to current coco set
出现这个问题的原因是coco的jdon文件和yolov5预测的json文件,里面image_id的名字不同。
修改以下地方:
def save_one_json(predn, jdict, path, class_map):
# Save one JSON result {"image_id": 42, "category_id": 18, "bbox": [258.15, 41.29, 348.26, 243.78], "score": 0.236}
name = int(path.stem) if path.stem.isnumeric() else path.stem
with open("/home/dyy/sda/dyy/datasets/coco/annotations/instances_val2017.json","r",encoding="utf-8") as f:
load_dict = json.load(f)
for image in load_dict["images"]:
if image['file_name'][:-4] == name:
image_id = image["id"]
#name = int(path.stem) if path.stem.isnumeric() else path.stem
box = xyxy2xywh(predn[:, :4]) # xywh
box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner
for p, b in zip(predn.tolist(), box.tolist()):
jdict.append({
'image_id': image_id,
'category_id': class_map[i