code wiki / (root) / nx_pose_score_one.nx

nx_pose_score_one.nx source

↩ module page · 69 lines · 3878 B

1// nx_pose_score_one.nx -- the FIRST real external-GT score: map the ViTPose port's 48x64 heatmap 2// keypoints (from nx_vitpose_forward on COCO 000000397133.jpg person0) into image coords via the 3// emitted crop box, and compute OKS vs the REAL COCO GT keypoints. This is industry grading, not 4// self-validation: GT = COCO's annotations. area = bbox w*h (f32, per nx_coco_oks contract). 5// lineage_id: nx_pose_score_one_v1 6import "nx_syscalls.nx" 7import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 8import "nx_coco_oks.nx" 9 10func so_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return n } 11// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 12// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 13// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 14// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 15func so_wn(v: i64) -> i64 { nxi_out(v); return 0 } 16 17func main() -> i64 { 18 // crop box emitted by nx_pose_preprocess (person0 of 000000397133) 19 let x0: i64 = 313; let y0: i64 = 34; let cw: i64 = 258; let ch: i64 = 346 20 21 // port output: 17 heatmap keypoints (W48 x H64), from the live nx_vitpose_forward run 22 let hx: *i64 = sys_mmap(8*17); let hy: *i64 = sys_mmap(8*17) 23 hx[0]=21; hy[0]=10; hx[1]=22; hy[1]=10; hx[2]=21; hy[2]=10; hx[3]=23; hy[3]=11 24 hx[4]=26; hy[4]=11; hx[5]=19; hy[5]=17; hx[6]=29; hy[6]=18; hx[7]=15; hy[7]=23 25 hx[8]=32; hy[8]=25; hx[9]=18; hy[9]=25; hx[10]=28; hy[10]=26; hx[11]=19; hy[11]=32 26 hx[12]=26; hy[12]=32; hx[13]=17; hy[13]=42; hx[14]=26; hy[14]=42; hx[15]=15; hy[15]=53 27 hx[16]=27; hy[16]=53 28 29 // REAL COCO GT person0 (line1 of keypoints_validation.jsonl): [x,y,v] x17 30 let gx: *i64 = sys_mmap(8*17); let gy: *i64 = sys_mmap(8*17); let gv: *i64 = sys_mmap(8*17) 31 gx[0]=433; gy[0]=94; gv[0]=2; gx[1]=434; gy[1]=90; gv[1]=2; gx[2]=0; gy[2]=0; gv[2]=0 32 gx[3]=443; gy[3]=98; gv[3]=2; gx[4]=0; gy[4]=0; gv[4]=0; gx[5]=420; gy[5]=128; gv[5]=2 33 gx[6]=474; gy[6]=133; gv[6]=2; gx[7]=396; gy[7]=162; gv[7]=2; gx[8]=489; gy[8]=173; gv[8]=2 34 gx[9]=0; gy[9]=0; gv[9]=0; gx[10]=0; gy[10]=0; gv[10]=0; gx[11]=419; gy[11]=214; gv[11]=2 35 gx[12]=458; gy[12]=215; gv[12]=2; gx[13]=411; gy[13]=274; gv[13]=2; gx[14]=458; gy[14]=273; gv[14]=2 36 gx[15]=402; gy[15]=333; gv[15]=2; gx[16]=465; gy[16]=334; gv[16]=2 37 38 // map heatmap -> image coords: img = origin + (h*2+1)*span / (2*cells) 39 let px: *i64 = sys_mmap(8*17); let py: *i64 = sys_mmap(8*17) 40 var i: i64 = 0 41 while i < 17 { 42 px[i] = x0 + ((hx[i]*2+1)*cw)/(2*48) 43 py[i] = y0 + ((hy[i]*2+1)*ch)/(2*64) 44 i = i + 1 45 } 46 47 // per-visible-keypoint pixel error (evidence) 48 so_w("per-kp pred->gt (visible): \n" as *u8) 49 i = 0 50 while i < 17 { 51 if gv[i] > 0 { 52 let dx: i64 = px[i]-gx[i]; let dy: i64 = py[i]-gy[i] 53 so_w(" kp" as *u8); so_wn(i); so_w(" pred(" as *u8); so_wn(px[i]); so_w("," as *u8); so_wn(py[i]) 54 so_w(") gt(" as *u8); so_wn(gx[i]); so_w("," as *u8); so_wn(gy[i]); so_w(") d2=" as *u8); so_wn(dx*dx+dy*dy); so_w("\n" as *u8) 55 } 56 i = i + 1 57 } 58 59 let area: i64 = nx_i32_to_f32(109*277) // bbox w*h as f32 (coco_oks contract) 60 let oks: i64 = coco_oks(px, py, gx, gy, gv, 17, area) 61 so_w("REAL OKS (COCO GT, 000000397133 person0) = " as *u8); so_wn(oks); so_w(" / 1000\n" as *u8) 62 so_w("thresholds passed @[.50..0.95]: " as *u8) 63 var t: i64 = 500; var np: i64 = 0 64 while t <= 950 { if oks >= t { np = np + 1 } t = t + 50 } 65 so_wn(np); so_w("/10 (AP contribution for this person = " as *u8); so_wn(np*100); so_w("/1000)\n" as *u8) 66 if oks > 0 { sys_exit(0) } 67 sys_exit(1) 68 return 0 69}