Bladeren bron

feat(config): enhance layout detection configuration for smart router support

- Updated the layout detection configuration to conditionally set defaults based on the module type.
- Added validation for 'smart_router' configurations, ensuring required parameters are present.
- Introduced a default strategy for 'smart_router' if not specified, improving configuration robustness.
zhch158_admin 9 uur geleden
bovenliggende
commit
4a30adaeb8
1 gewijzigde bestanden met toevoegingen van 22 en 11 verwijderingen
  1. 22 11
      ocr_tools/universal_doc_parser/core/config_manager.py

+ 22 - 11
ocr_tools/universal_doc_parser/core/config_manager.py

@@ -56,17 +56,28 @@ class ConfigManager:
         )
         
         # 设置版式检测默认配置
-        layout_defaults = {
-            'module': 'mineru',
-            'model_name': 'layout',
-            'device': 'cpu',
-            'batch_size': 1,
-            'conf': 0.25,
-            'iou': 0.45
-        }
-        config['layout_detection'] = cls._merge_defaults(
-            config.get('layout_detection', {}), layout_defaults
-        )
+        layout_config = config.get('layout_detection', {})
+        # 如果是智能路由器,不需要设置默认值
+        if layout_config.get('module') != 'smart_router':
+            layout_defaults = {
+                'module': 'mineru',
+                'model_name': 'layout',
+                'device': 'cpu',
+                'batch_size': 1,
+                'conf': 0.25,
+                'iou': 0.45
+            }
+            config['layout_detection'] = cls._merge_defaults(
+                layout_config, layout_defaults
+            )
+        else:
+            # 智能路由器配置验证
+            if 'models' not in layout_config or not layout_config['models']:
+                raise ValueError("smart_router requires 'models' configuration with at least one model")
+            # 设置默认策略
+            if 'strategy' not in layout_config:
+                layout_config['strategy'] = 'ocr_eval'
+            config['layout_detection'] = layout_config
         
         # 设置VL识别默认配置
         # vl_defaults = {