vision-rs / Getting Started
Your First Detection
The vision_rs::detect module is the entry point for running inference. It
wraps model-specific configuration and forward passes behind a single
ObjectDetector/DetectorConfig pair, so callers don’t need to touch the
model internals for simple inference.
use vision_rs::detect::{DetectorConfig, ObjectDetector, Yolo26DetectorConfig};
use vision_rs::models::yolo::yolo26::Yolo26Variant;
let config = DetectorConfig::Yolo26(Yolo26DetectorConfig::new(
Yolo26Variant::N,
"weights/yolo26n.bin",
vec!["car".into(), "truck".into(), "person".into()],
));
let detector = ObjectDetector::new(config)?;
let image_bytes = std::fs::read("frame.jpg")?;
let detections = detector.detect(&image_bytes).await?;
for d in &detections {
println!("{} {:.2} {:?}", d.class, d.confidence, d.bbox);
}
Walking through it
- Pick a variant.
Yolo26Varianthas five sizes —N(nano) throughXL— trading accuracy for speed/memory. See The YOLO26 Model for how they differ. - Build a config.
Yolo26DetectorConfig::newtakes the variant, a weights file path, and the class label list (must match the model’s training classes, in class-index order). It fills in sensible defaults:conf_threshold: 0.25,nms_iou_threshold: 0.45,img_size: 640. Adjust these fields directly on the returned config if your use case needs different thresholds. - Construct the detector.
ObjectDetector::newtakes ownership of the config and loads the model. - Run inference.
detect()takes raw JPEG or PNG bytes and returns everyDetectionthat clearsconf_threshold, after non-maximum suppression. EachDetectionhas abbox: [cx, cy, w, h](normalised to[0, 1]), a resolvedclasslabel, and aconfidencescore.
Getting a model
The yolo26 example binary (examples/yolo26.rs) has a download
subcommand for fetching pretrained weights and a dataset config, and a
bench subcommand for a throughput/latency smoke test:
source .env
cargo build --release --example yolo26 --features cuda
./target/release/examples/yolo26 download --dataset assets/datasets/coco128.toml
./target/release/examples/yolo26 bench \
--model ultralytics/yolo26n \
--dataset assets/datasets/coco128.toml \
--skip-map --warmup 10 --runs 100
See Benchmarking & Profiling
for the full set of yolo26 subcommands and profiling workflows.