Skip to content

Commit ca45394

Browse files
authored
docs: update blog
1 parent 37b9604 commit ca45394

1 file changed

Lines changed: 51 additions & 14 deletions

File tree

docs/blog/posts/support_pp_doc_layout.md

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ PP-DocLayout系列模型在版面分析方面效果很好,目前已经作为Pa
2525
- Python: 3.10.14
2626
- 其他依赖环境:
2727

28-
```text
29-
28+
```text linenums="1"
29+
paddle2onnx==2.1.0
30+
paddlepaddle==3.3.0
31+
onnx==1.17.0
32+
onnxruntime==1.23.2
3033
```
3134
3235
### 转换命令
@@ -37,27 +40,61 @@ paddle2onnx --model_dir=models/PP-DocLayoutV2 --model_filename inference.json
3740

3841
#### 比较结果
3942

40-
按照上面直接转换后,在相同输入下,ONNX模型和Paddle模型推理误差较大
43+
按照上面直接转换后,在相同输入下,ONNX模型和Paddle模型推理结果误差为14.8%。在我看来,这个误差其实挺大的
4144

42-
```bash
43-
>> np.testing.assert_allclose(batch_preds[0], ort_outputs[0], atol=1e-3, rtol=0)
45+
但是从可视化示例图结果来看,两者并无明显区别。可能在某些图上会有较大区别。
46+
47+
我在`/xxxx/miniforge3/envs/wjh_debug/lib/python3.10/site-packages/paddlex/inference/models/layout_analysis/predictor.py`中插入以下代码(在L103行左右),来保证输入相同,比较输出:
48+
49+
```python linenums="1"
50+
import onnxruntime
51+
import numpy as np
52+
53+
model_path = "models/PP-DocLayoutV2/inference_v5_op15_pd_cpu_fixed.onnx"
54+
ort_session = onnxruntime.InferenceSession(model_path)
55+
ort_inputs = {
56+
"im_shape": batch_inputs[0],
57+
"image": batch_inputs[1],
58+
"scale_factor": batch_inputs[2],
59+
}
60+
ort_outputs = ort_session.run(None, ort_inputs)
61+
62+
# do infer
63+
batch_preds = self.infer(batch_inputs)
64+
65+
# 千分位是否相同
66+
np.testing.assert_allclose(batch_preds[0], ort_outputs[0], atol=1e-3, rtol=0)
67+
```
68+
69+
输出结果如下:
70+
71+
```bash linenums="1"
4472
Traceback (most recent call last):
45-
File "<string>", line 1, in <module>
46-
File "/xxx/miniforge3/envs/wjh_debug/lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 1504, in assert_allclose
73+
File "/xxxx/paddleocr/test_pp_doc_layoutv2.py", line 4, in <module>
74+
output = model.predict(
75+
File "/xxxx/lib/python3.10/site-packages/paddleocr/_models/base.py", line 57, in predict
76+
result = list(self.predict_iter(*args, **kwargs))
77+
File "/xxxx/lib/python3.10/site-packages/paddlex/inference/models/base/predictor/base_predictor.py", line 281, in __call__
78+
yield from self.apply(input, **kwargs)
79+
File "/xxxx/lib/python3.10/site-packages/paddlex/inference/models/base/predictor/base_predictor.py", line 338, in apply
80+
prediction = self.process(batch_data, **kwargs)
81+
File "/xxxx/lib/python3.10/site-packages/paddlex/inference/models/layout_analysis/predictor.py", line 119, in process
82+
np.testing.assert_allclose(batch_preds[0], ort_outputs[0], atol=1e-3, rtol=0)
83+
File "/xxxx/lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 1504, in assert_allclose
4784
assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
48-
File "/xxx/miniforge3/envs/wjh_debug/lib/python3.10/contextlib.py", line 79, in inner
85+
File "/xxxx/lib/python3.10/contextlib.py", line 79, in inner
4986
return func(*args, **kwds)
50-
File "/xxx/miniforge3/envs/wjh_debug/lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 797, in assert_array_compare
87+
File "/xxxx/lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 797, in assert_array_compare
5188
raise AssertionError(msg)
5289
AssertionError:
5390
Not equal to tolerance rtol=0, atol=0.001
5491

55-
Mismatched elements: 1321 / 2400 (55%)
56-
Max absolute difference: 819.32886
57-
Max relative difference: 294.
58-
x: array([[2.200000e+01, 9.889959e-01, 3.354025e+01, ..., 6.150441e+02,
92+
Mismatched elements: 354 / 2400 (14.8%)
93+
Max absolute difference: 196.
94+
Max relative difference: 194.
95+
x: array([[2.200000e+01, 9.889924e-01, 3.354079e+01, ..., 6.150450e+02,
5996
2.900000e+02, 2.900000e+02],
60-
[2.200000e+01, 9.888721e-01, 3.372420e+01, ..., 8.526017e+02,...
97+
[2.200000e+01, 9.888635e-01, 3.372379e+01, ..., 8.526023e+02,...
6198
y: array([[2.200000e+01, 9.889925e-01, 3.354081e+01, ..., 6.150450e+02,
6299
2.900000e+02, 2.900000e+02],
63100
[2.200000e+01, 9.888635e-01, 3.372382e+01, ..., 8.526024e+02,...

0 commit comments

Comments
 (0)