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
CocoEval.update() only implements result preparation for iou_type == 'keypoints'; any other configured iou_type (e.g. 'bbox' or 'segm') hits the else branch and raises KeyError with the unsupported type. The wrapper class is a keypoint-specific adaptation of pycocotools' COCOeval, so it deliberately rejects other evaluation types.
Source
Thrown at pytorch_keypoint/HRNet/train_utils/coco_eval.py:99
keypoints = np.concatenate([keypoints, scores], axis=1)
keypoints = np.reshape(keypoints, -1)
# We recommend rounding coordinates to the nearest tenth of a pixel
# to reduce resulting JSON file size.
keypoints = [round(k, 2) for k in keypoints.tolist()]
res = {"image_id": target["image_id"],
"category_id": 1, # person
"keypoints": keypoints,
"score": target["score"] * k_score}
self.results.append(res)
def update(self, targets, outputs):
if self.iou_type == "keypoints":
self.prepare_for_coco_keypoints(targets, outputs)
else:
raise KeyError(f"not support iou_type: {self.iou_type}")
def synchronize_results(self):
# 同步所有进程中的数据
eval_ids, eval_results = merge(self.obj_ids, self.results)
self.aggregation_results = {"obj_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(eval_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
- Set iou_type="keypoints" where the evaluator is constructed for human-pose validation.
- If you need bbox/segm eval, use pycocotools COCOeval directly or the torchvision coco_eval wrapper that supports those types.
- Use the generic coco_eval.py from pytorch_object_detection/ references (supports bbox/segm) for detection tasks.
- Guard the construction site to assert the supported value before training starts.
Example fix
# before coco_evaluator = CocoEvaluator(base_dataset, iou_type="bbox") # after coco_evaluator = CocoEvaluator(base_dataset, iou_type="keypoints")
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED_IOU_TYPES = {"keypoints"}
assert iou_type in SUPPORTED_IOU_TYPES, f"HRNet CocoEval only supports {SUPPORTED_IOU_TYPES}, got {iou_type}" Type guard
def is_keypoint_eval(iou_type: str) -> bool:
return iou_type == "keypoints" Try / catch
try:
coco_evaluator.update(targets, outputs)
except KeyError as e:
logging.error("Unsupported iou_type configured: %s", e)
raise SystemExit("Set iou_type='keypoints' for pose evaluation") Prevention
- Keep task-specific configs (bbox vs keypoints) separate.
- Assert iou_type at evaluator construction time.
- Use pycocotools COCOeval directly for bbox/segm tasks.
When it happens
Trigger: Constructing the evaluator (or passing a config) with iou_type set to anything other than "keypoints", then calling update(targets, outputs) during validation.
Common situations: Copying the HRNet eval utils into a detection project and leaving/setting iou_type='bbox'; a config file shared between bbox and keypoint tasks; refactoring where the default iou_type changed.
Related errors
- Please run accumulate() first
- Unknown iou type {}
- Please run accumulate() first
- illegal stride value.
- The inverted_residual_setting should not be empty.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/7f1a3ea6df39288c.
Report an issue: GitHub.