code wiki / (root) / nx_coco_ap.nx

nx_coco_ap.nx source

↩ module page · 21 lines · 1164 B

1// nx_coco_ap.nx -- COCO keypoint AP@[.5:.95] from per-image OKS (the top-down single-person eval: GT box given, one 2// prediction per image). AP = mean over the 10 OKS thresholds {.50,.55,...,.95} of the fraction of predictions whose 3// OKS >= threshold. This is the number the field reports (ViTPose 75.8). Composes nx_coco_oks (per-image) -> this. 4// The full COCO detection AP (P-R over confidence, multi-instance matching) is a superset; this is the standard 5// keypoint-eval simplification used when the person box is provided (which is our top-down setting). license_tier: ORIGINAL 6import "nx_syscalls.nx" 7 8// oks_permille[n] = per-image OKS in permille (0..1000). Returns AP@[.5:.95] in permille. 9func coco_ap(oks_permille: *i64, n: i64) -> i64 { 10 if n <= 0 { return 0 } 11 var sum: i64 = 0 12 var t: i64 = 500 13 while t <= 950 { 14 var cnt: i64 = 0 15 var i: i64 = 0 16 while i < n { if oks_permille[i] >= t { cnt = cnt + 1 } i = i + 1 } 17 sum = sum + (cnt * 1000) / n // permille of predictions passing this OKS threshold 18 t = t + 50 19 } 20 return sum / 10 // mean over the 10 thresholds 21}