|
1 | 1 | use anyhow::Result; |
2 | | -use usls::{models::RFDETR, Annotator, Config, DataLoader}; |
| 2 | +use usls::{models::RFDETR, Annotator, Config, DataLoader, Scale, Task}; |
| 3 | + |
| 4 | +#[derive(argh::FromArgs)] |
| 5 | +/// Example |
| 6 | +struct Args { |
| 7 | + /// device |
| 8 | + #[argh(option, default = "String::from(\"cpu\")")] |
| 9 | + device: String, |
| 10 | + |
| 11 | + /// task |
| 12 | + #[argh(option, default = "String::from(\"det\")")] |
| 13 | + task: String, |
| 14 | + |
| 15 | + /// scale |
| 16 | + #[argh(option, default = "String::from(\"n\")")] |
| 17 | + scale: String, |
| 18 | + |
| 19 | + /// dtype |
| 20 | + #[argh(option, default = "String::from(\"auto\")")] |
| 21 | + dtype: String, |
| 22 | +} |
3 | 23 |
|
4 | 24 | fn main() -> Result<()> { |
5 | 25 | tracing_subscriber::fmt() |
6 | 26 | .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) |
7 | 27 | .with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339()) |
8 | 28 | .init(); |
| 29 | + let args: Args = argh::from_env(); |
9 | 30 |
|
10 | 31 | // config |
11 | | - let mut model = RFDETR::new(Config::rfdetr_base().commit()?)?; |
| 32 | + let config = match args.task.parse()? { |
| 33 | + Task::ObjectDetection => match args.scale.parse()? { |
| 34 | + Scale::N => Config::rfdetr_nano(), |
| 35 | + Scale::S => Config::rfdetr_small(), |
| 36 | + Scale::M => Config::rfdetr_medium(), |
| 37 | + Scale::B => Config::rfdetr_base(), |
| 38 | + Scale::L => Config::rfdetr_large(), |
| 39 | + _ => unimplemented!("Unsupported model scale: {:?}. Try b, s, t.", args.scale), |
| 40 | + }, |
| 41 | + Task::InstanceSegmentation => Config::rfdetr_seg_preview(), |
| 42 | + _ => unimplemented!("Unsupported task: {:?}. Try det, seg.", args.task), |
| 43 | + } |
| 44 | + .with_dtype_all(args.dtype.parse()?) |
| 45 | + .with_device_all(args.device.parse()?) |
| 46 | + .commit()?; |
| 47 | + let mut model = RFDETR::new(config)?; |
12 | 48 |
|
13 | 49 | // load |
14 | 50 | let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?; |
|
0 commit comments