|
|
@@ -14,7 +14,7 @@ from pathlib import Path
|
|
|
|
|
|
# 保存原始函数的引用
|
|
|
_original_get_table_recognition_res = None
|
|
|
-
|
|
|
+
|
|
|
def enhanced_get_table_recognition_res(
|
|
|
table_box: list,
|
|
|
table_structure_result: list,
|
|
|
@@ -518,4 +518,57 @@ pipeline = create_pipeline("table_recognition_v2")
|
|
|
results = pipeline.predict(image_path)
|
|
|
````
|
|
|
|
|
|
-这样既保持了原代码的完整性,又能实现你的个性化需求。
|
|
|
+这样既保持了原代码的完整性,又能实现你的个性化需求。
|
|
|
+
|
|
|
+## 无法正确进入adpter
|
|
|
+正在收集工作区信息正在筛选到最相关的信息你的判断完全正确:
|
|
|
+`from .table_recognition_post_processing_v2 import get_table_recognition_res`
|
|
|
+这种**直接 import 到局部作用域**的写法,会导致你在 module 层做 monkey patch(即`importlib.import_module(...).get_table_recognition_res = ...`)时,**pipeline_v2.py 内部的 get_table_recognition_res 变量不会被替换**,因为它已经在 import 时被绑定为本地函数对象。
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 解决方法
|
|
|
+
|
|
|
+### 方案1:直接 patch pipeline_v2 的局部变量
|
|
|
+
|
|
|
+你可以在 monkey patch 时**同时 patch paddlex.inference.pipelines.table_recognition.pipeline_v2 的 get_table_recognition_res**:
|
|
|
+
|
|
|
+````python
|
|
|
+import paddlex.inference.pipelines.table_recognition.pipeline_v2 as pipeline_v2
|
|
|
+from zhch.adapters.table_recognition_adapter import enhanced_get_table_recognition_res
|
|
|
+
|
|
|
+pipeline_v2.get_table_recognition_res = enhanced_get_table_recognition_res
|
|
|
+````
|
|
|
+
|
|
|
+这样,`_TableRecognitionPipelineV2` 里的所有 `get_table_recognition_res(...)` 调用都会用你的增强实现。
|
|
|
+
|
|
|
+### 方案2:修改 import 方式(推荐长期方案)
|
|
|
+
|
|
|
+如果你可以修改源码,建议把
|
|
|
+```python
|
|
|
+from .table_recognition_post_processing_v2 import get_table_recognition_res
|
|
|
+```
|
|
|
+改为
|
|
|
+```python
|
|
|
+import paddlex.inference.pipelines.table_recognition.table_recognition_post_processing_v2 as postproc_v2
|
|
|
+```
|
|
|
+然后用
|
|
|
+```python
|
|
|
+postproc_v2.get_table_recognition_res(...)
|
|
|
+```
|
|
|
+这样你只需要 monkey patch 一处即可,所有引用都能生效。
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 结论
|
|
|
+
|
|
|
+- 只 monkey patch module 层的 get_table_recognition_res 不足以影响 pipeline_v2.py 内部的直接 import。
|
|
|
+- 你**必须 patch paddlex.inference.pipelines.table_recognition.pipeline_v2.get_table_recognition_res**。
|
|
|
+- 推荐在适配器里加一行:
|
|
|
+
|
|
|
+````python
|
|
|
+import paddlex.inference.pipelines.table_recognition.pipeline_v2 as pipeline_v2
|
|
|
+pipeline_v2.get_table_recognition_res = enhanced_get_table_recognition_res
|
|
|
+````
|
|
|
+
|
|
|
+这样你的适配器就能100%生效,无需改动原有 PaddleX 代码。
|