Просмотр исходного кода

新增脚本:test_evaluator.py,用于强制导入注册模块并检查模型注册状态

zhch158_admin 3 месяцев назад
Родитель
Сommit
a0c965a816
1 измененных файлов с 65 добавлено и 0 удалено
  1. 65 0
      zhch/test_evaluator.py

+ 65 - 0
zhch/test_evaluator.py

@@ -0,0 +1,65 @@
+# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import sys
+import os
+from paddlex.engine import Engine
+
+# 设置环境变量
+# os.environ["PADDLE_PDX_PADDLEOCR_PATH"] = "/Users/zhch158/workspace/repository.git/PaddleX/paddle_env/lib/python3.11/site-packages/paddleocr"
+
+# 添加PaddleX路径
+# sys.path.insert(0, '/Users/zhch158/workspace/repository.git/PaddleX')
+
+def force_import_registrations():
+    """强制导入所有注册模块"""
+    try:
+        # 强制导入注册模块
+        import paddlex.repo_apis.PaddleOCR_api.table_rec.register
+        import paddlex.repo_apis.PaddleOCR_api.text_rec.register  
+        import paddlex.repo_apis.PaddleOCR_api.text_det.register
+        import paddlex.repo_apis.PaddleOCR_api.formula_rec.register
+        # import paddlex.repo_apis.PaddleOCR_api.textline_orientation.register
+        # import paddlex.repo_apis.PaddleOCR_api.doc_text_orientation.register
+        
+        print("✓ 所有注册模块导入成功")
+        
+        # 检查注册状态
+        from paddlex.repo_apis.base.register import MODEL_INFO_REGISTRY
+        table_models = [name for name in MODEL_INFO_REGISTRY._table.keys() 
+                       if 'SLA' in name]
+        print(f"已注册的表格模型: {table_models}")
+        
+        if 'SLANet_plus' in MODEL_INFO_REGISTRY._table:
+            print("✓ SLANet_plus 已成功注册")
+            return True
+        else:
+            print("✗ SLANet_plus 仍未注册")
+            return False
+            
+    except Exception as e:
+        print(f"注册模块导入失败: {e}")
+        return False
+
+if __name__ == "__main__":
+    # if force_import_registrations():
+    #     # 现在运行引擎
+    #     from paddlex.engine import Engine
+    #     print("开始运行...")
+    #     Engine().run()
+    # else:
+    #     print("注册失败,无法继续")
+    Engine().run()
+