Corral

Corral turns the raw footage, photos and text a company already has into reviewed, versioned training datasets.

folder of video / images / JSONL
  -> ingest    FFmpeg picks frames on scene change and motion; provenance per item
  -> mine      drop near-duplicates (perceptual hash, optional embeddings); rank by usefulness
  -> pre-label YOLO, Claude (headless CLI), or your own model; every label keeps source + confidence
  -> review    one item at a time, lowest confidence and most disagreement first; phone or keyboard
  -> export    YOLO / COCO / JSONL / VOC, immutable versions, splits by source, a dataset card

It is a Python package (FastAPI + SQLite, no external services) with a corral CLI and a review UI that runs in any browser, including a phone on the same network. MIT licensed.

Quickstart

Needs Python 3.11+, uv and FFmpeg (for video).

git clone <this repo> corral && cd corral
uv venv && uv pip install -e ".[dev]"          # add ,yolo for the YOLO labeler and embedding dedup
source .venv/bin/activate

corral schema-template > schema.toml           # edit the classes and fields
corral init cattle --schema schema.toml        # creates ./.corral/ and a project
corral ingest ~/footage -p cattle              # video, images and .jsonl, recursively
corral prelabel -p cattle -l yolo --weights yolo11n.pt --class-map cow=cow,person=person
corral prelabel -p cattle -l claude --limit 40 # optional: uses your logged-in Claude Code CLI
corral serve                                   # review at http://127.0.0.1:4610
corral export -p cattle --format yolo          # writes .corral/exports/cattle/v001-yolo/

corral serve --host 0.0.0.0 lets a phone on the same Wi-Fi review. There is no login; put it behind something you trust (Tailscale, Cloudflare Access) before exposing it further.

What each step does

Schemas. A project's TOML schema lists its tasks: boxes (bounding boxes with classes), classify (one class), tags (any subset) and field (enum, bool, int, float or text). A field can be scope = "subject", meaning the answer belongs to the animal or person in the item rather than the frame: a rancher's "was she actually sick?" recorded once applies to every clip of that cow (corral outcome --subject red --set confirmed_sick=yes). An int field can declare counts = "animals", so a VLM's head count and a detector's boxes are compared. See [examples/cattle.toml](examples/cattle.toml).

Ingest. corral ingest <folder> handles images, video and JSONL. Video is decoded by FFmpeg at a low candidate rate; a frame is kept on a scene change (FFmpeg's scene score), on motion (fraction of changed pixels) with a minimum gap, or as a heartbeat every N seconds when nothing moves. Each item records its source file and SHA-256, capture time and how it was known (EXIF, file name, container, mtime), and for video the offset and source frame index. --watch polls a folder and ingests files once their size stops changing. --group-by dir or a regex groups images for splitting; every frame of a clip is always one group.

Mine. Near-duplicates are dropped by 64-bit perceptual hash (and, with --embed, by cosine similarity of YOLO backbone embeddings). Reviewed items are never dropped. Every remaining item gets a priority from five parts, kept with the item so the UI can show why it is next: model uncertainty (0.40), disagreement between models (0.30), motion (0.10), night or IR (0.10) and rare predicted classes (0.10). Blurry frames are discounted.

Pre-label. Labelers are pluggable:

labelerusenotes
yoloboxesoptional [yolo] extra; --class-map maps model classes to yours
claudeclasses, tags, counts, fields, textruns claude -p ... --output-format json --json-schema ... per item; default model claude-haiku-5-5, or --model claude-sonnet-5-5; no API key needed if the CLI is logged in
file.py:Classyour modelsubclass corral.labelers.DetectorPlugin, implement detect(path) -> [PixelBox]; see [examples/vitals_detector.py](examples/vitals_detector.py)

Every label stores its source (model, weights hash, version) and a confidence. The Claude labeler skips box tasks and only asks subject-level questions of text items.

Review. One item at a time. Accept (A, swipe right), reject (R, swipe left: drops the item), fix (F: draw and adjust boxes, change answers, Enter to save). 1-9 pick a class for the active task, Tab moves between tasks, [/] cycle boxes, Delete removes one, Z or ← undoes the last review, → skips. The queue is the active-learning order above. With consensus = 2 each item needs two different reviewers; if their answers differ (boxes are matched one-to-one at IoU 0.5) the item goes to the Resolve view. The Stats view shows per-reviewer counts, accept/fix/reject rates, median seconds per item and agreement.

Export. corral export --format yolo|coco|jsonl|voc writes a numbered, read-only version with manifest.json (every file's SHA-256, every item's split, source and label provenance) and DATASET_CARD.md (counts per class and split, the share of labels a person wrote versus accepted from a model, sources, and known gaps). corral verify <dir> re-hashes it. If nothing changed, no version is written.

Splits are by source group, never by item: frames from one clip are near-copies of each other, and a random split puts a frame's twin in the test set. A group keeps its split in every later version, so a clip that was once in test never moves into train. Exported file names start with the split (test__clip__000123.jpg), so trainers that hold out by file name pattern work too.

Docs

Development

uv pip install -e ".[dev,yolo]"
pytest                       # 64 tests; set CORRAL_TEST_CLAUDE=1 to also call the real CLI
./scripts/demo.sh            # the end-to-end demo (needs demo-data/, see docs/demo.md)

The landing page lives in site/ (static HTML/CSS, no build).