11use aksr:: Builder ;
22use anyhow:: Result ;
33
4- use crate :: { elapsed_module, Config , Engine , Image , Processor , Scale , Xs , X } ;
4+ use crate :: { elapsed_module, Config , Engine , Image , Processor , Xs , X } ;
55
66#[ derive( Builder , Debug ) ]
77pub struct DINOv2 {
88 engine : Engine ,
99 height : usize ,
1010 width : usize ,
1111 batch : usize ,
12- dim : usize ,
1312 processor : Processor ,
1413}
1514
@@ -21,14 +20,6 @@ impl DINOv2 {
2120 engine. try_height ( ) . unwrap_or ( & 384 . into ( ) ) . opt ( ) ,
2221 engine. try_width ( ) . unwrap_or ( & 384 . into ( ) ) . opt ( ) ,
2322 ) ;
24- let dim = match & config. scale {
25- Some ( Scale :: S ) => 384 ,
26- Some ( Scale :: B ) => 768 ,
27- Some ( Scale :: L ) => 1024 ,
28- Some ( Scale :: G ) => 1536 ,
29- Some ( x) => anyhow:: bail!( "Unsupported scale: {:?}" , x) ,
30- None => anyhow:: bail!( "No model scale specified" ) ,
31- } ;
3223 let processor = Processor :: try_from_config ( & config. processor ) ?
3324 . with_image_width ( width as _ )
3425 . with_image_height ( height as _ ) ;
@@ -38,14 +29,12 @@ impl DINOv2 {
3829 height,
3930 width,
4031 batch,
41- dim,
4232 processor,
4333 } )
4434 }
4535
4636 fn preprocess ( & mut self , xs : & [ Image ] ) -> Result < Xs > {
4737 let x = self . processor . process_images ( xs) ?;
48-
4938 Ok ( x. into ( ) )
5039 }
5140
@@ -57,7 +46,6 @@ impl DINOv2 {
5746 let xs = elapsed_module ! ( "DINOv2" , "visual-preprocess" , self . preprocess( xs) ?) ;
5847 let xs = elapsed_module ! ( "DINOv2" , "visual-inference" , self . inference( xs) ?) ;
5948 let x = elapsed_module ! ( "DINOv2" , "visual-postprocess" , xs[ 0 ] . to_owned( ) ) ;
60-
6149 Ok ( x)
6250 }
6351}
0 commit comments