diff --git a/config.yaml b/config.yaml index 3472fed..cb58533 100644 --- a/config.yaml +++ b/config.yaml @@ -47,7 +47,7 @@ preprocessing: # OCR 参数(PaddleOCR 原生参数) ocr: # === 通用参数 === - use_gpu: true # 自动检测 GPU,不可用则回退 CPU + use_gpu: false # GPU 包未就绪前强制 CPU lang: ch show_log: false use_angle_cls: true @@ -75,7 +75,7 @@ ocr: # === SVTR 文本识别 === rec_drop_score: 0.5 # 低于此置信度丢弃 - rec_char_dict_path: dict/finance_dict.txt # 自定义财务字典 + # rec_char_dict_path: dict/finance_dict.txt # 内置字典已覆盖财务大写 # === TableMaster 表格识别 === table_algorithm: TableMaster diff --git a/core/recognizer.py b/core/recognizer.py index 0bf74c7..287e23c 100644 --- a/core/recognizer.py +++ b/core/recognizer.py @@ -43,8 +43,9 @@ def _build_ocr_params(config: dict, photo_type: str = 'normal'): def _check_gpu_available() -> bool: - """检查 GPU 是否可用(不依赖 PaddlePaddle)""" + """检查 GPU 是否对 PaddleOCR 可用(不仅看 nvidia-smi)""" try: + # 先看 nvidia-smi import subprocess result = subprocess.run( ['nvidia-smi'], @@ -52,7 +53,11 @@ def _check_gpu_available() -> bool: text=True, timeout=5 ) - return result.returncode == 0 + if result.returncode != 0: + return False + # 再看 PaddlePaddle 能否真正加载 GPU + import paddle + return paddle.is_compiled_with_cuda() except Exception: return False @@ -130,6 +135,12 @@ def run_ocr_det_rec(img, config: dict, photo_type: str = 'normal', verbose=False ocr = PaddleOCR(**params) result = ocr.ocr(img, cls=True) + # 防御:PaddleOCR 可能返回 None 或 [None] + if not result or result[0] is None: + if verbose: + print(f" ⚠️ PaddleOCR 未检测到文字", file=sys.stderr) + return [] + lines = [] for line_group in result: for line in line_group: