Run this model with HF Jobs
Run crockrocks/model_training on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/crockrocks/model_training. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/crockrocks/model_training on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use crockrocks/model_training with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use crockrocks/model_training with ultralytics:
from huggingface_hub import hf_hub_download from ultralytics import YOLO # pick the weights file from this repo's "Files and versions" tab weights = hf_hub_download("crockrocks/model_training", "<weights>.pt") model = YOLO(weights) source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
model_training: custom small-object detectors for RTSP cameras
This repository holds a training system plus released runs for real-time detectors of custom objects (jerry cans, metal clamps, gas cylinders, ...) on IP-camera streams.
- Each release trains and compares RF-DETR (Apache-2.0) and Ultralytics YOLO26 (AGPL-3.0).
- Models are exported to ONNX for
pai-vision/detect-pipeline.
The current weights are a demo trained on an Open Images V7 stand-in: 5 everyday classes, about 50 images per class, degraded to RTSP quality. They are not site models. They exist to show the pipeline working end to end; the full write-up is in docs/DEMO_OPENIMAGES.md.
Released files
| file | model | input | license | test mAP50-95 (held-out cameras) |
|---|---|---|---|---|
runs/rfdetr/demo_rfdetr_small/checkpoint_best_total.pth |
RF-DETR-S fine-tune | 512 | Apache-2.0 | 0.705 |
exports/demo_rfdetr_small.onnx (+ .labels.json) |
same, ONNX | 512 | Apache-2.0 | 0.719 (detect-pipeline full-frame tiles) |
runs/yolo/demo_yolo26s_freeze10/weights/best.pt |
YOLO26s, backbone frozen | 960 | AGPL-3.0 | 0.533 |
exports/demo_yolo26s_freeze10_in640.onnx (+ .labels.json) |
same, ONNX, use this one for 720p cameras | 640 | AGPL-3.0 | 0.487 (detect-pipeline full-frame tiles) |
exports/demo_yolo26s_freeze10.onnx (+ .labels.json) |
same, ONNX at training size | 960 | AGPL-3.0 | 0.410 (tiles); kept for comparison |
runs/yolo/demo_yolo26s_freeze0/weights/best.pt |
YOLO26s, full fine-tune | 960 | AGPL-3.0 | 0.419 |
- Classes, in id order:
bottle, mobile_phone, handbag, tin_can, box. - Run folders contain metrics, curves, confusion matrices and training configs.
runs/eval/20261127_100211/holds the final comparison table andruns/eval/20261127_095759/the YOLO input-size sweep. - Training-resume state is not included: Lightning
.ckptfiles and duplicate EMA weights.
Use
from huggingface_hub import snapshot_download
repo = snapshot_download("crockrocks/model_training") # code + docs + runs + exports
# RF-DETR (pip install "rfdetr==1.12.1")
from rfdetr import RFDETRSmall
model = RFDETRSmall(pretrain_weights=f"{repo}/runs/rfdetr/demo_rfdetr_small/checkpoint_best_total.pth")
detections = model.predict("frame.jpg", threshold=0.4) # supervision.Detections, class ids 0..4
# YOLO26 (pip install "ultralytics==8.4.164")
from ultralytics import YOLO
results = YOLO(f"{repo}/runs/yolo/demo_yolo26s_freeze10/weights/best.pt").predict("frame.jpg", imgsz=960, conf=0.4)
- Live camera:
python scripts/infer_stream.py <weights> --source rtsp://...runs with tracking. - Your own data: see docs/RTSP_WORKFLOW.md for the step-by-step process from RTSP cameras to a deployed model.
Intended use and limitations
- Purpose: these weights demonstrate the pipeline. Use them as a starting point or reference, not as a detector for production sites.
- Training data: consumer photos (Open Images V7, CC BY 2.0) with simulated camera degradation. That data doesn't label every instance (some bottles and boxes are unlabeled), and the photos aren't elevated CCTV viewpoints.
- Test set: 66 images and 124 boxes from 2 held-out pseudo-cameras, so differences of a few points are noise.
Licenses
Mixed; see docs/LICENSES.md:
- YOLO26-derived weights are AGPL-3.0;
- RF-DETR-derived weights are Apache-2.0;
- the demo images in
docs/demo_img/and the run plots are CC BY 2.0, credited indocs/demo_img/ATTRIBUTION.csv.
model_training: custom small-object detector
This trains a real-time detector for our own object classes: jerry cans, metal clamps, gas cylinders, and whatever else goes in configs/classes.yaml. It trains two model families on the same data, compares them on held-out scenes, and exports the better one as ONNX for pai-vision/detect-pipeline.
Step-by-step guide for your own RTSP cameras: docs/RTSP_WORKFLOW.md.
Research behind the choices: reports/Custom small object detector training.md. Worked example with real numbers (an Open Images stand-in until we have site access, 5 classes, about 50 images per class, RTSP-quality): docs/DEMO_OPENIMAGES.md. On held-out cameras, RF-DETR-S scored 0.705 mAP50-95 and YOLO26s 0.533.
| YOLO26s (Ultralytics) | RF-DETR-S/M (Roboflow) | |
|---|---|---|
| Transfer to new datasets (RF100-VL AP50:95) | 57.0 | 60.2 / 61.2 |
| T4 TensorRT FP16 latency | 2.6 ms | 3.5 / 4.4 ms |
| Params | 9.4 M | 32 / 34 M |
| License | AGPL-3.0 (or paid) | Apache-2.0 (N/S/M/L only) |
Approach: fine-tune the whole COCO-pretrained network and replace only the class head. Don't use a backbone-only checkpoint or train from scratch. Below roughly 3β10k images, pretrained weights win by a wide margin. Freezing is something to test (--freeze-sweep 0 10), not the default.
Setup
# .venv was copied from maruti_poc/.venv (ROCm torch for the RX 9060 XT) + requirements.txt
.venv/Scripts/activate # Windows: .venv\Scripts\activate
# fresh machine: install torch for your GPU first, then
pip install -r requirements.txt
Workflow
capture -> extract_frames -> autolabel (draft) -> review in CVAT -> prepare_dataset
-> train_yolo + train_rfdetr -> evaluate (pick) -> export (+verify) -> detect-pipeline
-> infer_stream --harvest (hard frames) -> review -> retrain (repeat)
| Step | Command |
|---|---|
| 1. Capture | follow docs/CAPTURE_GUIDE.md: 150β300 boxes per class, at least 5 scenes, hard negatives |
| 2. Frames | python scripts/extract_frames.py recordings/*.mp4 --every 3 β data/raw/<group>/ (one group per video/camera/session) |
| 3. Draft labels | python scripts/autolabel.py data/raw --preview (Grounding DINO, one query per class; tune prompts in classes.yaml). Check prompt quality on a reviewed group with scripts/score_labels.py. |
| 4. Review | Import data/raw/<group>/cvat_import.zip into CVAT, fix every image, and export to data/raw/<group>/labels/. An empty .txt marks a background image. |
| 5. Dataset | python scripts/prepare_dataset.py --name v1 β datasets/v1/ (split by group, so val/test are unseen scenes) |
| 6a. YOLO | python scripts/train_yolo.py --data datasets/v1/data.yaml (add --freeze-sweep 0 10, --model yolo26m.pt or --imgsz 1280 to compare) |
| 6b. RF-DETR | python scripts/train_rfdetr.py --data datasets/v1 (--variant medium to compare) |
| 7. Compare | python scripts/evaluate.py --data datasets/v1 --models runs/yolo/<run>/weights/best.pt runs/rfdetr/<run>/checkpoint_best_total.pth |
| 8. Export | python scripts/export.py <weights> --verify datasets/v1/images/test β exports/<name>.onnx + <name>.labels.json |
| 9. Live test | python scripts/infer_stream.py <weights> --source rtsp://... (or 0 for webcam) |
| 10. Improve | python scripts/infer_stream.py <weights> --source rtsp://... --no-show --harvest data/raw/harvest_cam1, then review and go back to step 5 with --name v2 |
Stand-in data tools (until site access): scripts/fetch_openimages.py pulls a balanced, labeled Open Images subset for any classes listed in a yaml like configs/demo_openimages.yaml. scripts/simulate_rtsp.py degrades labeled photos to camera quality (16:9 frame, sensor noise, low-bitrate H.264) with the labels kept aligned. autolabel.py and prepare_dataset.py take --classes <yaml>.
evaluate.py and infer_stream.py also accept an exported .onnx. It then runs the way detect-pipeline does with DETECT_FULL_FRAME=true: the pipeline's square tiles, its preprocessing and decoders, and its seam merge. The score is therefore the deployed full-frame accuracy. When this repo isn't cloned next to pai-vision/, point DETECT_PIPELINE_DIR at your detect-pipeline checkout.
Hyperparameters live in configs/yolo26.yaml and configs/rfdetr.yaml. Any key can be overridden with --set key=value.
Choosing the model
- Look at
evaluate.py's test table (unseen scenes): mAP50-95, the per-class AP50 for the weakest class (probably clamps), and latency. - The latency there is PyTorch eager on this machine. Measure ONNX or TensorRT on the deploy box before deciding.
- If RF-DETR and YOLO are within about 2 AP, the license and edge hardware usually decide:
- RF-DETR is Apache-2.0.
- YOLO26 is AGPL-3.0, but much lighter on N100, Jetson or Hailo.
Small objects
prepare_dataset.pyreports how many boxes are under 16 px at the training size.- If many are, raise
--imgszto 1280 for YOLO or--resolutionfor RF-DETR, which must be divisible by the patch size. Inference must use the same size. - SAHI-style tiling is only practical offline or on a fixed region of interest, not on full live streams.
Layout
configs/ classes.yaml (label space + prompts), yolo26.yaml, rfdetr.yaml
scripts/ common.py (Predictor, LatestFrameReader, label IO) + one script per step above
docs/ RTSP_WORKFLOW.md, CAPTURE_GUIDE.md, DEMO_OPENIMAGES.md (+ demo_img/, CC BY 2.0), MODEL_CARD.md, LICENSES.md
data/raw/<group>/ frames + labels/ (gitignored)
datasets/<name>/ built splits + data.yaml + stats.json (gitignored)
runs/{yolo,rfdetr,eval}/ training runs and comparison tables (gitignored)
exports/ ONNX + labels.json (gitignored)
reports/, research_notes/ model/procedure research
Deployment into detect-pipeline: known gaps (not yet changed there)
The smoke test found the following in pai-vision/detect-pipeline:
OnnxDetrDetectorreturns no detections for a 3-class RF-DETR model.- It tells
detsandlabelsapart byshape[-1] == 4. With 3 classes the head has 3+1 = 4 logit slots, so both outputs match. - Confirmed: 0 boxes, where
export.py --verifyreproduces 15/15. - Fix: select outputs by name (
dets/labels).
- It tells
- No custom class names in the service.
run.pybuilds both detectors withoutlabels=, so a custom YOLO model's class 0 would be published as COCO "person".OnnxDetrDetectorhas nolabelsparameter at all.- Needed: a setting such as
DETECT_ONNX_LABELS=<name>.labels.json, passed to both detectors.
- Input size has to match the export.
DETECT_ONNX_INPUTdefaults to 640, andresolve_input_sizefalls back to 640β320 if the configured size doesn't fit the static ONNX. Set it to the size in<name>.labels.json. - YOLO input size changes accuracy; RF-DETR's doesn't.
- The pipeline only feeds square crops: motion regions, or overlapping short-edge tiles with
DETECT_FULL_FRAME=true. Aspect ratio is therefore fine. - Object scale still matters. On the demo's 720p test cameras in tile mode, YOLO26s trained at 960 scores 0.410 mAP50-95 when exported at 960 and 0.487 at 640 (0.533 on whole frames in PyTorch).
- RF-DETR-S scores 0.719 in tile mode, no loss.
- So export YOLO at about 640 for 720p cameras, or train at the size the pipeline will feed.
- The pipeline only feeds square crops: motion regions, or overlapping short-edge tiles with
- Static objects need
DETECT_FULL_FRAME=true. By default the detector only runs on regions with motion or live tracks, so a cylinder or jerry can that is already sitting in view may never be scanned.
TensorRT: build the engine on the deploy GPU from the exported ONNX (trtexec --onnx=... --fp16, or ORT's TensorRT provider). Use INT8 only after checking per-class mAP, with at least 500 calibration frames from the real cameras.
Smoke-tested on this machine (2026-11-26)
The full chain ran on synthetic shapes pasted onto PPE photos, on the RX 9060 XT with ROCm 7.14 and Python 3.14:
- extract (with dedupe), autolabel (Grounding DINO tiny, CVAT zip), prepare (split by group);
- YOLO26s training (also
freeze=10) and RF-DETR-S training; - evaluate, export (both ONNX outputs match PyTorch at 100% through detect-pipeline's decoders), and infer_stream with ByteTrack and harvesting.
Notes for this AMD box:
- RF-DETR's matcher falls back to SciPy on the CPU, and the DINOv2 attention uses the "experimental" ROCm kernels, so RF-DETR training is slower per image than on NVIDIA.
TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1turns on the faster attention path; it is untested here.
- Downloads last month
- -