Skip to content

Fix MeanAveragePrecision on non-contiguous inputs - #3901

Open
mottopanikeiku wants to merge 1 commit into
pytorch:masterfrom
mottopanikeiku:fix-map-noncontiguous
Open

mottopanikeiku wants to merge 1 commit into
pytorch:masterfrom
mottopanikeiku:fix-map-noncontiguous

Conversation

@mottopanikeiku

Copy link
Copy Markdown

Description:

Use reshape instead of view when flattening binary inputs and multiclass targets, matching the other paths in _prepare_output. This fixes evaluation on valid transposed segmentation tensors. Add four layout regression cases and document the supported layout.

Reproducer:

import torch
from ignite.metrics import MeanAveragePrecision

p = torch.tensor([[[0.9, 0.2], [0.1, 0.8]]]).transpose(1, 2)
y = torch.tensor([[[1, 0], [0, 1]]]).transpose(1, 2)
m = MeanAveragePrecision()
m.update((p, y))
print(m.compute())
Before After
RuntimeError: view size is not compatible with input tensor's size and stride 1.0

Tests: pytest tests/ignite/metrics/test_mean_average_precision.py -m 'not distributed and not tpu': 15 passed, 36 deselected. Three new cases fail before the fix; the fourth is an existing-supported-layout control. Ruff check and format check pass.

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

I used AI assistance (Claude and GPT-6 Astra) to find, fix and test this bug.

I replaced view with reshape when flattening binary inputs and multiclass targets. Valid transposed segmentation tensors previously raised instead of computing average precision.

I added regression tests comparing strided inputs with their contiguous equivalents and documented that layout is supported.

Assisted-by: Claude
Assisted-by: GPT-6 Astra
Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com>
@github-actions github-actions Bot added the module: metrics Metrics module label Oct 17, 2026

This branch has not been deployed

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

Labels

module: metrics Metrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant