File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 1515 LoadImage ,
1616 Logger ,
1717 ModelType ,
18+ EngineType ,
1819 RapidTableInput ,
1920 RapidTableOutput ,
2021 get_boxes_recs ,
@@ -45,7 +46,21 @@ def __init__(self, cfg: Optional[RapidTableInput] = None):
4546
4647 def _init_ocr_engine (self ):
4748 try :
48- return import_package ("rapidocr" ).RapidOCR ()
49+ rapidocr_ = import_package ("rapidocr" )
50+ if rapidocr_ is None :
51+ raise ModuleNotFoundError ("rapidocr package is not installed" )
52+ if self .cfg .engine_type == EngineType .TORCH :
53+ EngineType_RapidOCR = rapidocr_ .EngineType
54+ return rapidocr_ .RapidOCR (
55+ params = {
56+ "Det.engine_type" : EngineType_RapidOCR .TORCH ,
57+ "Cls.engine_type" : EngineType_RapidOCR .TORCH ,
58+ "Rec.engine_type" : EngineType_RapidOCR .TORCH ,
59+ "EngineConfig.torch.use_cuda" : True , # Use torch GPU to infer
60+ "EngineConfig.torch.gpu_id" : 0 # Specify GPU id
61+ }
62+ )
63+ return rapidocr_ .RapidOCR ()
4964 except ModuleNotFoundError :
5065 logger .warning ("rapidocr package is not installed, only table rec" )
5166 return None
You can’t perform that action at this time.
0 commit comments