1010class TextDetector (InferBase ):
1111 def __init__ (self , args ):
1212 super (TextDetector , self ).__init__ (args )
13- self ._hw_list = []
1413
15- def init (self , warmup = False ):
14+ def _init_preprocess (self ):
15+ self .preprocess_ops = build_preprocess (self .args .det_config_path )
16+
17+ def _init_model (self ):
1618 self .model = Model (
1719 backend = self .args .backend ,
1820 model_path = self .args .det_model_path ,
@@ -34,11 +36,13 @@ def init(self, warmup=False):
3436 raise ValueError ("Input batch size must be 1 for detection model." )
3537
3638 self ._hw_list = hw_list
37- self .preprocess_ops = build_preprocess (self .args .det_config_path )
39+ self ._bs_list = [batchsize ]
40+
41+ def _init_postprocess (self ):
3842 self .postprocess_ops = build_postprocess (self .args .det_config_path , rescale_fields = ["polys" ])
3943
40- if warmup :
41- self .model . warmup ()
44+ def get_params ( self ) :
45+ return { "det_batch_num" : self ._bs_list }
4246
4347 def __call__ (self , image : np .ndarray ):
4448 data = self .preprocess (image )
@@ -54,9 +58,7 @@ def preprocess(self, image: np.ndarray) -> Dict:
5458 def model_infer (self , data : Dict ) -> List [np .ndarray ]:
5559 return self .model .infer ([data ["image" ]]) # model infer for single input
5660
57- def postprocess (self , pred , shape_list : np .ndarray ) -> np .ndarray :
61+ def postprocess (self , pred , shape_list : np .ndarray ) -> List [ np .ndarray ] :
5862 polys = self .postprocess_ops (tuple (pred ), shape_list )["polys" ][0 ] # {'polys': [img0_polys, ...], ...}
59- polys = np .array (polys )
60- # polys.shape may be (0,), (polys_num, points_num, 2), (1, polys_num, points_num, 2)
61- polys_shape = (- 1 , * polys .shape [- 2 :]) if polys .size != 0 else (0 , 0 , 2 )
62- return polys .reshape (* polys_shape ) # (polys_num, points_num, 2), because bs=1
63+ polys = [np .array (x ) for x in polys ]
64+ return polys # [poly(points_num, 2), ...], bs=1
0 commit comments