diff --git a/ultralytics/models/yolo/detect/val.py b/ultralytics/models/yolo/detect/val.py index 31f0fdc0..9ad9a4fb 100644 --- a/ultralytics/models/yolo/detect/val.py +++ b/ultralytics/models/yolo/detect/val.py @@ -74,7 +74,7 @@ class DetectionValidator(BaseValidator): and (val.endswith(f"{os.sep}val2017.txt") or val.endswith(f"{os.sep}test-dev2017.txt")) ) # is COCO self.is_lvis = isinstance(val, str) and "lvis" in val and not self.is_coco # is LVIS - self.class_map = converter.coco80_to_coco91_class() if self.is_coco else list(range(len(model.names))) + self.class_map = converter.coco80_to_coco91_class() if self.is_coco else list(range(1, len(model.names) + 1)) self.args.save_json |= self.args.val and (self.is_coco or self.is_lvis) and not self.training # run final val self.names = model.names self.nc = len(model.names) @@ -288,8 +288,7 @@ class DetectionValidator(BaseValidator): self.jdict.append( { "image_id": image_id, - "category_id": self.class_map[int(p[5])] - + (1 if self.is_lvis else 0), # index starts from 1 if it's lvis + "category_id": self.class_map[int(p[5])], "bbox": [round(x, 3) for x in b], "score": round(p[4], 5), } diff --git a/ultralytics/models/yolo/obb/val.py b/ultralytics/models/yolo/obb/val.py index 93bb2bfa..9e9bcf7d 100644 --- a/ultralytics/models/yolo/obb/val.py +++ b/ultralytics/models/yolo/obb/val.py @@ -160,7 +160,7 @@ class OBBValidator(DetectionValidator): for d in data: image_id = d["image_id"] score = d["score"] - classname = self.names[d["category_id"]].replace(" ", "-") + classname = self.names[d["category_id"] - 1].replace(" ", "-") p = d["poly"] with open(f'{pred_txt / f"Task1_{classname}"}.txt', "a") as f: @@ -175,7 +175,7 @@ class OBBValidator(DetectionValidator): image_id = d["image_id"].split("__")[0] pattern = re.compile(r"\d+___\d+") x, y = (int(c) for c in re.findall(pattern, d["image_id"])[0].split("___")) - bbox, score, cls = d["rbox"], d["score"], d["category_id"] + bbox, score, cls = d["rbox"], d["score"], d["category_id"] - 1 bbox[0] += x bbox[1] += y bbox.extend([score, cls])