OCR 修复:无 cuDNN 用 CPU、禁用 ir_optim 避免 SIGILL。
This commit is contained in:
@@ -10,6 +10,7 @@ from fastapi import FastAPI, File, Header, HTTPException, UploadFile
|
||||
from PIL import Image
|
||||
|
||||
os.environ.setdefault("OPENCV_IO_ENABLE_OPENEXR", "0")
|
||||
os.environ.setdefault("FLAGS_use_mkldnn", "0")
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
||||
logger = logging.getLogger("ocr-worker")
|
||||
@@ -36,7 +37,8 @@ def _create_engine(use_gpu: bool):
|
||||
lang="ch",
|
||||
show_log=False,
|
||||
use_gpu=use_gpu,
|
||||
enable_mkldnn=not use_gpu,
|
||||
enable_mkldnn=False,
|
||||
ir_optim=False,
|
||||
det_limit_side_len=min(OCR_MAX_SIDE, 1280),
|
||||
rec_batch_num=8,
|
||||
)
|
||||
@@ -150,19 +152,7 @@ def _run_ocr_impl(content: bytes) -> dict:
|
||||
|
||||
|
||||
def run_ocr_on_bytes(content: bytes) -> dict:
|
||||
try:
|
||||
return _run_ocr_impl(content)
|
||||
except Exception as exc:
|
||||
err = str(exc).lower()
|
||||
gpu_fail = _engine_mode == "gpu" and any(
|
||||
x in err for x in ("cuda", "cudnn", "gpu", "out of memory", "resource exhausted", "precondition")
|
||||
)
|
||||
if gpu_fail and OCR_USE_GPU:
|
||||
logger.warning("GPU OCR runtime failed, retry CPU: %s", exc)
|
||||
_reset_engine()
|
||||
get_engine(force_cpu=True)
|
||||
return _run_ocr_impl(content)
|
||||
raise
|
||||
return _run_ocr_impl(content)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
|
||||
Reference in New Issue
Block a user