#5083·kornia

`mean_average_precision`: float64 inputs miss the recall thresholds 0.1, 0.2, 0.3, 0.4, 0.6 and 0.8

Author: ducha-aikiCreated Sep 28, 2026Updated Sep 28, 2026

mean_average_precision builds its 11 recall thresholds with torch.arange(start=0, end=1.1, step=0.1).tolist(), in kornia/metrics/mean_average_precision.py. The arange is float32, so the thresholds are float32 values widened to Python floats: 0.10000000149, 0.20000000298, 0.30000001192, 0.40000000596, 0.60000002384 and 0.80000001192.

A float32, float16 or bfloat16 recall tensor compares against each threshold in its own dtype, so a recall of exactly 1/10 reaches the 0.1 threshold. A float64 recall of 1/10 is 0.1000000000000000055, which is below 0.10000000149, so float64 inputs skip that threshold. The same happens to every recall that lands exactly on 0.1, 0.2, 0.3, 0.4, 0.6 or 0.8. That is common: any class with 5 or 10 objects hits them.

python
import torch
from kornia.metrics import mean_average_precision

gt = torch.tensor([[i * 20.0, 0.0, i * 20.0 + 10, 10.0] for i in range(10)])
det = torch.cat([gt[:1], torch.tensor([[500.0, 500, 510, 510]]), gt[1:]])  # TP, FP, then 9 TP
scores = torch.linspace(1.0, 0.5, 11)
for dtype in (torch.float32, torch.float64):
    print(dtype, mean_average_precision([det.to(dtype)], [torch.ones(11, dtype=torch.long)], [scores.to(dtype)],
                                        [gt.to(dtype)], [torch.ones(10, dtype=torch.long)], 2)[1])
# torch.float32 {1: 0.9256...}   torch.float64 {1: 0.9173...}

The reference the function cites (sgrvinod calculate_mAP) works in float32 and returns 0.9256.

With recall_thresholds = [i / 10 for i in range(11)], float64 matches the reference on 288 of 288 random multi-image, multi-class inputs, where the current code matches on 234. A Python float is cast to the tensor's dtype in the comparison, so float32 and half keep their current values.

Posted on behalf of @ducha-aiki by Claude (Opus 5.5).