Prechádzať zdrojové kódy

feat(layout_model_router): add debug mode configuration for models

- Implemented the ability to pass debug mode settings to both primary and fallback models in the SmartLayoutRouter class.
- Enhanced model configuration by allowing output directory and page name settings to be inherited from the router, improving debugging capabilities during layout detection.
zhch158_admin 2 dní pred
rodič
commit
4121d3eac9

+ 15 - 0
ocr_tools/universal_doc_parser/core/layout_model_router.py

@@ -162,6 +162,14 @@ class SmartLayoutRouter(BaseLayoutDetector):
             if model_name == 'fallback':
                 continue  # 跳过回退模型(除非所有模型都失败)
             try:
+                # 传递 debug 模式配置给子模型(如果启用)
+                if self.debug_mode:
+                    model.debug_mode = self.debug_mode  # type: ignore
+                    if self.output_dir:
+                        model.output_dir = self.output_dir  # type: ignore
+                    if self.page_name:
+                        model.page_name = self.page_name  # type: ignore
+                
                 # 调用 detect() 方法,基类会自动执行后处理
                 results = model.detect(image)
                 all_postprocessed_results[model_name] = results
@@ -174,6 +182,13 @@ class SmartLayoutRouter(BaseLayoutDetector):
             # 如果所有模型都失败,尝试回退模型
             if 'fallback' in self.models:
                 logger.info("🔄 All models failed, using fallback model")
+                # 传递 debug 模式配置给回退模型(如果启用)
+                if self.debug_mode:
+                    self.models['fallback'].debug_mode = self.debug_mode  # type: ignore
+                    if self.output_dir:
+                        self.models['fallback'].output_dir = self.output_dir  # type: ignore
+                    if self.page_name:
+                        self.models['fallback'].page_name = self.page_name  # type: ignore
                 # 回退模型使用 detect() 方法(会自动执行后处理)
                 fallback_result = self.models['fallback'].detect(image)
                 return fallback_result