Integration Workflow¶
usls implements a clean, modular pipeline from data ingestion to results visualization.
The 4-Step Pipeline¶
- Configure Model: Select a pre-configured model (e.g.,
Config::rfdetr_nano()), customize settings, and commit the configuration. - Load Data: Setup a
DataLoaderto handle your input sources (images, videos, etc.). - Inference: Iterate through the
DataLoaderand pass data tomodel.run()ormodel.forward(). - Extract Results: Access detections, masks, or embeddings from the unified
Youtput. - Annotate (Optional): Use the
Annotatorto draw results back onto the original images. - Visualize (Optional): Use the
Viewerfor real-time display or video recording.
Example
use usls::*;
fn main() -> anyhow::Result<()> {
// 1. Configure & Build Model
let config = Config::rfdetr_nano()
.with_model_device(Device::Cuda(0))
.commit()?;
let mut model = RFDETR::new(config)?;
// 2. Setup DataLoader
let dl = DataLoader::new("image.jpg")?
.with_batch(model.batch())
.stream()?;
// optional: Annotate
let annotator = Annotator::default();
// optional: Viewer
let mut viewer = Viewer::default();
// 3. Run Inference
for xs in dl {
let ys = model.run(&xs)?;
for (x, y) in xs.iter().zip(ys.iter()) {
// 4. Access results
for hb in y.hbbs() {
println!("{}", hb);
}
// optional: Check if the window is closed and exit if so.
if viewer.is_window_exist_and_closed() {
break;
}
// optional: Annotate
let image_annotated = annotator.annotate(x, y)?;
// optional: Display the current image.
viewer.imshow(&image_annotated)?;
// optional: Wait for a key press or timeout, and exit on Escape.
if let Some(key) = viewer.wait_key(10) {
if key == usls::Key::Escape {
break;
}
}
// optional: Save the annotated image.
image_annotated.save("output.jpg")?;
}
}
Ok(())
}
Next Steps¶
-
Guides
Learn more about modules, config, and advanced usage
-
Model Zoo
Explore 50+ pre-trained models
-
FAQ
Find answers to common questions