doctr-synth-generator 0.4.0__tar.gz → 0.5.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.
- doctr_synth_generator-0.5.0/PKG-INFO +482 -0
- doctr_synth_generator-0.5.0/README.md +231 -0
- doctr_synth_generator-0.5.0/doctr_synth_generator.egg-info/PKG-INFO +482 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/doctr_synth_generator.egg-info/SOURCES.txt +19 -1
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/doctr_synth_generator.egg-info/requires.txt +3 -1
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/__init__.py +0 -1
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/__main__.py +17 -1
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/__init__.py +17 -2
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/background_downloader.py +8 -1
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/background_manager.py +38 -4
- doctr_synth_generator-0.5.0/generator/components/capture.py +311 -0
- doctr_synth_generator-0.5.0/generator/components/config.py +615 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/corpus_downloader.py +122 -6
- doctr_synth_generator-0.5.0/generator/components/designs.py +213 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/font_downloader.py +99 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/font_selector.py +74 -4
- doctr_synth_generator-0.5.0/generator/components/generator.py +274 -0
- doctr_synth_generator-0.5.0/generator/components/legibility.py +107 -0
- doctr_synth_generator-0.5.0/generator/components/media.py +177 -0
- doctr_synth_generator-0.5.0/generator/components/page_generator.py +2233 -0
- doctr_synth_generator-0.5.0/generator/components/scan.py +100 -0
- doctr_synth_generator-0.5.0/generator/components/shaping.py +108 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/text_renderer.py +8 -1
- doctr_synth_generator-0.5.0/generator/components/text_styling.py +253 -0
- doctr_synth_generator-0.5.0/generator/components/textures.py +242 -0
- doctr_synth_generator-0.5.0/generator/components/token_sampler.py +86 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/vocab_coverage.py +107 -8
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/vocabs.py +181 -150
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/dataset_generator.py +31 -6
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/doctr_dataset.py +11 -98
- doctr_synth_generator-0.5.0/generator/recipes/__init__.py +9 -0
- doctr_synth_generator-0.5.0/generator/recipes/corpus.py +325 -0
- doctr_synth_generator-0.5.0/generator/recipes/detection.py +640 -0
- doctr_synth_generator-0.5.0/generator/recipes/fonts.py +452 -0
- doctr_synth_generator-0.5.0/generator/recipes/languages.py +200 -0
- doctr_synth_generator-0.5.0/generator/recipes/preview.py +99 -0
- doctr_synth_generator-0.5.0/generator/recipes/recognition.py +767 -0
- doctr_synth_generator-0.5.0/generator/recipes/render.py +144 -0
- doctr_synth_generator-0.5.0/generator/recipes/text.py +338 -0
- doctr_synth_generator-0.5.0/generator/version.py +1 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/pyproject.toml +9 -5
- doctr_synth_generator-0.5.0/scripts/build_multilingual_detection.py +77 -0
- doctr_synth_generator-0.5.0/scripts/build_multilingual_recognition.py +87 -0
- doctr_synth_generator-0.5.0/scripts/generate_grid.py +309 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/setup.py +1 -1
- doctr_synth_generator-0.4.0/PKG-INFO +0 -777
- doctr_synth_generator-0.4.0/README.md +0 -528
- doctr_synth_generator-0.4.0/doctr_synth_generator.egg-info/PKG-INFO +0 -777
- doctr_synth_generator-0.4.0/generator/components/config.py +0 -324
- doctr_synth_generator-0.4.0/generator/components/generator.py +0 -172
- doctr_synth_generator-0.4.0/generator/components/latex_generator.py +0 -145
- doctr_synth_generator-0.4.0/generator/components/page_generator.py +0 -637
- doctr_synth_generator-0.4.0/generator/components/text_styling.py +0 -118
- doctr_synth_generator-0.4.0/generator/version.py +0 -1
- doctr_synth_generator-0.4.0/scripts/generate_grid.py +0 -185
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/LICENSE +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/doctr_synth_generator.egg-info/dependency_links.txt +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/doctr_synth_generator.egg-info/entry_points.txt +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/doctr_synth_generator.egg-info/top_level.txt +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/doctr_synth_generator.egg-info/zip-safe +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/api.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/__init__.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/augmentation_pipeline.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/random_blur.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/random_gaussian_noise.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/random_jpeg_compression.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/random_perspective.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/random_pixel_dropout.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/augmentations/random_rotate.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/dataset_balancer.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/generator/components/dataset_splitter.py +0 -0
- {doctr_synth_generator-0.4.0 → doctr_synth_generator-0.5.0}/setup.cfg +0 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: doctr-synth-generator
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: A synthetic data generator for training OCR models
|
|
5
|
+
Author-email: Felix Dittrich <felixdittrich92@gmail.com>
|
|
6
|
+
Maintainer: Felix Dittrich
|
|
7
|
+
License: Apache License
|
|
8
|
+
Version 2.0, January 2004
|
|
9
|
+
http://www.apache.org/licenses/
|
|
10
|
+
|
|
11
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
12
|
+
|
|
13
|
+
1. Definitions.
|
|
14
|
+
|
|
15
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
16
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
17
|
+
|
|
18
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
19
|
+
the copyright owner that is granting the License.
|
|
20
|
+
|
|
21
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
22
|
+
other entities that control, are controlled by, or are under common
|
|
23
|
+
control with that entity. For the purposes of this definition,
|
|
24
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
25
|
+
direction or management of such entity, whether by contract or
|
|
26
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
27
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
28
|
+
|
|
29
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
30
|
+
exercising permissions granted by this License.
|
|
31
|
+
|
|
32
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
33
|
+
including but not limited to software source code, documentation
|
|
34
|
+
source, and configuration files.
|
|
35
|
+
|
|
36
|
+
"Object" form shall mean any form resulting from mechanical
|
|
37
|
+
transformation or translation of a Source form, including but
|
|
38
|
+
not limited to compiled object code, generated documentation,
|
|
39
|
+
and conversions to other media types.
|
|
40
|
+
|
|
41
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
42
|
+
Object form, made available under the License, as indicated by a
|
|
43
|
+
copyright notice that is included in or attached to the work
|
|
44
|
+
(an example is provided in the Appendix below).
|
|
45
|
+
|
|
46
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
47
|
+
form, that is based on (or derived from) the Work and for which the
|
|
48
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
49
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
50
|
+
of this License, Derivative Works shall not include works that remain
|
|
51
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
52
|
+
the Work and Derivative Works thereof.
|
|
53
|
+
|
|
54
|
+
"Contribution" shall mean any work of authorship, including
|
|
55
|
+
the original version of the Work and any modifications or additions
|
|
56
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
57
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
58
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
59
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
60
|
+
means any form of electronic, verbal, or written communication sent
|
|
61
|
+
to the Licensor or its representatives, including but not limited to
|
|
62
|
+
communication on electronic mailing lists, source code control systems,
|
|
63
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
64
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
65
|
+
excluding communication that is conspicuously marked or otherwise
|
|
66
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
67
|
+
|
|
68
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
69
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
70
|
+
subsequently incorporated within the Work.
|
|
71
|
+
|
|
72
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
73
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
74
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
75
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
76
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
77
|
+
Work and such Derivative Works in Source or Object form.
|
|
78
|
+
|
|
79
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
80
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
81
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
82
|
+
(except as stated in this section) patent license to make, have made,
|
|
83
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
84
|
+
where such license applies only to those patent claims licensable
|
|
85
|
+
by such Contributor that are necessarily infringed by their
|
|
86
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
87
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
88
|
+
institute patent litigation against any entity (including a
|
|
89
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
90
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
91
|
+
or contributory patent infringement, then any patent licenses
|
|
92
|
+
granted to You under this License for that Work shall terminate
|
|
93
|
+
as of the date such litigation is filed.
|
|
94
|
+
|
|
95
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
96
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
97
|
+
modifications, and in Source or Object form, provided that You
|
|
98
|
+
meet the following conditions:
|
|
99
|
+
|
|
100
|
+
(a) You must give any other recipients of the Work or
|
|
101
|
+
Derivative Works a copy of this License; and
|
|
102
|
+
|
|
103
|
+
(b) You must cause any modified files to carry prominent notices
|
|
104
|
+
stating that You changed the files; and
|
|
105
|
+
|
|
106
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
107
|
+
that You distribute, all copyright, patent, trademark, and
|
|
108
|
+
attribution notices from the Source form of the Work,
|
|
109
|
+
excluding those notices that do not pertain to any part of
|
|
110
|
+
the Derivative Works; and
|
|
111
|
+
|
|
112
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
113
|
+
distribution, then any Derivative Works that You distribute must
|
|
114
|
+
include a readable copy of the attribution notices contained
|
|
115
|
+
within such NOTICE file, excluding those notices that do not
|
|
116
|
+
pertain to any part of the Derivative Works, in at least one
|
|
117
|
+
of the following places: within a NOTICE text file distributed
|
|
118
|
+
as part of the Derivative Works; within the Source form or
|
|
119
|
+
documentation, if provided along with the Derivative Works; or,
|
|
120
|
+
within a display generated by the Derivative Works, if and
|
|
121
|
+
wherever such third-party notices normally appear. The contents
|
|
122
|
+
of the NOTICE file are for informational purposes only and
|
|
123
|
+
do not modify the License. You may add Your own attribution
|
|
124
|
+
notices within Derivative Works that You distribute, alongside
|
|
125
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
126
|
+
that such additional attribution notices cannot be construed
|
|
127
|
+
as modifying the License.
|
|
128
|
+
|
|
129
|
+
You may add Your own copyright statement to Your modifications and
|
|
130
|
+
may provide additional or different license terms and conditions
|
|
131
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
132
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
133
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
134
|
+
the conditions stated in this License.
|
|
135
|
+
|
|
136
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
137
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
138
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
139
|
+
this License, without any additional terms or conditions.
|
|
140
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
141
|
+
the terms of any separate license agreement you may have executed
|
|
142
|
+
with Licensor regarding such Contributions.
|
|
143
|
+
|
|
144
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
145
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
146
|
+
except as required for reasonable and customary use in describing the
|
|
147
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
148
|
+
|
|
149
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
150
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
151
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
152
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
153
|
+
implied, including, without limitation, any warranties or conditions
|
|
154
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
155
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
156
|
+
appropriateness of using or redistributing the Work and assume any
|
|
157
|
+
risks associated with Your exercise of permissions under this License.
|
|
158
|
+
|
|
159
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
160
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
161
|
+
unless required by applicable law (such as deliberate and grossly
|
|
162
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
163
|
+
liable to You for damages, including any direct, indirect, special,
|
|
164
|
+
incidental, or consequential damages of any character arising as a
|
|
165
|
+
result of this License or out of the use or inability to use the
|
|
166
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
167
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
168
|
+
other commercial damages or losses), even if such Contributor
|
|
169
|
+
has been advised of the possibility of such damages.
|
|
170
|
+
|
|
171
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
172
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
173
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
174
|
+
or other liability obligations and/or rights consistent with this
|
|
175
|
+
License. However, in accepting such obligations, You may act only
|
|
176
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
177
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
178
|
+
defend, and hold each Contributor harmless for any liability
|
|
179
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
180
|
+
of your accepting any such warranty or additional liability.
|
|
181
|
+
|
|
182
|
+
END OF TERMS AND CONDITIONS
|
|
183
|
+
|
|
184
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
185
|
+
|
|
186
|
+
To apply the Apache License to your work, attach the following
|
|
187
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
188
|
+
replaced with your own identifying information. (Don't include
|
|
189
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
190
|
+
comment syntax for the file format. We also recommend that a
|
|
191
|
+
file or class name and description of purpose be included on the
|
|
192
|
+
same "printed page" as the copyright notice for easier
|
|
193
|
+
identification within third-party archives.
|
|
194
|
+
|
|
195
|
+
Copyright [yyyy] [name of copyright owner]
|
|
196
|
+
|
|
197
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
198
|
+
you may not use this file except in compliance with the License.
|
|
199
|
+
You may obtain a copy of the License at
|
|
200
|
+
|
|
201
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
202
|
+
|
|
203
|
+
Unless required by applicable law or agreed to in writing, software
|
|
204
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
205
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
206
|
+
See the License for the specific language governing permissions and
|
|
207
|
+
limitations under the License.
|
|
208
|
+
|
|
209
|
+
Project-URL: repository, https://github.com/felixdittrich92/docTR-Synth-Generator
|
|
210
|
+
Project-URL: tracker, https://github.com/felixdittrich92/docTR-Synth-Generator/issues
|
|
211
|
+
Project-URL: changelog, https://github.com/felixdittrich92/docTR-Synth-Generator/releases
|
|
212
|
+
Keywords: OCR,deep learning,computer vision,text recognition,synthetic data,data augmentation,image processing
|
|
213
|
+
Classifier: Development Status :: 4 - Beta
|
|
214
|
+
Classifier: Intended Audience :: Developers
|
|
215
|
+
Classifier: Intended Audience :: Education
|
|
216
|
+
Classifier: Intended Audience :: Science/Research
|
|
217
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
218
|
+
Classifier: Natural Language :: English
|
|
219
|
+
Classifier: Operating System :: OS Independent
|
|
220
|
+
Classifier: Programming Language :: Python :: 3
|
|
221
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
222
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
223
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
224
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
225
|
+
Requires-Python: <4,>=3.11.0
|
|
226
|
+
Description-Content-Type: text/markdown
|
|
227
|
+
License-File: LICENSE
|
|
228
|
+
Requires-Dist: fonttools<5.0.0,>=4.50.0
|
|
229
|
+
Requires-Dist: numpy<3.0.0,>=2.0.0
|
|
230
|
+
Requires-Dist: Pillow>=11.0.0
|
|
231
|
+
Requires-Dist: uharfbuzz>=0.39.0
|
|
232
|
+
Provides-Extra: testing
|
|
233
|
+
Requires-Dist: pytest>=5.3.2; extra == "testing"
|
|
234
|
+
Requires-Dist: coverage[toml]>=4.5.4; extra == "testing"
|
|
235
|
+
Provides-Extra: quality
|
|
236
|
+
Requires-Dist: ruff>=0.1.5; extra == "quality"
|
|
237
|
+
Requires-Dist: mypy>=0.812; extra == "quality"
|
|
238
|
+
Requires-Dist: pre-commit>=2.17.0; extra == "quality"
|
|
239
|
+
Provides-Extra: dev
|
|
240
|
+
Requires-Dist: fonttools<5.0.0,>=4.50.0; extra == "dev"
|
|
241
|
+
Requires-Dist: numpy<3.0.0,>=2.0.0; extra == "dev"
|
|
242
|
+
Requires-Dist: Pillow>=11.0.0; extra == "dev"
|
|
243
|
+
Requires-Dist: uharfbuzz>=0.39.0; extra == "dev"
|
|
244
|
+
Requires-Dist: pytest>=5.3.2; extra == "dev"
|
|
245
|
+
Requires-Dist: coverage[toml]>=4.5.4; extra == "dev"
|
|
246
|
+
Requires-Dist: ruff>=0.1.5; extra == "dev"
|
|
247
|
+
Requires-Dist: mypy>=0.812; extra == "dev"
|
|
248
|
+
Requires-Dist: pre-commit>=2.17.0; extra == "dev"
|
|
249
|
+
Requires-Dist: python-doctr>=1.1.0; extra == "dev"
|
|
250
|
+
Dynamic: license-file
|
|
251
|
+
|
|
252
|
+
[](LICENSE)
|
|
253
|
+

|
|
254
|
+
[](https://codecov.io/gh/felixdittrich92/docTR-Synth-Generator)
|
|
255
|
+
[](https://www.codefactor.io/repository/github/felixdittrich92/doctr-synth-generator)
|
|
256
|
+
[](https://pypi.org/project/docTR-Synth-Generator/)
|
|
257
|
+
|
|
258
|
+
# docTR-Synth-Generator
|
|
259
|
+
|
|
260
|
+
Synthetic training data for [docTR](https://github.com/mindee/doctr): word crops for
|
|
261
|
+
**text recognition** and full document pages with word polygons for **text detection**,
|
|
262
|
+
in ~100 languages and 24 scripts.
|
|
263
|
+
|
|
264
|
+

|
|
265
|
+
|
|
266
|
+
- **Zero-config** - real words, matching fonts and paper backgrounds are downloaded and cached on first use.
|
|
267
|
+
- **Labels that match the pixels** - every word is shaped with HarfBuzz before a font is used for it, so no
|
|
268
|
+
crop shows a tofu box, a dotted circle or an empty glyph its label doesn't mention.
|
|
269
|
+
- **Complete vocab coverage** - every character of the docTR vocab you train on appears in train *and* val.
|
|
270
|
+
- **Realistic documents** - paragraphs, newspapers, forms, tables, receipts, ID cards and vertical CJK text
|
|
271
|
+
on real paper sizes and on generated magazine-style designs, with photos, stamps, handwriting, barcodes
|
|
272
|
+
and punch holes; folded or crumpled;
|
|
273
|
+
scanned in colour, grayscale or black-and-white, or photographed on tablecloths and tables (bent sheets,
|
|
274
|
+
perspective, uneven light, shadows, colour casts).
|
|
275
|
+
- **Hard negatives** - unlabelled show-through from the back of the sheet, and pages with no text at all
|
|
276
|
+
(creased blank paper, fabric, wood, empty forms, graphics), so a detector learns what is *not* text.
|
|
277
|
+
- **Crops like a detector cuts them** - recognition crops carry real margins and the cut-off edges of
|
|
278
|
+
neighbouring lines and table rules, as crops from real pages do.
|
|
279
|
+
- **docTR-ready** - writes the folder layout docTR's training scripts read, or plugs into them on the fly.
|
|
280
|
+
|
|
281
|
+
## Installation
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
pip install doctr-synth-generator
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Arabic, Hebrew and the Indic and South-East Asian scripts need a Pillow build with **libraqm**
|
|
288
|
+
(`python -c "from PIL import features; print(features.check('raqm'))"` must print `True`).
|
|
289
|
+
On Debian/Ubuntu: `apt install libraqm0 libfribidi0`.
|
|
290
|
+
|
|
291
|
+
## Quickstart
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from generator import generate_dataset
|
|
295
|
+
|
|
296
|
+
# 10k recognition crops (English by default)
|
|
297
|
+
generate_dataset("rec_dataset", num_images=10_000)
|
|
298
|
+
|
|
299
|
+
# several languages - words, fonts and shaping are resolved per language code
|
|
300
|
+
generate_dataset("rec_dataset", num_images=10_000, languages=["en", "de", "ru", "ar", "hi"])
|
|
301
|
+
|
|
302
|
+
# 2k detection pages
|
|
303
|
+
generate_dataset("det_dataset", num_images=2_000, task="detection", languages=["en", "de"])
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The same from the command line:
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
doctr-synth rec_dataset -n 10000 -l en de ru ar hi
|
|
310
|
+
doctr-synth det_dataset -n 2000 -t detection -l en de --layout form
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Each split is written as `images/` + `labels.json` in docTR's format, so it trains as is:
|
|
314
|
+
`--train_path rec_dataset/train --val_path rec_dataset/val`.
|
|
315
|
+
|
|
316
|
+
## Configuration
|
|
317
|
+
|
|
318
|
+
Every keyword of `generate_dataset()` is a configuration option. For full control build the
|
|
319
|
+
config yourself - flat names are routed into the right sub-config:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
from generator import GenerationConfig, SyntheticDatasetGenerator
|
|
323
|
+
|
|
324
|
+
cfg = GenerationConfig.flat(
|
|
325
|
+
output_dir="det_dataset",
|
|
326
|
+
task="detection",
|
|
327
|
+
num_images=5_000,
|
|
328
|
+
languages=["en", "fr"],
|
|
329
|
+
det_layout="newspaper",
|
|
330
|
+
capture_prob=0.5,
|
|
331
|
+
output_jpeg=True,
|
|
332
|
+
num_workers=8,
|
|
333
|
+
)
|
|
334
|
+
SyntheticDatasetGenerator(cfg).generate_dataset()
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
The options you are most likely to change:
|
|
338
|
+
|
|
339
|
+
| Option | Default | What it does |
|
|
340
|
+
| --- | --- | --- |
|
|
341
|
+
| `task` | `"recognition"` | `"recognition"` crops or `"detection"` pages |
|
|
342
|
+
| `num_images` / `val_percent` | `1000` / `0.2` | total samples and the validation **fraction** (`0.15`, not `15`) |
|
|
343
|
+
| `languages` | `["en"]` | ISO 639-1 codes; select words, fonts and script shaping |
|
|
344
|
+
| `target_vocab` | `None` | recognition: restrict labels to a docTR `VOCABS` key or list, e.g. `["german", "urdu"]` |
|
|
345
|
+
| `num_workers` / `output_jpeg` | `4` / `False` | parallel processes, JPEG instead of PNG |
|
|
346
|
+
| `font_size_range` | `(12, 40)` | recognition: crop text size in pixels |
|
|
347
|
+
| `det_layout` | `"mixed"` | `paragraph`, `newspaper`, `form`, `id_card`, `vertical`, `table`, `receipt` or `mixed` |
|
|
348
|
+
| `det_vertical_prob` | `0.2` | chance a horizontal page also carries vertical text |
|
|
349
|
+
| `det_partial_page_prob` | `0.25` | chance a page ends part-way down, like the last page of a letter |
|
|
350
|
+
| `det_furniture_prob` | `0.3` | headers, page numbers, stamps, logos, barcodes, signatures |
|
|
351
|
+
| `det_handwriting_prob` | `0.35` | chance a form or receipt value is hand-written |
|
|
352
|
+
| `det_picture_prob` | `0.3` | chance a paragraph or newspaper page carries a photo with a caption |
|
|
353
|
+
| `det_crease_prob` | `0.2` | chance a sheet is folded or crumpled (receipts more often) |
|
|
354
|
+
| `det_bleed_through_prob` | `0.25` | chance the back side shows through as light, unlabelled text |
|
|
355
|
+
| `capture_prob` | `0.35` | chance a page is photographed (perspective, shadow, lighting) rather than scanned |
|
|
356
|
+
| `capture_curl_prob` | `0.6` | chance a photographed sheet is bent, so its text lines bow |
|
|
357
|
+
| `capture_textured_surface_prob` | `0.65` | chance a photographed sheet lies on fabric, wood or crumpled paper |
|
|
358
|
+
| `grayscale_prob` / `bitonal_prob` | `0.3` / `0.08` | crops and pages delivered in grayscale or black-and-white (fax, copier, scanner apps) |
|
|
359
|
+
| `context_prob` | `0.35` | recognition: crop margins show cut-off neighbouring lines or table rules |
|
|
360
|
+
| `media_dpi_range` | `(150, 300)` | scan resolution of the physical page |
|
|
361
|
+
| `min_local_contrast` | `30.0` | recognition: re-draw a crop until every part of the word is readable |
|
|
362
|
+
| `language_balance` | `"balanced"` | `"balanced"` or `"proportional"` split across languages |
|
|
363
|
+
| `procedural_bg_prob` | `0.3` | share of generated magazine/brochure/poster backgrounds (colour fields, gradients, sidebars, halftone, artwork) |
|
|
364
|
+
| `wordlist_path` / `font_dir` / `bg_image_dir` | `None` | use your own words, fonts or backgrounds instead of the downloads |
|
|
365
|
+
|
|
366
|
+
All options are documented in [`generator/components/config.py`](generator/components/config.py);
|
|
367
|
+
any field there works as a flat keyword (detection fields take a `det_` prefix, capture `capture_`,
|
|
368
|
+
media `media_`).
|
|
369
|
+
|
|
370
|
+
## Large-scale datasets
|
|
371
|
+
|
|
372
|
+
For millions of samples use the recipes. They build datasets in resumable shards, vet every
|
|
373
|
+
font, and guarantee vocab coverage:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
# recognition - Latin, Cyrillic and Greek (66 languages)
|
|
377
|
+
python -m generator.recipes.recognition prepare --languages european --out european_rec
|
|
378
|
+
python -m generator.recipes.recognition preview --out european_rec # look before you render
|
|
379
|
+
python -m generator.recipes.recognition render --out european_rec # resumable
|
|
380
|
+
python -m generator.recipes.recognition verify --out european_rec # every vocab character rendered?
|
|
381
|
+
|
|
382
|
+
# detection - pages in ~100 languages
|
|
383
|
+
python -m generator.recipes.detection prepare --languages all --out multilingual_det
|
|
384
|
+
python -m generator.recipes.detection render --out multilingual_det
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Or run a ready-made build end to end (resumable; extra recipe options are passed through):
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
python scripts/build_multilingual_detection.py --out multilingual_det # ~120k pages, 99 languages (~31 GB)
|
|
391
|
+
python scripts/build_multilingual_recognition.py --out multilingual_rec # 1.2M crops, 96 languages, no zh/ja/ko
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
`--languages` takes `european`, `multilingual` (every non-CJK vocab: 96 languages) or `all`, or
|
|
395
|
+
codes such as `de,fr,ru`. `--num-train`, `--num-val` and `--min-char-count` set the size and the
|
|
396
|
+
per-character floor (`--min-char-count-large`, default `50`, for the thousands of CJK ideographs and Hangul
|
|
397
|
+
syllables). Recognition: `--handwriting-share` (default `0.05`) writes crops in one of ~40
|
|
398
|
+
handwriting faces (Latin, Cyrillic, Greek, Arabic, Hebrew, Thai, Indic, CJK, Korean). Detection:
|
|
399
|
+
`--density` (`mixed` by default: 55% letters, 30% reports, 15% broadsheet-dense pages with up to ~2500
|
|
400
|
+
words), `--negative-share` (default `0.05`, pages without text) and `--input-size` (default `1024`, the
|
|
401
|
+
docTR `--input_size` you train at: every word stays at least 5-6 px tall there). Train with docTR as usual:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
python references/recognition/train.py crnn_vgg16_bn --train_path european_rec/train --val_path european_rec/val ...
|
|
405
|
+
python references/detection/train.py db_resnet50 --train_path multilingual_det/train --val_path multilingual_det/val --rotation ...
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Pass `--rotation` for detection: photographed and skewed pages carry rotated polygons, and without it
|
|
409
|
+
docTR turns them into loose straight boxes. To learn really dense newspapers, render with
|
|
410
|
+
`--input-size 1536` and train with `--input_size 1536`: the same legibility floor then admits finer print.
|
|
411
|
+
|
|
412
|
+
Each `shard_XXXX/` folder under `train/` is picked up by docTR's recognition script. The model vocab
|
|
413
|
+
is written to `meta/vocab.txt`: add it to docTR's `VOCABS` under a name and pass that name as `--vocab`.
|
|
414
|
+
How the recipes keep each image and its label in agreement:
|
|
415
|
+
|
|
416
|
+
- The model vocab is what the vetted fonts can actually draw; anything else is reported in
|
|
417
|
+
`meta/vocab_dropped.json` instead of becoming a class no image contains.
|
|
418
|
+
- A font is used for a language only if it draws every letter that occurs in that language.
|
|
419
|
+
- Every vocab character reaches at least `--min-char-count` train labels (default 1000) - real words
|
|
420
|
+
first, symbols in real contexts (`R&D`, `25°C`, `C:\Users`), synthetic tokens only as a fallback.
|
|
421
|
+
- `verify` recounts the labels that were actually written, and `topup` renders whatever is short.
|
|
422
|
+
- Validation shares no word with training, and words that look identical in another script
|
|
423
|
+
(Cyrillic `се` vs Latin `ce`) are left out.
|
|
424
|
+
|
|
425
|
+
## Train on the fly
|
|
426
|
+
|
|
427
|
+
Skip the disk entirely: `build_recognition_datasets` / `build_detection_datasets` return PyTorch
|
|
428
|
+
datasets that render a fresh sample on every access and drop into docTR's training scripts in
|
|
429
|
+
place of `RecognitionDataset` / `DetectionDataset`:
|
|
430
|
+
|
|
431
|
+
```python
|
|
432
|
+
from generator import GenerationConfig, build_recognition_datasets, synth_worker_init_fn
|
|
433
|
+
|
|
434
|
+
cfg = GenerationConfig.flat(task="recognition", num_images=100_000, val_percent=0.1)
|
|
435
|
+
train_set, val_set = build_recognition_datasets(cfg, vocab="french", img_transforms=img_transforms)
|
|
436
|
+
|
|
437
|
+
train_loader = DataLoader(
|
|
438
|
+
train_set,
|
|
439
|
+
batch_size=64,
|
|
440
|
+
shuffle=True,
|
|
441
|
+
num_workers=8,
|
|
442
|
+
collate_fn=train_set.collate_fn,
|
|
443
|
+
worker_init_fn=synth_worker_init_fn,
|
|
444
|
+
)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
Pass the vocab your model trains on: every label is restricted to it. For detection use
|
|
448
|
+
`build_detection_datasets(cfg, languages=["en", "de"], use_polygons=True)`. Requires PyTorch
|
|
449
|
+
(`pip install python-doctr`).
|
|
450
|
+
|
|
451
|
+
## Development
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
pip install -e ".[dev]"
|
|
455
|
+
make test # offline test suite + coverage
|
|
456
|
+
make quality # ruff + mypy
|
|
457
|
+
make style # format and auto-fix
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
To regenerate the image at the top, prepare one detection and one recognition build and run
|
|
461
|
+
`python scripts/generate_grid.py --det <det build> --rec <rec build> -o docs/examples.jpg` (both built with `--languages all`).
|
|
462
|
+
|
|
463
|
+
## Citation
|
|
464
|
+
|
|
465
|
+
```bibtex
|
|
466
|
+
@misc{docTR-Synth-Generator,
|
|
467
|
+
title={docTR-Synth-Generator: A tool to generate synthetic OCR text datasets - made for docTR},
|
|
468
|
+
author={{Dittrich, Felix}},
|
|
469
|
+
year={2026},
|
|
470
|
+
publisher = {GitHub},
|
|
471
|
+
howpublished = {\url{https://github.com/felixdittrich92/docTR-Synth-Generator}}
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
Word lists come from [FrequencyWords](https://github.com/hermitdave/FrequencyWords) and
|
|
476
|
+
[most-common-words-multilingual](https://github.com/frekwencja/most-common-words-multilingual), fonts
|
|
477
|
+
from [Google Fonts](https://fonts.google.com) and the [fonts_v1](https://github.com/felixdittrich92/docTR-Synth-Generator/releases/download/v0.0.1/fonts_v1.zip)
|
|
478
|
+
release; please respect their licenses when redistributing generated datasets.
|
|
479
|
+
|
|
480
|
+
## License
|
|
481
|
+
|
|
482
|
+
Distributed under the Apache 2.0 License. See [`LICENSE`](LICENSE) for more information.
|