This commit is contained in:
zimoyin
2026-10-12 11:03:59 +08:00
parent 5ddda545f5
commit cebe783839
7 changed files with 53 additions and 2 deletions
+1
View File
@@ -28,6 +28,7 @@ def create_app(settings: Settings | None = None) -> FastAPI:
text_det_unclip_ratio=settings.text_det_unclip_ratio,
text_rec_score_thresh=settings.text_rec_score_thresh,
text_recognition_batch_size=settings.text_recognition_batch_size,
cpu_threads=settings.cpu_threads,
)
tasks = OCRTaskQueue(create_ocr, worker_count=settings.ocr_workers)
+1
View File
@@ -37,6 +37,7 @@ class Settings(BaseModel):
text_det_unclip_ratio: float = Field(default=1.5, ge=0.1, le=5.0)
text_rec_score_thresh: float = Field(default=0.0, ge=0.0, le=1.0)
text_recognition_batch_size: int = Field(default=1, ge=1, le=64)
cpu_threads: int = Field(default=10, ge=1, le=64)
log_level: str = "INFO"
def __init__(self, **overrides: Any) -> None:
+5 -1
View File
@@ -41,6 +41,7 @@ class OCRService:
text_det_unclip_ratio: float = 1.5,
text_rec_score_thresh: float = 0.0,
text_recognition_batch_size: int = 1,
cpu_threads: int = 10,
) -> None:
self.lang = lang
self.device = device
@@ -54,6 +55,7 @@ class OCRService:
self._text_det_unclip_ratio = text_det_unclip_ratio
self._text_rec_score_thresh = text_rec_score_thresh
self._text_recognition_batch_size = text_recognition_batch_size
self._cpu_threads = cpu_threads
self._engine: Any | None = None
self._lock = threading.Lock()
self._inference_lock = threading.Lock()
@@ -130,10 +132,11 @@ class OCRService:
) from exc
with self._process_model_lock:
logger.info(
"加载 OCR 引擎: det=%s rec=%s device=%s model_dir=%s",
"加载 OCR 引擎: det=%s rec=%s device=%s cpu_threads=%d model_dir=%s",
self._det_model_name,
self._rec_model_name,
self.device,
self._cpu_threads,
self.model_dir,
)
self._engine = PaddleOCR(
@@ -150,6 +153,7 @@ class OCRService:
text_det_unclip_ratio=self._text_det_unclip_ratio,
text_rec_score_thresh=self._text_rec_score_thresh,
text_recognition_batch_size=self._text_recognition_batch_size,
cpu_threads=self._cpu_threads,
)
self._install_progress_hooks(self._engine)
logger.info("OCR 引擎加载完成")