Views
No views yet

| File | Precision | Size | Use |
|---|---|---|---|
onnx/model_fp16.onnx | fp16 weights, fp32 I/O | ~54 MB | Recommended, WebGPU (onnxruntime-web) |
onnx/model.onnx | fp32 | ~108 MB | Reference build |
weights.pt | fp32 | ~121 MB | Source checkpoint |
input: [1, 3, 512, 512] float32 NCHW. Resolution is fixed.dets: [1, 100, 4] float32, boxes in cxcywh normalized 0..1.labels: [1, 100, 2] float32, raw logits. Apply sigmoid.metadata_props.1import numpy as np, onnxruntime as ort
2from PIL import Image
3
4MEAN = np.array([0.485, 0.456, 0.406], np.float32)
5STD = np.array([0.229, 0.224, 0.225], np.float32)
6THRESHOLD = ... # set from the CHANGELOG entry for the revision you pin
7
8img = Image.open("input.jpg").convert("RGB")
9W, H = img.size
10side = min(W, H)
11x0, y0 = (W - side) // 2, (H - side) // 2
12square = img.crop((x0, y0, x0 + side, y0 + side)).resize((512, 512), Image.BILINEAR)
13x = ((np.asarray(square, np.float32) / 255.0 - MEAN) / STD).transpose(2, 0, 1)[None]
14
15sess = ort.InferenceSession("onnx/model_fp16.onnx", providers=["CPUExecutionProvider"])
16dets, labels = sess.run(None, {sess.get_inputs()[0].name: x})
17
18prob = 1 / (1 + np.exp(-labels[0]))
19idx = np.argsort(-prob.reshape(-1))
20query, cls, score = idx // 2, idx % 2, prob.reshape(-1)[idx]
21cx, cy, bw, bh = dets[0][query].T
22xyxy = np.stack([x0 + (cx - bw / 2) * side, y0 + (cy - bh / 2) * side,
23 x0 + (cx + bw / 2) * side, y0 + (cy + bh / 2) * side], axis=1)
24
25for s, c, b in zip(score, cls, xyxy):
26 if s >= THRESHOLD and c == 1:
27 print(f"police vehicle {s:.2f} at {b.round().astype(int).tolist()}")