Initialize OpenOCR unified interface. Args: task: Task type ('ocr', 'det', 'rec', 'unirec', 'doc', 'launch_openocr_demo', 'launch_unirec_demo', 'launch_opendoc_demo') # Common parameters use_gpu: GPU usage strategy ('auto', 'true', or 'false')
(
self,
task: str = 'ocr',
# Common parameters
use_gpu: str = 'auto',
# OCR task parameters
mode: str = 'mobile',
backend: str = 'onnx',
onnx_det_model_path: Optional[str] = None,
onnx_rec_model_path: Optional[str] = None,
drop_score: float = 0.5,
det_box_type: str = 'quad',
# UniRec task parameters
unirec_encoder_path: Optional[str] = None,
unirec_decoder_path: Optional[str] = None,
tokenizer_mapping_path: Optional[str] = None,
max_length: int = 2048,
# Doc task parameters
layout_model_path: Optional[str] = None,
layout_threshold: float = 0.5,
use_layout_detection: bool = True,
use_chart_recognition: bool = True,
auto_download: bool = True,
max_parallel_blocks: int = 4,
)
| 47 | """ |
| 48 | |
| 49 | def __init__( |
| 50 | self, |
| 51 | task: str = 'ocr', |
| 52 | # Common parameters |
| 53 | use_gpu: str = 'auto', |
| 54 | # OCR task parameters |
| 55 | mode: str = 'mobile', |
| 56 | backend: str = 'onnx', |
| 57 | onnx_det_model_path: Optional[str] = None, |
| 58 | onnx_rec_model_path: Optional[str] = None, |
| 59 | drop_score: float = 0.5, |
| 60 | det_box_type: str = 'quad', |
| 61 | # UniRec task parameters |
| 62 | unirec_encoder_path: Optional[str] = None, |
| 63 | unirec_decoder_path: Optional[str] = None, |
| 64 | tokenizer_mapping_path: Optional[str] = None, |
| 65 | max_length: int = 2048, |
| 66 | # Doc task parameters |
| 67 | layout_model_path: Optional[str] = None, |
| 68 | layout_threshold: float = 0.5, |
| 69 | use_layout_detection: bool = True, |
| 70 | use_chart_recognition: bool = True, |
| 71 | auto_download: bool = True, |
| 72 | max_parallel_blocks: int = 4, |
| 73 | ): |
| 74 | """ |
| 75 | Initialize OpenOCR unified interface. |
| 76 | |
| 77 | Args: |
| 78 | task: Task type ('ocr', 'det', 'rec', 'unirec', 'doc', 'launch_openocr_demo', 'launch_unirec_demo', 'launch_opendoc_demo') |
| 79 | |
| 80 | # Common parameters |
| 81 | use_gpu: GPU usage strategy ('auto', 'true', or 'false') |
| 82 | |
| 83 | # OCR task parameters |
| 84 | mode: Model mode ('mobile' or 'server') |
| 85 | backend: Backend type ('onnx') |
| 86 | onnx_det_model_path: Path to detection ONNX model |
| 87 | onnx_rec_model_path: Path to recognition ONNX model |
| 88 | drop_score: Score threshold for filtering results |
| 89 | det_box_type: Detection box type ('quad' or 'poly') |
| 90 | |
| 91 | # UniRec task parameters |
| 92 | unirec_encoder_path: Path to UniRec encoder ONNX model |
| 93 | unirec_decoder_path: Path to UniRec decoder ONNX model |
| 94 | tokenizer_mapping_path: Path to tokenizer mapping JSON |
| 95 | max_length: Maximum generation length |
| 96 | |
| 97 | # Doc task parameters |
| 98 | layout_model_path: Path to layout detection model |
| 99 | layout_threshold: Layout detection threshold |
| 100 | use_layout_detection: Whether to use layout detection |
| 101 | use_chart_recognition: Whether to recognize charts |
| 102 | auto_download: Whether to auto-download missing models |
| 103 | max_parallel_blocks: Maximum number of blocks to process in parallel for VLM recognition (doc task only, default: 4) |
| 104 | """ |
| 105 | self.task = task.lower() |
| 106 | self.model = None |
nothing calls this directly
no test coverage detected