WZMIAOMIAO/deep-learning-for-image-processing · error · ValueError

Unknown iou type {}

Error message

Unknown iou type {}

What it means

CocoEval.prepare dispatches on iou_type (bbox/segm/keypoints); any other value falls through to ValueError 'Unknown iou type'. The iou_type usually comes from the COCO dataset's annotation file or is set on the evaluator.

Source

Thrown at pytorch_object_detection/faster_rcnn/train_utils/coco_eval.py:66

    def accumulate(self):
        for coco_eval in self.coco_eval.values():
            coco_eval.accumulate()

    def summarize(self):
        for iou_type, coco_eval in self.coco_eval.items():
            print("IoU metric: {}".format(iou_type))
            coco_eval.summarize()

    def prepare(self, predictions, iou_type):
        if iou_type == "bbox":
            return self.prepare_for_coco_detection(predictions)
        elif iou_type == "segm":
            return self.prepare_for_coco_segmentation(predictions)
        elif iou_type == "keypoints":
            return self.prepare_for_coco_keypoint(predictions)
        else:
            raise ValueError("Unknown iou type {}".format(iou_type))

    def prepare_for_coco_detection(self, predictions):
        coco_results = []
        for original_id, prediction in predictions.items():
            if len(prediction) == 0:
                continue

            boxes = prediction["boxes"]
            boxes = convert_to_xywh(boxes).tolist()
            scores = prediction["scores"].tolist()
            labels = prediction["labels"].tolist()

            coco_results.extend(
                [
                    {
                        "image_id": original_id,
                        "category_id": labels[k],
                        "bbox": box,

View on GitHub (pinned to 1ec3fe6f37)

Solutions

  1. Set iou_type to one of "bbox", "segm", or "keypoints"
  2. Check the COCO annotation JSON (jsonInfo['info'] / dataset task type) for a nonstandard iou_type value
  3. If evaluating a new task type, extend prepare() with a prepare_for_<type> branch instead of reusing the existing one

Example fix

// before
evaluator = CocoEval(coco_gt, iou_type="bboxes")
// after
evaluator = CocoEval(coco_gt, iou_type="bbox")
Defensive patterns

Strategy: validation

Validate before calling

VALID_IOU_TYPES = {"bbox", "segm", "keypoints"}
assert iou_type in VALID_IOU_TYPES, f"iou_type must be one of {VALID_IOU_TYPES}, got {iou_type}"

Type guard

def is_valid_iou_type(t) -> bool:
    return t in ("bbox", "segm", "keypoints")

Try / catch

try:
    results = evaluator.prepare(predictions)
except ValueError as e:
    if "Unknown iou type" in str(e):
        iou_type = "bbox"
        results = evaluator.prepare(predictions)

Prevention

When it happens

Trigger: Constructing COCOResults/CocoEval with iou_type outside {bbox, segm, keypoints}, e.g. a typo like 'bboxes' or a task-specific string like 'tracking'.

Common situations: Hand-edited COCO annotation 'info' fields, custom datasets with unusual iou_type, version drift between pycocotools-style evaluators and this vendored copy.

Related errors


AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30). Data as JSON: /api/errors/61f68b6d32db6b4d. Report an issue: GitHub.