Image segmentation eval crashes with model_to_dataset on RELLIS-3D

Open
#655 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@smitdighe is already working on this.

Since Nov 5, 2026.

  • #656 by @smitdighe — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch

Research direction

Start with TorchImageSegmentationModel.eval() in perceptionmetrics/models/torch_segmentation.py and the confusion matrix and metrics table code in perceptionmetrics/utils/segmentation_metrics.py. Reproduce with examples/tutorial_image_segmentation_sample.ipynb using translation_direction="model_to_dataset" and a dataset with non-contiguous class indices. Add the proposed one-image regression test in tests/models/test_torch_segmentation.py; done means evaluation returns the metrics table without an IndexError and both translation directions give matching per-class IoU.

Written by the indexing model from the issue text.

Description

Problem

TorchImageSegmentationModel.eval() raises IndexError with translation_direction="model_to_dataset" when the dataset class indices are not contiguous, e.g. RELLIS-3D (20 classes, indices up to 34) or Cityscapes label IDs. It fails only after inference over the whole split. The GUI Evaluator hits the same error.

Steps to reproduce

  1. Run examples/tutorial_image_segmentation_sample.ipynb up to "Init dataset and model objects".
  2. Evaluate with:
results = model.eval(dataset, split="test", translation_direction="model_to_dataset")

Expected vs actual

Expected: the metrics table, matching dataset_to_model (class names map one to one).

Actual: IndexError once inference finishes.

Logs

RELLIS-3D run (the first line is a print I added):

dataset classes: 20, max idx: 34
[...]
Traceback (most recent call last):
[...]
    return um.get_metrics_dataframe(metrics_factory, eval_ontology)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[...]
    results[class_name][metric] = float(per_class[class_data["idx"]])
                                        ~~~~~~~~~^^^^^^^^^^^^^^^^^^^
IndexError: index 23 is out of bounds for axis 0 with size 20

Screenshots

GUI evaluator with model_to_dataset

Error shown by the evaluator

RELLIS-3D sample run

Root cause

The confusion matrix is sized by the class count, not the largest index:

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/models/torch_segmentation.py#L409-L416

With model_to_dataset, eval_ontology is the dataset ontology, so for RELLIS-3D the matrix is 20x20. GT pixels with index 20 or higher are dropped here:

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/utils/segmentation_metrics.py#L59-L61

and building the table then indexes past the end:

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/utils/segmentation_metrics.py#L310-L311

Proposed approach

  • Size the matrix by the largest index, as export() already does. Unused indices get NaN and the macro average skips them.

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/datasets/segmentation.py#L111-L113

  • Add tests/models/test_torch_segmentation.py: a one-image dataset with indices 0, 3 and 4 and a model that returns the GT, expecting IoU 1.0 in both directions. It uses the torch skip guard from tests/utils/test_torch.py.
  • Locally, both directions then give identical per-class IoU on the RELLIS-3D sample (mIoU 0.4617), and the suite passes.
  • The same line exists in the LiDAR, TensorFlow and eval_preds paths, which I could not run here. Should they go in the same PR?

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/models/torch_segmentation.py#L738

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/models/tf_segmentation.py#L385

https://github.com/JdeRobot/PerceptionMetrics/blob/b1ad785d2cd505027458d467bf6bef7c33e6ce47/perceptionmetrics/datasets/segmentation.py#L304

Expected impact

model_to_dataset no longer crashes for non-contiguous dataset ontologies. Contiguous ontologies are unaffected (largest index plus one equals the class count).

Environment

  • Commit: b1ad785d2cd505027458d467bf6bef7c33e6ce47 (master)
  • OS: Ubuntu 26.04.1 LTS on WSL2, kernel 6.6.114.1-microsoft-standard-WSL2
  • Python 3.12.14, torch 2.4.1+cpu, torchvision 0.19.1+cpu, numpy 1.26.4, streamlit 1.54.0

I'm happy to open a PR once the approach looks right to you.

cc @dpascualhe

Dominant language
Python
Stars
114
Forks
116
Avg merge
1d 7h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JdeRobot/PerceptionMetrics

All issues in JdeRobot/PerceptionMetrics

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.