open-mmlab/mmdetection · critical · Exception

no prediction for the image with id: {img_id}

Error message

no prediction for the image with id: {img_id}

What it means

CocoPanopticMetric.compute_metrics pairs each ground-truth annotation with predictions by image_id; if a ground-truth image id has no matching entry in the prediction json, it raises a generic Exception 'no prediction for the image with id: ...'. pq_compute_multi_core requires matched (gt, pred) pairs for every image, so a missing prediction is fatal rather than counted as zero PQ.

Source

Thrown at mmdet/evaluation/metrics/coco_panoptic_metric.py:503

                return dict()

            imgs = self._coco_api.imgs
            gt_json = self._coco_api.img_ann_map
            gt_json = [{
                'image_id': k,
                'segments_info': v,
                'file_name': imgs[k]['segm_file']
            } for k, v in gt_json.items()]
            pred_json = load(json_filename)
            pred_json = dict(
                (el['image_id'], el) for el in pred_json['annotations'])

            # match the gt_anns and pred_anns in the same image
            matched_annotations_list = []
            for gt_ann in gt_json:
                img_id = gt_ann['image_id']
                if img_id not in pred_json.keys():
                    raise Exception('no prediction for the image'
                                    ' with id: {}'.format(img_id))
                matched_annotations_list.append((gt_ann, pred_json[img_id]))

            pq_stat = pq_compute_multi_core(
                matched_annotations_list,
                gt_folder,
                pred_folder,
                self.categories,
                backend_args=self.backend_args,
                nproc=self.nproc)

        else:
            # aggregate the results generated in process
            if self._coco_api is None:
                categories = dict()
                for id, name in enumerate(self.dataset_meta['classes']):
                    isthing = 1 if name in self.dataset_meta[
                        'thing_classes'] else 0

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Ensure the prediction json covers every image_id in the GT ann_file (dump predictions for the full test set)
  2. Verify ann_file, gt folder and the prediction file come from the same dataset split
  3. If some images legitimately have no predictions, ensure the dump step still writes an empty prediction entry for those image ids

Example fix

# before: offline eval with partial predictions
python tools/test.py cfg.py results.pkl --cfg-options test_evaluator.ann_file=ann.json
# after: dump for the FULL test set, then eval with the matching json
python tools/test.py cfg.py ckpt.pth --out results.pkl  # complete dump first
Defensive patterns

Strategy: validation

Validate before calling

gt_ids = {ann['image_id'] for ann in gt_json['annotations'] if 'segments_info' in ann} if False else {a['image_id'] for a in gt_json.get('annotations', [])}
# simpler: before eval, compare id sets
gt_ids = {im['id'] for im in gt_json['images']}
pred_ids = set(pred_json.keys())
missing = gt_ids - pred_ids
assert not missing, f'predictions missing image ids: {sorted(missing)[:5]}...'

Type guard

def predictions_cover_gt(gt_image_ids: set, pred_json: dict) -> bool:
    return gt_image_ids.issubset(pred_json.keys())

Try / catch

try:
    evaluator.compute_metrics(results)
except Exception as e:
    if 'no prediction for the image' in str(e):
        missing = gt_ids - set(pred_json.keys())
        raise RuntimeError(f're-dump predictions; missing ids: {sorted(missing)[:10]}') from e
    raise

Prevention

When it happens

Trigger: Running panoptic eval when the dumped predictions json lacks some image ids present in the GT annotation file — e.g. results dumped from a subset of images, an interrupted dump, mismatched ann_file vs. prediction folder, or predictions filtered out (empty pred for an image not written).

Common situations: Evaluating on a partial results file (resume/re-run of DumpDetResults offline eval); GT json regenerated with extra images; test set and ann_file out of sync; score_thr filtering removing all predictions so the image is never dumped.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/6f41506975d6edce. Report an issue: GitHub.