Skip to content

Count integer segmentation labels directly in mean IoU - #900

Open
snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:perf/bincount-mean-iou-labels
Open

snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:perf/bincount-mean-iou-labels

Conversation

@snygginghani

Copy link
Copy Markdown

Summary

Mean IoU builds three general-purpose histograms of integer class IDs for each image. Count valid IDs directly with numpy.bincount and remove duplicate copies of the reference mask. The integer path preserves class bounds and the existing treatment of ignored positions. Non-integer labels use the existing histogram path.

Benchmark and validation

I used the two ADE20K fixture masks (512×683 and 364×500), repeated 16 times each. For reproducible predictions, I reduced label IDs by one and shifted each prediction by its one-based index along alternating axes. This exercises the normal 150-class ADE20K label reduction path on 8.5 million pixels.

Workload Before After
Metric calculation, already-decoded arrays 417.5 ms 216.6 ms
Public .compute() with encoding and decoding 579.1 ms 436.1 ms

These are alternating-run medians on Windows 11, Intel Core i5-12400F and NumPy 2.4.6. Every result matched exactly. Benchmarked with num_labels=150, ignore_index=255, reduce_labels=True, and nan_to_num=0.

python -m pytest tests/test_mean_iou_histogram.py -q passed both cases, covering ignored pixels, out-of-range labels and the single-class boundary. Black, isort, flake8 and git diff --check passed. This change is limited to histogram work. Label remapping is covered separately by #810.

AI assistance was used to investigate and prepare the patch, tests and benchmark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant