mirror of
https://github.com/mii443/usls.git
synced 2025-08-22 15:45:41 +00:00
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use anyhow::Result;
|
|
use usls::{models::YOLO, Annotator, DataLoader, ModelConfig};
|
|
|
|
#[derive(argh::FromArgs)]
|
|
/// Example
|
|
struct Args {
|
|
/// dtype
|
|
#[argh(option, default = "String::from(\"auto\")")]
|
|
dtype: String,
|
|
|
|
/// device
|
|
#[argh(option, default = "String::from(\"cpu:0\")")]
|
|
device: String,
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
|
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
|
|
.init();
|
|
|
|
let args: Args = argh::from_env();
|
|
|
|
// build model
|
|
let config = ModelConfig::ultralytics_rtdetr_l()
|
|
.with_model_dtype(args.dtype.as_str().try_into()?)
|
|
.with_model_device(args.device.as_str().try_into()?)
|
|
.commit()?;
|
|
let mut model = YOLO::new(config)?;
|
|
|
|
// load images
|
|
let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?;
|
|
|
|
// run
|
|
let ys = model.forward(&xs)?;
|
|
println!("{:?}", ys);
|
|
|
|
// annotate
|
|
let annotator = Annotator::default();
|
|
for (x, y) in xs.iter().zip(ys.iter()) {
|
|
annotator.annotate(x, y)?.save(format!(
|
|
"{}.jpg",
|
|
usls::Dir::Current
|
|
.base_dir_with_subs(&["runs", "ultralytics-RTDETR"])?
|
|
.join(usls::timestamp(None))
|
|
.display(),
|
|
))?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|