Micro accuracy in segmentation is always the same as macro accuracy

Open Beginner friendly
#674 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@guptakaran20 is already working on this.

Since Nov 7, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
numpy, python

Research direction

Start by reading perceptionmetrics/utils/segmentation_metrics.py, especially get_tn(per_class=False) and the micro accuracy calculation. Reproduce the issue with the NumPy example in the report, then check any segmentation metric tests covering averaged accuracy. Done when micro accuracy reports 4/6 (0.667) for the example and macro behavior remains correct.

Written by the indexing model from the issue text.

Description

Micro accuracy for segmentation is not the real pixel accuracy, and it always comes out the same as macro accuracy.

Example with 3 classes and 6 pixels, 4 predicted right. Real accuracy is 0.667 but both show 0.778:

import numpy as np
from perceptionmetrics.utils.segmentation_metrics import SegmentationMetricsFactory

m = SegmentationMetricsFactory(n_classes=3)
m.update(np.array([0, 0, 1, 1, 0, 0]), np.array([0, 0, 1, 1, 2, 2]))
print(m.get_averaged_metric("accuracy", "macro"))  # 0.778
print(m.get_averaged_metric("accuracy", "micro"))  # 0.778

I think it is because get_tn(per_class=False) adds up the true negatives of every class.

Possible fix: for micro, use correct pixels / total pixels.

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.