11use anyhow:: Result ;
2- use usls:: { models:: RTDETR , Annotator , Config , DataLoader } ;
2+ use usls:: { models:: RTDETR , Annotator , Config , DataLoader , Scale , Version } ;
3+
4+ #[ derive( argh:: FromArgs ) ]
5+ /// Example
6+ struct Args {
7+ /// device
8+ #[ argh( option, default = "String::from(\" cpu\" )" ) ]
9+ device : String ,
10+
11+ /// scale
12+ #[ argh( option, default = "String::from(\" s\" )" ) ]
13+ scale : String ,
14+
15+ /// dtype
16+ #[ argh( option, default = "String::from(\" q4f16\" )" ) ]
17+ dtype : String ,
18+
19+ /// model
20+ #[ argh( option) ]
21+ model : Option < String > ,
22+
23+ /// version
24+ #[ argh( option, default = "1.0" ) ]
25+ ver : f32 ,
26+
27+ /// confidences
28+ #[ argh( option) ]
29+ confs : Vec < f32 > ,
30+ }
331
432fn main ( ) -> Result < ( ) > {
533 tracing_subscriber:: fmt ( )
634 . with_env_filter ( tracing_subscriber:: EnvFilter :: from_default_env ( ) )
735 . with_timer ( tracing_subscriber:: fmt:: time:: ChronoLocal :: rfc_3339 ( ) )
836 . init ( ) ;
37+ let args: Args = argh:: from_env ( ) ;
938
1039 // config
11- let config = Config :: rtdetr_v2_s_coco ( ) . commit ( ) ?;
12- // rtdetr_v1_r18vd_coco()
13- // rtdetr_v2_ms_coco()
14- // rtdetr_v2_m_coco()
15- // rtdetr_v2_l_coco()
16- // rtdetr_v2_x_coco()
40+ let config = match args. model {
41+ Some ( model) => Config :: rtdetr ( ) . with_model_file ( & model) ,
42+ None => {
43+ match args. ver . try_into ( ) ? {
44+ Version ( 1 , 0 , _) => match args. scale . parse ( ) ? {
45+ Scale :: Named ( ref name) if name == "r18" => Config :: rtdetr_v1_r18 ( ) ,
46+ Scale :: Named ( ref name) if name == "r18-obj365" => Config :: rtdetr_v1_r18_obj365 ( ) ,
47+ Scale :: Named ( ref name) if name == "r34" => Config :: rtdetr_v1_r34 ( ) ,
48+ Scale :: Named ( ref name) if name == "r50" => Config :: rtdetr_v1_r50 ( ) ,
49+ Scale :: Named ( ref name) if name == "r50-obj365" => Config :: rtdetr_v1_r50_obj365 ( ) ,
50+ Scale :: Named ( ref name) if name == "r101" => Config :: rtdetr_v1_r101 ( ) ,
51+ Scale :: Named ( ref name) if name == "r101-obj365" => Config :: rtdetr_v1_r101_obj365 ( ) ,
52+ _ => unimplemented ! (
53+ "Unsupported model scale: {:?} for RT-DETRv1. Try r18, r18-obj365, r34, r50, r50-obj365, r101, r101-obj365." ,
54+ args. scale,
55+ ) ,
56+ } ,
57+ Version ( 2 , 0 , _) => match args. scale . parse ( ) ?{
58+ Scale :: S => Config :: rtdetr_v2_s ( ) ,
59+ Scale :: M => Config :: rtdetr_v2_m ( ) ,
60+ Scale :: Named ( ref name) if name == "ms" => Config :: rtdetr_v2_ms ( ) ,
61+ Scale :: L => Config :: rtdetr_v2_l ( ) ,
62+ Scale :: X => Config :: rtdetr_v2_x ( ) ,
63+ _ => unimplemented ! (
64+ "Unsupported model scale: {:?} for RT-DETRv2. Try s, m, ms, l, x." ,
65+ args. scale,
66+ ) ,
67+ } ,
68+ Version ( 4 , 0 , _) => match args. scale . parse ( ) ?{
69+ Scale :: S => Config :: rtdetr_v4_s ( ) ,
70+ Scale :: M => Config :: rtdetr_v4_m ( ) ,
71+ Scale :: L => Config :: rtdetr_v4_l ( ) ,
72+ Scale :: X => Config :: rtdetr_v4_x ( ) ,
73+ _ => unimplemented ! (
74+ "Unsupported model scale: {:?} for RT-DETRv4. Try s, m, l, x." ,
75+ args. scale,
76+ ) ,
77+ } ,
78+ _ => unimplemented ! (
79+ "Unsupported model version: {:?}. Try v1, v2, v4 for RT-DETR." ,
80+ args. ver
81+ ) ,
82+ }
83+ }
84+ }
85+ . with_dtype_all ( args. dtype . parse ( ) ?)
86+ . with_device_all ( args. device . parse ( ) ?)
87+ . with_class_confs ( if args. confs . is_empty ( ) {
88+ & [ 0.35 ]
89+ } else {
90+ & args. confs
91+ } )
92+ . commit ( ) ?;
1793 let mut model = RTDETR :: new ( config) ?;
1894
1995 // load
@@ -34,6 +110,8 @@ fn main() -> Result<()> {
34110 . display( ) ,
35111 ) ) ?;
36112 }
113+
114+ // summary
37115 usls:: perf ( false ) ;
38116
39117 Ok ( ( ) )
0 commit comments