NURLNURL registrynurl-lang.org →

← objdet

objdet 0.2.0 API

detect.nu

packages/objdet/src/detect.nu — tiny-YOLOv2 detection head.

Decodes the [1,125,13,13] grid the network produces into boxes: each of the 13×13 cells predicts 5 anchor boxes, each carrying (tx,ty,tw,th,to)

sigmoid/exp; the score is objectness × softmax(class). Overlapping boxes of the same class are then removed by non-max suppression.

API

& c @ nurl_peek_f32 *u base i idx → f

: Detection { i cls f score f cx f cy f w f h }

A detection in normalised (0..1) centre/size coordinates.

@ sigmoid f x → f

@ voc_class i i → s

VOC 2007 20 classes (tiny-yolov2 order).

@ yolo_decode *u grid f thresh → ( Vec Detection )

Decode the grid into detections above thresh.

@ yolo_nms ( Vec Detection ) dets f iou_thresh → ( Vec Detection )

Non-max suppression: sort by score, greedily keep, drop same-class boxes overlapping a kept box by more than iou_thresh.


image.nu

packages/objdet/src/image.nu — minimal image I/O for object detection.

Reads/writes binary PPM (P6) — the simplest lossless RGB container, which ffmpeg/convert produce from any image or video frame. Plus the pixel ops a detector needs: bilinear resize (to the model's input size), box drawing (for annotated output), and packing to an NCHW float tensor.

An Image keeps the raw file bytes and an offset to the pixel data, so reading copies nothing; a freshly built image (resize/blank) owns a new byte buffer. Pixels are interleaved RGB, row-major.

API

& c @ nurl_poke_f32 *u base i idx f val → v

: Image { i w i h ( Vec u ) buf i off }

@ img_w Image im → i

@ img_h Image im → i

@ img_get Image im i x i y i ch → i

Byte at (x,y,ch); clamped to the edge so resize/draw never read OOB.

@ img_set Image im i x i y i ch i val → v

@ ppm_read s path → ?Image

@ img_blank i w i h → Image

A blank (black) image of the given size, owning a fresh buffer.

@ ppm_write s path Image im → b

@ img_resize Image im i nw i nh → Image

── bilinear resize ───────────────────────────────────────────────

@ img_draw_rect Image im i x0 i y0 i x1 i y1 i r i gg i bb → v

Draw a (thick) rectangle outline in the given colour.

@ img_to_nchw Image im → *u

── pack to NCHW float tensor (values 0..255) ───────────────────── Writes a fresh host buffer of 3HW floats in CHW order; the model's in-graph preprocessor scales by 1/255.


main.nu

packages/objdet/src/main.nu — object detection from pure NURL on the GPU.

objdet <model.onnx> <image.ppm> [out.ppm] objdet <model.onnx> --video <in_dir> <out_dir> <count>

Loads any tiny-YOLOv2-style ONNX detector (e.g. the ONNX model-zoo tinyyolov2-8.onnx), runs it on the GPU through packages/onnx, decodes the grid into labelled boxes (packages objdet/detect), prints them, and (for an image) writes an annotated PPM. The video mode runs a frame sequence frame00000.ppm … reusing one GPU engine (kernels compiled once).

Convert to/from PPM with ffmpeg/ImageMagick, e.g. convert photo.jpg photo.ppm ffmpeg -i clip.mp4 -vf fps=10 in/frame%05d.ppm ffmpeg -framerate 10 -i out/frame%05d.ppm out.mp4

API

@ p s m → v

@ pf f x → v

@ pn i n → v

@ streqm s a s b → b

@ shape4 i a i b i c i d → ( Vec i )

@ detect_image *Engine e OGraph g Image im f conf f iou → i

Run the detector on one image, draw boxes in place, print detections. Returns the number of detections.

@ load_model s path *u pok → OGraph

@ frame_path s dir i n → String

frame path: <dir>/frameNNNNN.ppm

@ main → i