open-mmlab/mmdetection · error · KeyError
metrics {iou_metrics} is not supported. Only supports mIoU/m
Error message
metrics {iou_metrics} is not supported. Only supports mIoU/mDice/mFscore. What it means
IoUMetric (semantic segmentation) validates iou_metrics is a subset of {'mIoU','mDice','mFscore'}; anything else raises this KeyError at construction. The argument may be a single string or list, but only those three statistic names are implemented.
Source
Thrown at mmdet/evaluation/metrics/semseg_metric.py:62
names to disambiguate homonymous metrics of different evaluators.
If prefix is not provided in the argument, self.default_prefix
will be used instead. Defaults to None.
"""
def __init__(self,
iou_metrics: Sequence[str] = ['mIoU'],
beta: int = 1,
collect_device: str = 'cpu',
output_dir: Optional[str] = None,
format_only: bool = False,
backend_args: dict = None,
prefix: Optional[str] = None) -> None:
super().__init__(collect_device=collect_device, prefix=prefix)
if isinstance(iou_metrics, str):
iou_metrics = [iou_metrics]
if not set(iou_metrics).issubset(set(['mIoU', 'mDice', 'mFscore'])):
raise KeyError(f'metrics {iou_metrics} is not supported. '
f'Only supports mIoU/mDice/mFscore.')
self.metrics = iou_metrics
self.beta = beta
self.output_dir = output_dir
if self.output_dir and is_main_process():
mkdir_or_exist(self.output_dir)
self.format_only = format_only
self.backend_args = backend_args
def process(self, data_batch: dict, data_samples: Sequence[dict]) -> None:
"""Process one batch of data and data_samples.
The processed results should be stored in ``self.results``, which will
be used to compute the metrics when all batches have been processed.
Args:
data_batch (dict): A batch of data from the dataloader.
data_samples (Sequence[dict]): A batch of outputs from the model.View on GitHub (pinned to cfd5d3a985)
Solutions
- Restrict iou_metrics to mIoU, mDice, mFscore (any subset, exact casing)
- Remove mAcc/aAcc from the list; note overall accuracy is reported separately by the metric where supported
- Set iou_metrics='mIoU' (the common default) if unsure
Example fix
# before val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU', 'mAcc', 'aAcc']) # after val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'mIoU','mDice','mFscore'}
bad = set(iou_metrics if isinstance(iou_metrics, list) else [iou_metrics]) - SUPPORTED
assert not bad, f'unsupported iou_metrics: {bad}' Type guard
def are_valid_iou_metrics(v) -> bool:
items = [v] if isinstance(v, str) else v
return isinstance(items, list) and set(items).issubset({'mIoU','mDice','mFscore'}) Prevention
- Restrict iou_metrics to mIoU/mDice/mFscore
- Don't mix mmcls/mmseg metric names
- Start from official seg configs
When it happens
Trigger: Passing iou_metrics=['mIoU','mAcc','aAcc'] or iou_metrics='dice' (wrong casing/name) to IoUMetric; confusing semanticseg metrics with classification metrics.
Common situations: Copy-pasting metric lists from mmcls or older mmseg configs (mAcc/aAcc moved elsewhere or removed); misspelling 'mFscore' as 'f1' or 'mF1'.
Related errors
- metric must be a list or a str.
- out_indices must be a subset of range(0, 8). But received {o
- Expect "arch" to be either a string or a dict, got {type(arc
- num_classes={num_classes} is too small
- Invalid text mode "{self.text_mode}".
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/352aa48d47e06c99.
Report an issue: GitHub.