Files
usls/examples/yoloe/main.rs
2025-06-05 16:29:29 +08:00

60 lines
1.6 KiB
Rust

use anyhow::Result;
use usls::{models::YOLO, Annotator, Config, DataLoader, Style};
#[derive(argh::FromArgs)]
/// Example
struct Args {
/// dtype
#[argh(option, default = "String::from(\"fp16\")")]
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();
// config
let config = Config::yoloe_v8s_seg_pf()
// yoloe_v8m_seg_pf()
// yoloe_v8l_seg_pf()
// yoloe_11s_seg_pf()
// yoloe_11m_seg_pf()
// yoloe_11l_seg_pf()
.with_model_dtype(args.dtype.as_str().parse()?)
.with_model_device(args.device.as_str().parse()?)
.commit()?;
let mut model = YOLO::new(config)?;
// load
let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?;
// run
let ys = model.forward(&xs)?;
println!("{:?}", ys);
// annotate
let annotator = Annotator::default()
.with_hbb_style(Style::hbb().with_draw_fill(true))
.with_mask_style(Style::mask().with_draw_mask_polygon_largest(true));
for (x, y) in xs.iter().zip(ys.iter()) {
annotator.annotate(x, y)?.save(format!(
"{}.jpg",
usls::Dir::Current
.base_dir_with_subs(&["runs", model.spec()])?
.join(usls::timestamp(None))
.display(),
))?;
}
Ok(())
}