Skip to content
Get started

Camera answers on a device

Use with an AI tool

When you watch a camera, Curva trains a small head per yes/no question on that camera’s frames, from the hosted model’s answers. Once trained, the heads can run on the device itself: a device decides offline, on the same image encoder and the same heads the server uses, and gets the server’s answers bit for bit.

The device needs two files:

File What it holds Size How often it changes
Encoder file (.cvenc) the int8 CLIP ViT-B/32 image encoder, pinned by its SHA-256 153 MB when Curva changes the encoder
Vision pack (.cvpack) one stream’s trained heads: thresholds, calibration, the switch-on state about 145 KB a question every time the server retrains

Ship the encoder once (in the app, or one download) and send vision packs as small updates. One encoder serves every pack, so a device with two cameras loads it once.

Terminal window
curva pack --encoder -o clip.cvenc
curva pack --project fleet --db curva.db --stream cab-17 --questions cab.json -o cab-17.cvpack
stream `cab-17` of project `fleet`:
phone_in_hand: on, answers alone when sure
seatbelt: shadowing, gives its probability and always abstains until it earns its thresholds
smoking: still learning, left out
the device also needs the encoder file once: `curva pack --encoder -o clip.cvenc`
wrote cab-17.cvpack (0.3 MB)

--stream is the stream name the camera used on /v1/watch, and --questions a JSON file with the same questions object (curva recipe show <name> prints a ready one). Yes/no questions with a trained head go in; text questions, questions that depend on another answer, and heads still learning stay out. --encoder fetches and converts the model the first time, like the server does.

For a frame and a question: p, the probability of yes; abstain; and audit. abstain is true exactly when the server would send the frame to the hosted model: the head is still shadowing, the frame does not look like the frames it learned on, or p is under the threshold the head earned. Treat an abstain as “unknown”, or send that frame to Curva when the device is online. audit marks the one sure answer in 20 the server would check with the hosted model anyway; queue those frames if you upload anything.

#include "curva_pack.h"
CurvaEncoder *encoder = NULL;
int32_t code = curva_encoder_open(encoder_bytes, encoder_len, 4, &encoder);
CurvaVision *vision = NULL;
if (code == CURVA_PACK_OK) code = curva_vision_open(encoder, pack_bytes, pack_len, &vision);
if (code != CURVA_PACK_OK) printf("%s\n", curva_pack_error(code));
CurvaSight sight;
code = curva_vision_ask_jpeg(vision, "phone_in_hand", jpeg, jpeg_len, &sight);
if (code == CURVA_PACK_OK && !sight.abstain && sight.p >= 0.5) warn_driver();
curva_vision_free(vision);
curva_encoder_free(encoder);

The third argument of curva_encoder_open is the number of threads for one frame (0 for every core). For several questions on one frame, encode once and ask each question with the vector:

float vector[CURVA_VISION_DIM];
curva_encoder_embed_jpeg(encoder, jpeg, jpeg_len, vector, CURVA_VISION_DIM);
for (size_t q = 0; q < curva_vision_questions(vision); q++)
curva_vision_ask(vision, curva_vision_question(vision, q), vector, CURVA_VISION_DIM, &sight);

curva_encoder_embed_rgb(encoder, rgb, width, height, vector, CURVA_VISION_DIM) takes raw RGB (3 bytes a pixel, rows top to bottom) from a camera pipeline that has no JPEG. JPEGs are read the way the server reads them, EXIF orientation included. The library copies what it needs, so free the file bytes after opening. One encoder and one pack answer from any number of threads at once.

The codes are the on-phone guard’s, plus two:

Code Meaning
9 the vision pack was made for another encoder than the encoder file
10 the frame is not a readable JPEG, the RGB size does not match its width and height, it has more than 16 million pixels, or a vector is not 512 finite numbers

No call crashes the app: null pointers, damaged files and bad frames return a code, and an internal panic is caught and returned as 8.

The same library as the on-phone guard, with the same commands. Its dependencies are pure Rust (curva-core, serde_json, zune-jpeg): no tokio, HTTP, SQLite, crypto or C code. The encoder uses the arm64 dot-product instructions or AVX2 on x86-64 when the CPU has them, and plain Rust otherwise; on this laptop the plain path gave the same embeddings bit for bit. A server on x86-64 against a device on arm64 was not compared.

Training stays on the server. After it retrains (or when a head switches on), run curva pack --stream again and ship the new vision pack. In the app, open the new pack against the encoder you already hold, switch to it, then free the old one. If the new pack does not open (damaged, a newer format, or code 9 because the server moved to a new encoder), keep the old one and fetch the encoder file that matches. Both files are checked against damage (CRC-32), not signed: check that they came from your backend before opening them.

On 26 October 2026, on an Apple M1 laptop (not a phone) shared with other builds, release build. Heads were trained on the server with its own settings, then put in a vision pack. For each held-out frame, the server path decodes it with the server’s decoder, encodes it on 8 threads and asks its heads; the device path opens the encoder file and the pack through the C functions and calls curva_vision_ask_jpeg. Two sets:

  • Photos: 39 everyday questions on Open Images photos with human labels. Up to 450 labelled photos per question to learn from; the last 50 of each held out. 33 questions had a trained head (3 of them on), 1,650 held-out photos.
  • Video: the 77 helmet and phone driving clips (6 s at 10 fps, a slow zoom over a labelled photo), cut into 4,620 frames. Every third clip held out; the heads learned from every frame of the others, each labelled with its clip’s label. Both heads trained and both shadowing (see below), 1,440 held-out frames from 24 clips.
Photos Video frames
Same embedding as the server, bit for bit 1,650 of 1,650 1,440 of 1,440
Same abstain and audit as the server 1,650 of 1,650 1,440 of 1,440
Largest probability gap 0 0
Same embedding with the plain kernel (CPUs without dot-product instructions) 100 of 100 100 of 100
Answered alone, same on both 48, all right 0 (no video head switches on)
Accuracy of p >= 0.5 on every held-out frame, server and device 78.5% 52.8%
JPEG to answer, 4 threads, median / p99 20.7 / 61.2 ms 20.3 / 63.6 ms
JPEG to answer, 1 thread, median / p99 56.2 / 205.0 ms 49.0 / 228.8 ms
Heads only, from a vector, median 5.3 µs 5.3 µs
Opening the encoder file / the pack 0.63 s / 25 ms 0.47 s / 1.3 ms
Pack size 4.7 MB (33 heads) 285 KB (2 heads)

Other builds kept the machine’s load average between 6 and 15 during these runs, which shows in the p99 times. The C caller peaked at 320 MB, holding the 153 MB file while opening it. The library is 784 KB (shared, stripped, arm64 macOS).

The device repeats the server’s heads exactly, mistakes included. In the first run on the video set, the helmet head switched on after learning from 28 clips and was then right on only 92 of its 190 alone answers: frames of one clip are near copies, so the switch-on check counted many frames of few scenes. Since the switch-on fix of 26 October, near copies no longer count as new evidence, the helmet head stays shadowing and gives 0 alone answers, and the device still matches the server bit for bit. Android and iOS builds were not run here, and phone cores are slower than this laptop’s.