|
1 | 1 | use anyhow::Result; |
2 | | -use usls::{models::RTMO, Annotator, DataLoader, Options, Style, SKELETON_COCO_19}; |
| 2 | +use usls::{models::RTMO, Annotator, DataLoader, Config, Style, SKELETON_COCO_19}; |
| 3 | +#[derive(argh::FromArgs)] |
| 4 | +/// Example |
| 5 | +struct Args { |
| 6 | + /// model file |
| 7 | + #[argh(option)] |
| 8 | + model: Option<String>, |
3 | 9 |
|
| 10 | + /// source |
| 11 | + #[argh(option, default = "String::from(\"./assets/bus.jpg\")")] |
| 12 | + source: String, |
| 13 | + /// dtype |
| 14 | + #[argh(option, default = "String::from(\"fp16\")")] |
| 15 | + dtype: String, |
| 16 | + |
| 17 | + /// device |
| 18 | + #[argh(option, default = "String::from(\"cpu:0\")")] |
| 19 | + device: String, |
| 20 | + |
| 21 | + /// scale: t, s, m, l |
| 22 | + #[argh(option, default = "String::from(\"t\")")] |
| 23 | + scale: String, |
| 24 | +} |
4 | 25 | fn main() -> Result<()> { |
5 | 26 | tracing_subscriber::fmt() |
6 | 27 | .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) |
7 | 28 | .with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339()) |
8 | 29 | .init(); |
9 | | - |
| 30 | + let args: Args = argh::from_env(); |
| 31 | + // build model |
| 32 | + let config = match args.scale.as_str() { |
| 33 | + "t" => Config::rtmo_t(), |
| 34 | + "s" => Config::rtmo_s(), |
| 35 | + "m" => Config::rtmo_m(), |
| 36 | + "l" => Config::rtmo_l(), |
| 37 | + _ => unreachable!(), |
| 38 | + } |
| 39 | + .with_model_file(&args.model.unwrap_or_default()) |
| 40 | + .with_model_dtype(args.dtype.parse()?) |
| 41 | + .with_model_device(args.device.parse()?) |
| 42 | + .commit()?; |
10 | 43 | // build model |
11 | | - let mut model = RTMO::new(Options::rtmo_s().commit()?)?; |
| 44 | + let mut model = RTMO::new(config)?; |
12 | 45 |
|
13 | 46 | // load image |
14 | | - let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?; |
| 47 | + |
| 48 | + let xs = DataLoader::try_read_n(&[&args.source])?; |
15 | 49 |
|
16 | 50 | // run |
17 | 51 | let ys = model.forward(&xs)?; |
|
0 commit comments