WZMIAOMIAO/deep-learning-for-image-processing · error · KeyError
not support iou_type: {self.iou_type}
Error message
not support iou_type: {self.iou_type} What it means
CocoEvaluator.update only supports the iou_types 'bbox' and 'segm'; anything else (e.g. 'keypoints') has no prepare method wired up and raises KeyError. Note the message says 'not support' despite being a KeyError.
Source
Thrown at pytorch_object_detection/mask_rcnn/train_utils/coco_eval.py:130
class_idx = int(label)
if self.classes_mapping is not None:
class_idx = int(self.classes_mapping[str(class_idx)])
res = {"image_id": img_id,
"category_id": class_idx,
"segmentation": rle,
"score": round(score, 3)}
res_list.append(res)
self.results.append(res_list)
def update(self, targets, outputs):
if self.iou_type == "bbox":
self.prepare_for_coco_detection(targets, outputs)
elif self.iou_type == "segm":
self.prepare_for_coco_segmentation(targets, outputs)
else:
raise KeyError(f"not support iou_type: {self.iou_type}")
def synchronize_results(self):
# 同步所有进程中的数据
eval_ids, eval_results = merge(self.img_ids, self.results)
self.aggregation_results = {"img_ids": eval_ids, "results": eval_results}
# 主进程上保存即可
if is_main_process():
results = []
[results.extend(i) for i in eval_results]
# write predict results into json file
json_str = json.dumps(results, indent=4)
with open(self.results_file_name, 'w') as json_file:
json_file.write(json_str)
def evaluate(self):
# 只在主进程上评估即可
if is_main_process():View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Restrict iou_types to 'bbox' or 'segm' when building CocoEvaluator
- Fix the typo in the iou_type string
- Add a prepare_for_coco_keypoints-style branch in coco_eval.py if you need keypoints
Example fix
// before evaluator = CocoEvaluator(coco_gt, iou_types=["keypoints"]) // after evaluator = CocoEvaluator(coco_gt, iou_types=["bbox", "segm"])
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'bbox', 'segm'}
assert set(iou_types).issubset(SUPPORTED), f"iou_types must be subset of {SUPPORTED}"
evaluator = CocoEvaluator(coco_gt, iou_types=iou_types) Type guard
def supported_iou_types(types):
return all(t in ('bbox', 'segm') for t in types) Try / catch
try:
evaluator.update(targets, outputs)
except KeyError as e:
if 'iou_type' in str(e): logger.error('unsupported iou_type; use bbox or segm')
raise Prevention
- Only pass 'bbox' or 'segm' iou_types with this vendored evaluator
- Add tests that instantiate the evaluator with your configured types
- Patch in keypoints support upstream before using it
When it happens
Trigger: Constructing CocoEvaluator(coco_gt, iou_types=["keypoints"]) or any unsupported type, then calling update(targets, outputs).
Common situations: Copying detection code to a pose-estimation task; typo in iou_type like 'bboxs' or 'segmentation'; passing a list element from torchvision defaults that this vendored copy doesn't implement.
Related errors
- Unknown iou type {}
- Please run accumulate() first
- not support iou_type: {self.iou_type}
- Please run accumulate() first
- Please run accumulate() first
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/6ab5595ce09bde8d.
Report an issue: GitHub.