WZMIAOMIAO/deep-learning-for-image-processing · error · ValueError
Unknown iou type {}
Error message
Unknown iou type {} What it means
CocoEvaluator.prepare() dispatches prediction-preparation based on the COCO iou_type ('bbox', 'segm', 'keypoints'). If iou_type is anything else, it raises ValueError because there is no prepare_for_coco_* method for it. This guards against typos or unsupported task types passed when constructing/using CocoEvaluator.
Source
Thrown at pytorch_object_detection/yolov3_spp/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
- Use one of the supported iou_type values: 'bbox', 'segm', or 'keypoints'.
- Check the exact strings passed in the iou_types list when constructing CocoEvaluator and fix typos.
- If you need a new task type, add a prepare_for_coco_<type> method and extend the dispatch chain in prepare().
Example fix
// before iou_types = ['box'] coco_evaluator = CocoEvaluator(base_dataset, iou_types=iou_types) // after iou_types = ['bbox'] coco_evaluator = CocoEvaluator(base_dataset, iou_types=iou_types)
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'bbox', 'segm', 'keypoints'}
assert set(iou_types).issubset(SUPPORTED), f"bad iou_type: {iou_types}" Type guard
def is_supported_iou_type(t) -> bool:
return isinstance(t, str) and t in ('bbox', 'segm', 'keypoints') Try / catch
try:
evaluator.update(predictions)
except ValueError as e:
logging.error(f"COCO eval misconfigured: {e}"); raise Prevention
- Keep iou_types as a module-level constant with only the three supported strings
- Derive iou_types from the task type rather than hand-editing strings
- Unit-test CocoEvaluator construction for each supported task
When it happens
Trigger: Calling prepare() (indirectly via update()) on a CocoEvaluator that was constructed with an iou_type string other than 'bbox', 'segm', or 'keypoints' — e.g. a typo like 'box' or 'segmentation'.
Common situations: Typo in the iou_type list passed to CocoEvaluator; copying evaluation code from a detection example into a segmentation or keypoint project and editing the string incorrectly; using a custom task type the evaluator doesn't support.
Related errors
- return_layers are not present in model
- illegal stride value.
- The inverted_residual_setting should not be empty.
- replace_stride_with_dilation should be None or a 3-element t
- not support iou_type: {self.iou_type}
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/40f8d275dea538c1.
Report an issue: GitHub.