pass1-lite 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pass1_lite-0.2.0/CITATION.cff +18 -0
- pass1_lite-0.2.0/LICENSE +202 -0
- pass1_lite-0.2.0/MANIFEST.in +7 -0
- pass1_lite-0.2.0/NOTICE +36 -0
- pass1_lite-0.2.0/PKG-INFO +98 -0
- pass1_lite-0.2.0/README.md +122 -0
- pass1_lite-0.2.0/README_pypi.md +67 -0
- pass1_lite-0.2.0/README_zh.md +89 -0
- pass1_lite-0.2.0/assets/ASSETS-LICENSE.md +16 -0
- pass1_lite-0.2.0/assets/benchmark_unseen298.png +0 -0
- pass1_lite-0.2.0/examples/reproduce.py +47 -0
- pass1_lite-0.2.0/examples/run_xiaomi_vllm.py +80 -0
- pass1_lite-0.2.0/pyproject.toml +52 -0
- pass1_lite-0.2.0/setup.cfg +4 -0
- pass1_lite-0.2.0/src/pass1_lite/__init__.py +82 -0
- pass1_lite-0.2.0/src/pass1_lite/adapters.py +528 -0
- pass1_lite-0.2.0/src/pass1_lite/cli.py +523 -0
- pass1_lite-0.2.0/src/pass1_lite/client.py +290 -0
- pass1_lite-0.2.0/src/pass1_lite/core.py +870 -0
- pass1_lite-0.2.0/src/pass1_lite.egg-info/PKG-INFO +98 -0
- pass1_lite-0.2.0/src/pass1_lite.egg-info/SOURCES.txt +29 -0
- pass1_lite-0.2.0/src/pass1_lite.egg-info/dependency_links.txt +1 -0
- pass1_lite-0.2.0/src/pass1_lite.egg-info/entry_points.txt +2 -0
- pass1_lite-0.2.0/src/pass1_lite.egg-info/requires.txt +6 -0
- pass1_lite-0.2.0/src/pass1_lite.egg-info/top_level.txt +1 -0
- pass1_lite-0.2.0/tests/test_adapters_cli_client.py +626 -0
- pass1_lite-0.2.0/tests/test_pass1_lite.py +568 -0
- pass1_lite-0.2.0/tests/test_upstream_pr_patches.py +432 -0
- pass1_lite-0.2.0/upstream_pr/0001-paddlex-preserve-polygon.patch +170 -0
- pass1_lite-0.2.0/upstream_pr/0002-hf-preserve-polygon-and-docs.patch +214 -0
- pass1_lite-0.2.0/upstream_pr/PR_DESCRIPTION.md +38 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use Pass1_Lite in your research or OCR pipeline, please cite it using the metadata below."
|
|
3
|
+
type: software
|
|
4
|
+
title: "Pass1_Lite: Training-Free Geometric and Frequency-Gated Pass-1 Crop Refinement for Two-Stage Document OCR"
|
|
5
|
+
version: "0.2.0"
|
|
6
|
+
date-released: "2026-11-19"
|
|
7
|
+
license: "Apache-2.0"
|
|
8
|
+
repository-code: "https://github.com/wangsenning/pass1-lite"
|
|
9
|
+
url: "https://github.com/wangsenning/pass1-lite"
|
|
10
|
+
authors:
|
|
11
|
+
- name: "wangsenning"
|
|
12
|
+
email: "2873329570@qq.com"
|
|
13
|
+
keywords:
|
|
14
|
+
- ocr
|
|
15
|
+
- document-ai
|
|
16
|
+
- layout-analysis
|
|
17
|
+
- image-processing
|
|
18
|
+
- moire-suppression
|
pass1_lite-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
include LICENSE NOTICE README.md README_zh.md README_pypi.md CITATION.cff pyproject.toml
|
|
2
|
+
recursive-include src *.py
|
|
3
|
+
recursive-include tests *.py
|
|
4
|
+
recursive-include examples *.py
|
|
5
|
+
recursive-include upstream_pr *.patch *.md
|
|
6
|
+
include assets/benchmark_unseen298.png
|
|
7
|
+
include assets/ASSETS-LICENSE.md
|
pass1_lite-0.2.0/NOTICE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Pass1_Lite OCR Refinement Toolkit
|
|
2
|
+
Licensed under the Apache License, Version 2.0.
|
|
3
|
+
|
|
4
|
+
Third-Party Code Attribution & Modifications:
|
|
5
|
+
---------------------------------------------
|
|
6
|
+
1. `fit_image` in `src/pass1_lite/core.py` is derived from
|
|
7
|
+
`evaluation_pipeline/cropping.py` in Xiaomi-OCR-0
|
|
8
|
+
(https://github.com/xiaomi-research/Xiaomi-OCR-0, snapshot files dated
|
|
9
|
+
2026-11-04, Apache License 2.0).
|
|
10
|
+
Modification summary: copied into a standalone non-in-place variant
|
|
11
|
+
(`image.copy()` prior to `PIL.Image.Image.thumbnail`) so caller images shared
|
|
12
|
+
across evaluation or inference arms are never mutated in-place.
|
|
13
|
+
|
|
14
|
+
2. Label/task mappings (`LABEL_TASK_MAPPING` in `src/pass1_lite/adapters.py`),
|
|
15
|
+
prompt contracts (`XIAOMI_PROMPTS` in `src/pass1_lite/client.py`), and
|
|
16
|
+
repetition-detection heuristics (`detect_repetition_loop` in
|
|
17
|
+
`src/pass1_lite/client.py`, adapted from `postprocess/repetition_guard.py`
|
|
18
|
+
with additional guards for sparse OTSL grids, Markdown table separators, and
|
|
19
|
+
typographic leaders) match the upstream Xiaomi-OCR-0 two-stage pipeline
|
|
20
|
+
(`Apache License 2.0`). Upstream source files carry no additional
|
|
21
|
+
repository-level `NOTICE` file beyond `THIRD_PARTY_NOTICES.md` (which applies
|
|
22
|
+
solely to KaTeX 0.16.11 frontend assets not redistributed here).
|
|
23
|
+
|
|
24
|
+
Package Distribution Contents & Benchmark Attribution:
|
|
25
|
+
------------------------------------------------------
|
|
26
|
+
- Python wheel (`.whl`) and source distribution (`.tar.gz`) builds contain ONLY
|
|
27
|
+
Apache-2.0 source code, tests, examples, standalone upstream PR patches,
|
|
28
|
+
asset license notes (`assets/ASSETS-LICENSE.md`), and the original numeric
|
|
29
|
+
benchmark chart (`assets/benchmark_unseen298.png`).
|
|
30
|
+
Neither archive contains dataset images, qualitative showcase figures, or
|
|
31
|
+
benchmark page-ID manifests (`report/`).
|
|
32
|
+
- Benchmark evaluations reported in repository documentation were conducted on
|
|
33
|
+
`Real5-OmniDocBench` (`PaddlePaddle/Real5-OmniDocBench`) and `OmniDocBench`
|
|
34
|
+
(`opendatalab/OmniDocBench`). For licensing and attribution details governing
|
|
35
|
+
non-code documentation assets in the source repository (including
|
|
36
|
+
`assets/showcase_before_after*.png`), see `assets/ASSETS-LICENSE.md`.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pass1-lite
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Training-free geometric and frequency-gated Pass-1 crop refinement for two-stage document OCR
|
|
5
|
+
Author-email: wangsenning <2873329570@qq.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/wangsenning/pass1-lite
|
|
8
|
+
Project-URL: Repository, https://github.com/wangsenning/pass1-lite
|
|
9
|
+
Project-URL: Issues, https://github.com/wangsenning/pass1-lite/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/wangsenning/pass1-lite#readme
|
|
11
|
+
Keywords: ocr,document-ai,layout-analysis,image-processing,moire-suppression
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
License-File: NOTICE
|
|
25
|
+
Requires-Dist: numpy>=1.24
|
|
26
|
+
Requires-Dist: opencv-python-headless>=4.8
|
|
27
|
+
Requires-Dist: pillow>=10.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# Pass1_Lite
|
|
33
|
+
|
|
34
|
+
**Drop-in crop refinement between your layout detector and OCR VLM.**
|
|
35
|
+
Cuts real-world text edit distance from **`0.0519` to `0.0403` (`-22.4%` relative, `+0.48/100` Real5 overall; `-41.9%` on Skew, `-28.0%` on Screen photos)** with **zero retraining**, **zero PyTorch**, and **≈1.00× runtime (`0.9986×` All6 / `1.0047×` Real5)**.
|
|
36
|
+
|
|
37
|
+
[GitHub Repository & Visual Before/After Showcase](https://github.com/wangsenning/pass1-lite#readme) · [简体中文文档](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/README_zh.md) · [Full Statistical Audit](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/report/retrospective.md) · [Upstream PR Patches](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/upstream_pr/PR_DESCRIPTION.md)
|
|
38
|
+
|
|
39
|
+
## Why Pass1_Lite?
|
|
40
|
+
|
|
41
|
+
Two-stage document OCR (`Layout Detector → Crop → VLM`) loses accuracy in the wild for three simple, fixable reasons:
|
|
42
|
+
|
|
43
|
+
1. **Skewed crops pull in neighbor text** — Axis-aligned boxes absorb adjacent headings, columns, and captions. `Pass1_Lite` masks exterior pixels using a `+4 px` dilated polygon filled with **local 85th-percentile paper luminance** (no clipped strokes, no harsh gray seams).
|
|
44
|
+
2. **Phone photos of screens break VLM vision encoders** — LCD RGB subpixel moiré scrambles digits and small words. `Pass1_Lite` auto-detects subpixel chroma oscillation on native pages and applies **text-only luminance LPF + `2×` upscaling** (tables & formulas stay untouched; `<0.9%` of Clean regions (5/298 pages)).
|
|
45
|
+
3. **Detectors invert vertical order inside columns** — `Pass1_Lite` runs a deterministic, idempotent same-column order repair pass before Markdown assembly.
|
|
46
|
+
|
|
47
|
+
> **Why not full-page deskew or raw `crop(bbox)`?** Two-pass deskew regresses Clean (`-0.33`) and Scanning (`-0.60`) while adding `+3.6%` latency; raw `crop(bbox)` or 0 px hard-white/gray masks leave neighbor bleed, clipped strokes, or unmitigated screen moiré. `Pass1_Lite` is the zero-regression middle layer verified on 1,788 blind images.
|
|
48
|
+
>
|
|
49
|
+
> **Lightweight & honest scope:** Only `numpy`, `opencv-python-headless`, and `pillow` (zero `torch`). All benchmark gains below were measured on **`Xiaomi-OCR-0 (0.8B)` + `PaddleX PP-DocLayoutV3`**; the Python/CLI adapters also accept `HuggingFace` / custom JSON layouts and any OpenAI-compatible VLM endpoint (`vLLM`, `Qwen-VL`, etc.) via `--preset generic` *(gains on other VLMs have not been benchmarked here)*.
|
|
50
|
+
|
|
51
|
+
## 30-Second Quickstart
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install pass1-lite
|
|
55
|
+
|
|
56
|
+
# 1. Try instantly with zero GPU / zero models (generates side-by-side comparison.png)
|
|
57
|
+
pass1-lite demo --out-dir ./demo_out
|
|
58
|
+
|
|
59
|
+
# 2. Diagnose LCD moire & EXIF rotation risks on any real photo
|
|
60
|
+
pass1-lite inspect ./scan.jpg
|
|
61
|
+
|
|
62
|
+
# 3. End-to-end two-stage OCR -> Markdown (PaddleX -> Pass1_Lite -> vLLM)
|
|
63
|
+
pass1-lite ocr ./pages/ --paddlex \
|
|
64
|
+
--vllm-url http://127.0.0.1:8000/v1 --model Xiaomi-OCR-0 \
|
|
65
|
+
--out-dir ./md_out --save-visual --resume
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Python API (6 Lines, Zero Glue Code)
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from pass1_lite import from_paddlex_result, load_image_rgb, ocr_page_crops, prepare_page_crops
|
|
72
|
+
|
|
73
|
+
img = load_image_rgb("page.jpg")
|
|
74
|
+
regions = from_paddlex_result(paddlex_pred, *img.size, table_threshold=0.25) # or from_hf_detections(...)
|
|
75
|
+
bundle = prepare_page_crops(img, regions)
|
|
76
|
+
markdown, _ = ocr_page_crops(bundle, base_url="http://127.0.0.1:8000/v1", model="Xiaomi-OCR-0")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Benchmark (`298` Held-Out Docs × `6` Domains = `1,788` Images)
|
|
80
|
+
|
|
81
|
+

|
|
82
|
+
|
|
83
|
+
| Pipeline | Clean | Screen | Skew | Warping | Real5 Overall | Real5 Text Error ↓ | All6 Runtime |
|
|
84
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
85
|
+
| Standard Baseline (`official_base`) | `95.62` | `94.19` | `92.10` | `95.25` | `94.47` | `0.0519` | `1.000×` |
|
|
86
|
+
| **`Pass1_Lite` (Single-Pass Default)** | **`95.63`** | **`94.80`** | `93.47` | **`95.52`** | `94.95` (`+0.48`) | `0.0403` (`-22.4%`) | **`0.9986×`** |
|
|
87
|
+
| Two-Pass Full-Page Deskew (`sysfix_v1`) | `95.29` (`-0.33`) | **`94.80`** | **`95.73`** | `94.99` (`-0.26`) | **`95.17`** | **`0.0388`** | `1.036×` |
|
|
88
|
+
|
|
89
|
+
*Best value(s) per column are **bolded**. `Pass1_Lite` row reports the GPU-verified `v0.2` default (`Real5=94.9491`, `Skew=93.4685`, `Warping=95.5222`); the pre-registered frozen run (`fill_ratio_mode="frozen_unclipped"`) scored `Real5=94.9424` (`Skew=93.4812`, `Warping=95.4761`; paired `text_ED` diff `0.0000`, `p=0.71`).*
|
|
90
|
+
|
|
91
|
+
- **Safe production default:** Statistically significant text error reduction in **6/6 domains (`p ≤ 0.039`)** with **0 domain regressions** (Clean `+0.01`, Real5 text ED `0.0519 → 0.0403` / `-22.4%`, `+0.48/100` overall, `181` docs improved / `21` worse / `68` tied), at **≈1.00× runtime** (`0.9986×` All6, `1.0047×` Real5; `3.6%` faster than two-pass deskew).
|
|
92
|
+
- **Honest scope:** Statistically significant gains are in **text (`p < 0.001`)** and **reading order (`p < 0.001`)**. Table (`p=0.89`) and formula (`p=0.33`) deltas vs baseline are not statistically significant. Against two-pass deskew, `Pass1_Lite` missed pre-registered non-inferiority (`G4 FAIL`, `-0.22` Real5 overall) because severe skew formulas still favor full-page rotation (`cdm_pg 96.24` vs `90.97`), at the cost of Clean (`-0.33`), Warping (`-0.26`), and Scanning (`-0.60`) regressions.
|
|
93
|
+
|
|
94
|
+
See the [GitHub repository](https://github.com/wangsenning/pass1-lite#readme) for real-dataset before/after visual comparisons, full statistical audit (`G1–G4`, pretraining overlap disclosure, `v0.2` GPU parity), CLI guardrails, and standalone upstream PR patches.
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
Apache-2.0 ([`LICENSE`](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/LICENSE) · [`NOTICE`](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/NOTICE)). PyPI wheel and sdist packages contain pure Apache-2.0 code and the original numeric benchmark chart only (zero dataset images or benchmark page-ID manifests).
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Pass1_Lite
|
|
4
|
+
|
|
5
|
+
**Drop-in crop refinement between your layout detector and OCR VLM.**
|
|
6
|
+
Cut real-world text edit distance from **`0.0519` to `0.0403` (`-22.4%` relative, `+0.48/100` Real5 overall; `-41.9%` on Skew, `-28.0%` on Screen photos)** with **zero retraining**, **zero PyTorch**, and **≈1.00× runtime (`0.9986×` All6 / `1.0047×` Real5)**.
|
|
7
|
+
|
|
8
|
+
**English** · [简体中文](README_zh.md) · [Audit Report](report/retrospective.md) · [Upstream PR Patches](upstream_pr/PR_DESCRIPTION.md)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
<sub><b>Selected qualitative examples</b> from <code>Real5-OmniDocBench</code> (<code>unseen_298</code>, <code>Xiaomi-OCR-0 0.8B</code> + <code>PP-DocLayoutV3</code>). Aggregate across 1,788 images: Real5 text ED <code>0.0519 → 0.0403</code> (<code>-22.4%</code>, <code>+0.48/100</code> overall; <code>181</code> docs better / <code>21</code> worse / <code>68</code> tied across 270 text docs). Known failure mode: severe skew formulas still favor two-pass deskew (<code>cdm_pg 96.24</code> vs <code>90.97</code>). Shown strictly as research commentary and excluded from PyPI builds; see <a href="assets/ASSETS-LICENSE.md">assets/ASSETS-LICENSE.md</a>.</sub>
|
|
14
|
+
|
|
15
|
+
## Why Pass1_Lite?
|
|
16
|
+
|
|
17
|
+
Two-stage document OCR (`Layout Detector → Crop → VLM`) loses accuracy in the wild for three simple, fixable reasons:
|
|
18
|
+
|
|
19
|
+
1. **Skewed crops pull in neighbor text** — Axis-aligned boxes absorb adjacent headings, columns, and captions. `Pass1_Lite` masks exterior pixels using a `+4 px` dilated polygon filled with **local 85th-percentile paper luminance** (no clipped strokes, no harsh gray seams).
|
|
20
|
+
2. **Phone photos of screens break VLM vision encoders** — LCD RGB subpixel moiré scrambles digits and small words. `Pass1_Lite` auto-detects subpixel chroma oscillation on native pages and applies **text-only luminance LPF + `2×` upscaling** (tables & formulas stay untouched; `<0.9%` of Clean regions (5/298 pages)).
|
|
21
|
+
3. **Detectors invert vertical order inside columns** — `Pass1_Lite` runs a deterministic, idempotent same-column order repair pass before Markdown assembly.
|
|
22
|
+
|
|
23
|
+
> **Why not full-page deskew or raw `crop(bbox)`?** Two-pass deskew regresses Clean (`-0.33`) and Scanning (`-0.60`) while adding `+3.6%` latency; raw `crop(bbox)` or 0 px hard-white/gray masks leave neighbor bleed, clipped strokes, or unmitigated screen moiré. `Pass1_Lite` is the zero-regression middle layer verified on 1,788 blind images.
|
|
24
|
+
>
|
|
25
|
+
> **Lightweight & honest scope:** Only `numpy`, `opencv-python-headless`, and `pillow` (zero `torch`). All benchmark gains below were measured on **`Xiaomi-OCR-0 (0.8B)` + `PaddleX PP-DocLayoutV3`**; the Python/CLI adapters also accept `HuggingFace` / custom JSON layouts and any OpenAI-compatible VLM endpoint (`vLLM`, `Qwen-VL`, etc.) via `--preset generic` *(gains on other VLMs have not been benchmarked here)*.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 30-Second Quickstart
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install pass1-lite # or from source: pip install . (dev: pip install -e ".[dev]")
|
|
33
|
+
|
|
34
|
+
# 1. Try instantly with zero GPU / zero models (generates side-by-side comparison.png)
|
|
35
|
+
pass1-lite demo --out-dir ./demo_out
|
|
36
|
+
|
|
37
|
+
# 2. Diagnose LCD moire & EXIF rotation risks on any real photo
|
|
38
|
+
pass1-lite inspect ./scan.jpg
|
|
39
|
+
|
|
40
|
+
# 3. End-to-end two-stage OCR -> Markdown (PaddleX -> Pass1_Lite -> vLLM)
|
|
41
|
+
pass1-lite ocr ./pages/ --paddlex \
|
|
42
|
+
--vllm-url http://127.0.0.1:8000/v1 --model Xiaomi-OCR-0 \
|
|
43
|
+
--out-dir ./md_out --save-visual --resume
|
|
44
|
+
```
|
|
45
|
+
<sub>Already have layout JSON/JSONL? Replace <code>--paddlex</code> with <code>--layout layout.json</code> (single page) or <code>--layout-jsonl layout.jsonl</code> (directories). Using Qwen-VL or another VLM? Add <code>--preset generic</code>. Add <code>--retry-repetitive</code> to opt into repetition-collapse retries.</sub>
|
|
46
|
+
|
|
47
|
+
### Python API (6 Lines, Zero Glue Code)
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from pass1_lite import from_paddlex_result, load_image_rgb, ocr_page_crops, prepare_page_crops
|
|
51
|
+
|
|
52
|
+
img = load_image_rgb("page.jpg")
|
|
53
|
+
regions = from_paddlex_result(paddlex_pred, *img.size, table_threshold=0.25) # or from_hf_detections(...)
|
|
54
|
+
bundle = prepare_page_crops(img, regions)
|
|
55
|
+
markdown, _ = ocr_page_crops(bundle, base_url="http://127.0.0.1:8000/v1", model="Xiaomi-OCR-0")
|
|
56
|
+
```
|
|
57
|
+
Runnable scripts: [examples/reproduce.py](examples/reproduce.py) · [examples/run_xiaomi_vllm.py](examples/run_xiaomi_vllm.py)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Benchmark (`298` Held-Out Docs × `6` Domains = `1,788` Images)
|
|
62
|
+
|
|
63
|
+

|
|
64
|
+
|
|
65
|
+
| Pipeline | Clean | Screen | Skew | Warping | Real5 Overall | Real5 Text Error ↓ | All6 Runtime |
|
|
66
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
67
|
+
| Standard Baseline (`official_base`) | `95.62` | `94.19` | `92.10` | `95.25` | `94.47` | `0.0519` | `1.000×` |
|
|
68
|
+
| **`Pass1_Lite` (Single-Pass Default)** | **`95.63`** | **`94.80`** | `93.47` | **`95.52`** | `94.95` (`+0.48`) | `0.0403` (`-22.4%`) | **`0.9986×`** |
|
|
69
|
+
| Two-Pass Full-Page Deskew (`sysfix_v1`) | `95.29` (`-0.33`) | **`94.80`** | **`95.73`** | `94.99` (`-0.26`) | **`95.17`** | **`0.0388`** | `1.036×` |
|
|
70
|
+
|
|
71
|
+
<sub>Best value(s) in each column are <b>bolded</b>. The <code>Pass1_Lite</code> row reports the GPU-verified <code>v0.2</code> default (<code>pass1_lite_v02_clipped</code> in <code>report/results.csv</code>: <code>Real5=94.9491</code>, <code>Skew=93.4685</code>, <code>Warping=95.5222</code>); the pre-registered frozen run (<code>fill_ratio_mode="frozen_unclipped"</code>) scored <code>Real5=94.9424</code> (<code>Skew=93.4812</code>, <code>Warping=95.4761</code>; paired <code>text_ED</code> diff <code>0.0000</code>, <code>p=0.71</code>).</sub>
|
|
72
|
+
|
|
73
|
+
- **Safe production default:** Statistically significant text error reduction in **6/6 domains (`p ≤ 0.039`)** with **0 domain regressions** (Clean `+0.01`, Real5 text ED `0.0519 → 0.0403` / `-22.4%`, `+0.48/100` overall; `-41.9%` Skew, `-28.0%` Screen, `-17.7%` Warping), at **≈1.00× runtime** (`0.9986×` All6, `1.0047×` Real5; `3.6%` faster than two-pass deskew).
|
|
74
|
+
- **Honest scope:** Statistically significant gains are in **text (`p < 0.001`)** and **reading order (`p < 0.001`)**. Table & formula deltas vs baseline are not statistically significant, and severe skew still benefits from two-pass deskew (`G4 FAIL`, `-0.22` Real5 overall) at the expense of Clean (`-0.33`), Warping (`-0.26`), and Scanning (`-0.60`) regressions.
|
|
75
|
+
|
|
76
|
+
<details>
|
|
77
|
+
<summary><strong>Full Statistical Audit, Pretraining Disclosure & Upstream <code>--polygon</code> Control</strong></summary>
|
|
78
|
+
|
|
79
|
+
1. **Split Hygiene, Provenance & Upstream Pretraining Caveat**: `unseen_298` (`298` unique stems / `canon_doc`s × `6` domains = `1,788` images) has **`0` stem/`canon_doc` overlap** with all internal development/tuning splits (`dev_52`, `scale60`, `test_fresh`, `demo18`, `test_extra`, `region_data_v1`, `splits.json`). Upstream `PaddleX PP-DocLayoutV3` (`PaddlePaddle`, also the `Real5-OmniDocBench` authors) and `Xiaomi-OCR-0` pretraining corpora may overlap with `OmniDocBench` / `Real5-OmniDocBench`; `"held-out"` strictly guarantees zero leakage against our tuning and development splits. Page identifiers in `report/pages.csv` are verbatim official `OmniDocBench` IDs for split reproducibility (`report/` is excluded from PyPI distributions).
|
|
80
|
+
2. **Pre-Registered Gates (`G1–G3 PASS`, `G4 FAIL`)**:
|
|
81
|
+
- **G1 PASS**: Pooled `Real5` `text_ED` improvement **`+0.0116`** (`95% CI=[0.0094, 0.0137]`, `p < 0.001` [`0.0002`, 5,000-perm floor], `LOTO3=+0.0107`, `WLT=181/21/68` on `v0.2` default; `181/20/69` frozen).
|
|
82
|
+
- **G2 PASS**: Pooled `Real5` `ro_ED` improvement **`+0.0060`** (`95% CI=[0.0032, 0.0088]`, `p < 0.001` [`0.0002`], `LOTO3=+0.0048`).
|
|
83
|
+
- **G3 PASS**: `Clean` `v16_ov_nb +0.0117` (`95.6306`), `text_ED 0.0333 -> 0.0326` (`p=0.0386`), `ro_ED p < 0.001`, table `p=0.5023`, Clean moire false-trigger rate `5/298` pages (`<0.9%` regions).
|
|
84
|
+
- **G4 FAIL**: Against two-pass `sysfix_v1`, `pass1_lite` missed `Real5 v16_ov_nb >= -0.20` (`-0.2179` on `v0.2`, `-0.2246` frozen; `sysfix_v1` `Skew cdm_pg=96.24` vs `90.97` on `n=38` formula docs) and frozen `text_ED` CI lower bound (`-0.0033` vs `-0.0030`). Pooled `Real5` table (`p=0.8938`) and formula (`p=0.3267`) deltas vs `official_base` are non-significant. Wall-clock totals (`All6`): `official_base` `8994s`, `pass1_lite` `8982s` (`0.9986×`; Real5-only `1.0047×`), `sysfix_v1` `9319s` (`1.0361×`).
|
|
85
|
+
3. **GPU-Verified `v0.2` Default Parity**: Re-inferring all `591 / 1,788` `unseen_298` pages (`19,605` crops) where `from_paddlex_result` + `prepare_page_crops(..., fill_ratio_mode="clipped")` differed by ≥1 pixel under identical FP16 vLLM + official `OmniDocBench v1.6 + CDM` (`0` timeouts, `0` errors) yielded `Real5 v16_ov_nb = 94.9491` (`+0.4833` vs base, `+0.0067` vs frozen `94.9424`), `All6 = 95.0627` (`+0.4047` vs base), `Clean` identical to 4 decimals, and paired `v0.2` vs frozen `text_ED` diff `0.0000` (`p=0.7105`). Pass `fill_ratio_mode="frozen_unclipped"` to reproduce the exact pre-registered frozen crops bit-for-bit.
|
|
86
|
+
4. **Upstream `--polygon` Preservation Fix (`dev_52 Skew + Warping`)**: Upstream `Xiaomi-OCR-0` already implemented gray `(128,128,128)` masking in `cropping.py`, but `layout_detect_paddlex.py` overwrote `polygon` with a 4-point bbox and HF postprocessing dropped `polygon_points`. Restoring propagation (`N`, see [`upstream_pr/`](upstream_pr/PR_DESCRIPTION.md)) gains `+0.3634` (`Skew`) and `+0.3311` (`Warping`) over `official_base`, **while `Skew` `cdm_pg` (`n=9` formula pages, driven chiefly by `jiaocaineedrop_20608808.pdf_0.jpg`) moved from `99.45` to `96.24` (`-3.21 pp`)**. `Pass1_Lite` (`fill_ratio_mode="frozen_unclipped"` in frozen eval) restores `cdm_pg` to `99.45` and outperforms `N` by `+1.2214` (`Skew`, `88%` from `+3.21/3 = +1.07` formula recovery on `n=9` pages; doc-clustered `text_ED p=0.3505` non-significant) and `+0.1366` (`Warping`, doc-clustered text `p=0.0436`).
|
|
87
|
+
|
|
88
|
+
Full ledger: [report/retrospective.md](report/retrospective.md) · [report/results.csv](report/results.csv) · [report/pages.csv](report/pages.csv)
|
|
89
|
+
|
|
90
|
+
</details>
|
|
91
|
+
|
|
92
|
+
<details>
|
|
93
|
+
<summary><strong>CLI Reference, Usage Guardrails & Repository Map</strong></summary>
|
|
94
|
+
|
|
95
|
+
### CLI Commands
|
|
96
|
+
| Command | Purpose |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `pass1-lite demo [--out-dir DIR]` | Run synthetic skew/moire/order demo & save `comparison.png` |
|
|
99
|
+
| `pass1-lite inspect <path> [--json] [--exif-transpose]` | Check native resolution, EXIF orientation warnings, and moire score |
|
|
100
|
+
| `pass1-lite refine <img> --layout <json> --out-dir <dir> [--save-visual]` | Export refined crops, updated regions JSON, and visual comparison |
|
|
101
|
+
| `pass1-lite ocr <path> --vllm-url <url> --model <name> (--paddlex \| --layout \| --layout-jsonl) --out-dir <dir> [--resume] [--retry-repetitive]` | End-to-end two-stage OCR to Markdown (per-page error isolation, default `max_tokens=16384`) |
|
|
102
|
+
|
|
103
|
+
### Usage Guardrails
|
|
104
|
+
- Keep Stage-1 `table_threshold=0.25` (with `--paddlex`, this sets the global PaddleX detector threshold across all classes matching upstream `Xiaomi-OCR-0`; with `--layout`/`--layout-jsonl`, it filters scored `table` regions while preserving unscored tables). Do not offline-filter at `0.40`.
|
|
105
|
+
- Run `bg_subpixel_moire_score` on **native-resolution** images (do **not** downscale via `fit_image` beforehand; `moire_threshold=2.0` is scale-dependent).
|
|
106
|
+
- `apply_lpf_upscale` converts text crops to grayscale (`tables` & `formulas` stay untouched); on colored text over iso-luminant colored paper, pass `moire_threshold=1e9` or `stretch=False` (`lpf_stretch=False`).
|
|
107
|
+
- Pass `polygon_px_size` with `polygon_px` (automatic via `from_paddlex_result`, `from_hf_detections`, `attach_polygons_to_regions`); `polygon_px_size=None` trusts `polygon_px` as-is for legacy callers.
|
|
108
|
+
- **Label contract:** `from_paddlex_result`/`from_hf_detections` drop unknown and `abandon` classes (matching upstream `PP-DocLayoutV3`), whereas `load_layout_regions(..., fmt="regions")` and `prepare_page_crops` skip `skip`/`abandon` and default unknown custom labels to `"text"`.
|
|
109
|
+
- **Repetition retries & benchmark setting:** `ocr_page_crops(..., retry_repetitive=False)` defaults to opt-in retries (`max_tokens=16384` default); pass `retry_repetitive=True` or CLI `--retry-repetitive` to enable repetition-collapse retries. Note that the `unseen_298` benchmark ran both baseline and `Pass1_Lite` arms with upstream `--retry-repetitive` (upstream `repetition_guard`).
|
|
110
|
+
- Optional upstream integration tests accept `XIAOMI_OCR_REPO` (checkout dir) and `PASS1_LITE_HIST_FILE` (`twostage_enhancements.py` path).
|
|
111
|
+
|
|
112
|
+
### Repository Layout
|
|
113
|
+
- `src/pass1_lite/`: `core.py` (geometry/mask/LPF/order), `adapters.py` (PaddleX/HF/OTSL/visuals), `client.py` (stdlib OpenAI/vLLM client), `cli.py` (`pass1-lite`).
|
|
114
|
+
- `upstream_pr/`: Standalone minimal PR patches ([`0001`](upstream_pr/0001-paddlex-preserve-polygon.patch), [`0002`](upstream_pr/0002-hf-preserve-polygon-and-docs.patch), [`PR_DESCRIPTION.md`](upstream_pr/PR_DESCRIPTION.md)).
|
|
115
|
+
- `report/`: Audit ledger ([`retrospective.md`](report/retrospective.md), [`results.csv`](report/results.csv), [`pages.csv`](report/pages.csv)) — excluded from PyPI builds.
|
|
116
|
+
- `assets/`, `examples/`, `tests/`: Benchmark summary chart, real-dataset before/after comparisons ([`assets/ASSETS-LICENSE.md`](assets/ASSETS-LICENSE.md)), runnable scripts, and 22 unit/integration/PR tests.
|
|
117
|
+
|
|
118
|
+
</details>
|
|
119
|
+
|
|
120
|
+
## License & Notice
|
|
121
|
+
|
|
122
|
+
Source code is licensed under Apache-2.0 ([`LICENSE`](LICENSE) · [`NOTICE`](NOTICE)). PyPI wheel/sdist packages contain only Apache-2.0 code and the original numeric benchmark chart (`assets/benchmark_unseen298.png`); see [`assets/ASSETS-LICENSE.md`](assets/ASSETS-LICENSE.md) for the non-Apache research-commentary terms and takedown contact covering `assets/showcase_before_after*.png`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Pass1_Lite
|
|
2
|
+
|
|
3
|
+
**Drop-in crop refinement between your layout detector and OCR VLM.**
|
|
4
|
+
Cuts real-world text edit distance from **`0.0519` to `0.0403` (`-22.4%` relative, `+0.48/100` Real5 overall; `-41.9%` on Skew, `-28.0%` on Screen photos)** with **zero retraining**, **zero PyTorch**, and **≈1.00× runtime (`0.9986×` All6 / `1.0047×` Real5)**.
|
|
5
|
+
|
|
6
|
+
[GitHub Repository & Visual Before/After Showcase](https://github.com/wangsenning/pass1-lite#readme) · [简体中文文档](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/README_zh.md) · [Full Statistical Audit](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/report/retrospective.md) · [Upstream PR Patches](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/upstream_pr/PR_DESCRIPTION.md)
|
|
7
|
+
|
|
8
|
+
## Why Pass1_Lite?
|
|
9
|
+
|
|
10
|
+
Two-stage document OCR (`Layout Detector → Crop → VLM`) loses accuracy in the wild for three simple, fixable reasons:
|
|
11
|
+
|
|
12
|
+
1. **Skewed crops pull in neighbor text** — Axis-aligned boxes absorb adjacent headings, columns, and captions. `Pass1_Lite` masks exterior pixels using a `+4 px` dilated polygon filled with **local 85th-percentile paper luminance** (no clipped strokes, no harsh gray seams).
|
|
13
|
+
2. **Phone photos of screens break VLM vision encoders** — LCD RGB subpixel moiré scrambles digits and small words. `Pass1_Lite` auto-detects subpixel chroma oscillation on native pages and applies **text-only luminance LPF + `2×` upscaling** (tables & formulas stay untouched; `<0.9%` of Clean regions (5/298 pages)).
|
|
14
|
+
3. **Detectors invert vertical order inside columns** — `Pass1_Lite` runs a deterministic, idempotent same-column order repair pass before Markdown assembly.
|
|
15
|
+
|
|
16
|
+
> **Why not full-page deskew or raw `crop(bbox)`?** Two-pass deskew regresses Clean (`-0.33`) and Scanning (`-0.60`) while adding `+3.6%` latency; raw `crop(bbox)` or 0 px hard-white/gray masks leave neighbor bleed, clipped strokes, or unmitigated screen moiré. `Pass1_Lite` is the zero-regression middle layer verified on 1,788 blind images.
|
|
17
|
+
>
|
|
18
|
+
> **Lightweight & honest scope:** Only `numpy`, `opencv-python-headless`, and `pillow` (zero `torch`). All benchmark gains below were measured on **`Xiaomi-OCR-0 (0.8B)` + `PaddleX PP-DocLayoutV3`**; the Python/CLI adapters also accept `HuggingFace` / custom JSON layouts and any OpenAI-compatible VLM endpoint (`vLLM`, `Qwen-VL`, etc.) via `--preset generic` *(gains on other VLMs have not been benchmarked here)*.
|
|
19
|
+
|
|
20
|
+
## 30-Second Quickstart
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pass1-lite
|
|
24
|
+
|
|
25
|
+
# 1. Try instantly with zero GPU / zero models (generates side-by-side comparison.png)
|
|
26
|
+
pass1-lite demo --out-dir ./demo_out
|
|
27
|
+
|
|
28
|
+
# 2. Diagnose LCD moire & EXIF rotation risks on any real photo
|
|
29
|
+
pass1-lite inspect ./scan.jpg
|
|
30
|
+
|
|
31
|
+
# 3. End-to-end two-stage OCR -> Markdown (PaddleX -> Pass1_Lite -> vLLM)
|
|
32
|
+
pass1-lite ocr ./pages/ --paddlex \
|
|
33
|
+
--vllm-url http://127.0.0.1:8000/v1 --model Xiaomi-OCR-0 \
|
|
34
|
+
--out-dir ./md_out --save-visual --resume
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Python API (6 Lines, Zero Glue Code)
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from pass1_lite import from_paddlex_result, load_image_rgb, ocr_page_crops, prepare_page_crops
|
|
41
|
+
|
|
42
|
+
img = load_image_rgb("page.jpg")
|
|
43
|
+
regions = from_paddlex_result(paddlex_pred, *img.size, table_threshold=0.25) # or from_hf_detections(...)
|
|
44
|
+
bundle = prepare_page_crops(img, regions)
|
|
45
|
+
markdown, _ = ocr_page_crops(bundle, base_url="http://127.0.0.1:8000/v1", model="Xiaomi-OCR-0")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Benchmark (`298` Held-Out Docs × `6` Domains = `1,788` Images)
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
| Pipeline | Clean | Screen | Skew | Warping | Real5 Overall | Real5 Text Error ↓ | All6 Runtime |
|
|
53
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
54
|
+
| Standard Baseline (`official_base`) | `95.62` | `94.19` | `92.10` | `95.25` | `94.47` | `0.0519` | `1.000×` |
|
|
55
|
+
| **`Pass1_Lite` (Single-Pass Default)** | **`95.63`** | **`94.80`** | `93.47` | **`95.52`** | `94.95` (`+0.48`) | `0.0403` (`-22.4%`) | **`0.9986×`** |
|
|
56
|
+
| Two-Pass Full-Page Deskew (`sysfix_v1`) | `95.29` (`-0.33`) | **`94.80`** | **`95.73`** | `94.99` (`-0.26`) | **`95.17`** | **`0.0388`** | `1.036×` |
|
|
57
|
+
|
|
58
|
+
*Best value(s) per column are **bolded**. `Pass1_Lite` row reports the GPU-verified `v0.2` default (`Real5=94.9491`, `Skew=93.4685`, `Warping=95.5222`); the pre-registered frozen run (`fill_ratio_mode="frozen_unclipped"`) scored `Real5=94.9424` (`Skew=93.4812`, `Warping=95.4761`; paired `text_ED` diff `0.0000`, `p=0.71`).*
|
|
59
|
+
|
|
60
|
+
- **Safe production default:** Statistically significant text error reduction in **6/6 domains (`p ≤ 0.039`)** with **0 domain regressions** (Clean `+0.01`, Real5 text ED `0.0519 → 0.0403` / `-22.4%`, `+0.48/100` overall, `181` docs improved / `21` worse / `68` tied), at **≈1.00× runtime** (`0.9986×` All6, `1.0047×` Real5; `3.6%` faster than two-pass deskew).
|
|
61
|
+
- **Honest scope:** Statistically significant gains are in **text (`p < 0.001`)** and **reading order (`p < 0.001`)**. Table (`p=0.89`) and formula (`p=0.33`) deltas vs baseline are not statistically significant. Against two-pass deskew, `Pass1_Lite` missed pre-registered non-inferiority (`G4 FAIL`, `-0.22` Real5 overall) because severe skew formulas still favor full-page rotation (`cdm_pg 96.24` vs `90.97`), at the cost of Clean (`-0.33`), Warping (`-0.26`), and Scanning (`-0.60`) regressions.
|
|
62
|
+
|
|
63
|
+
See the [GitHub repository](https://github.com/wangsenning/pass1-lite#readme) for real-dataset before/after visual comparisons, full statistical audit (`G1–G4`, pretraining overlap disclosure, `v0.2` GPU parity), CLI guardrails, and standalone upstream PR patches.
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
Apache-2.0 ([`LICENSE`](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/LICENSE) · [`NOTICE`](https://github.com/wangsenning/pass1-lite/blob/v0.2.0/NOTICE)). PyPI wheel and sdist packages contain pure Apache-2.0 code and the original numeric benchmark chart only (zero dataset images or benchmark page-ID manifests).
|