onnxtr 0.1.0__py3-none-any.whl

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.
Files changed (70) hide show
  1. onnxtr/__init__.py +2 -0
  2. onnxtr/contrib/__init__.py +0 -0
  3. onnxtr/contrib/artefacts.py +131 -0
  4. onnxtr/contrib/base.py +105 -0
  5. onnxtr/file_utils.py +33 -0
  6. onnxtr/io/__init__.py +5 -0
  7. onnxtr/io/elements.py +455 -0
  8. onnxtr/io/html.py +28 -0
  9. onnxtr/io/image.py +56 -0
  10. onnxtr/io/pdf.py +42 -0
  11. onnxtr/io/reader.py +85 -0
  12. onnxtr/models/__init__.py +4 -0
  13. onnxtr/models/_utils.py +141 -0
  14. onnxtr/models/builder.py +355 -0
  15. onnxtr/models/classification/__init__.py +2 -0
  16. onnxtr/models/classification/models/__init__.py +1 -0
  17. onnxtr/models/classification/models/mobilenet.py +120 -0
  18. onnxtr/models/classification/predictor/__init__.py +1 -0
  19. onnxtr/models/classification/predictor/base.py +57 -0
  20. onnxtr/models/classification/zoo.py +76 -0
  21. onnxtr/models/detection/__init__.py +2 -0
  22. onnxtr/models/detection/core.py +101 -0
  23. onnxtr/models/detection/models/__init__.py +3 -0
  24. onnxtr/models/detection/models/differentiable_binarization.py +159 -0
  25. onnxtr/models/detection/models/fast.py +160 -0
  26. onnxtr/models/detection/models/linknet.py +160 -0
  27. onnxtr/models/detection/postprocessor/__init__.py +0 -0
  28. onnxtr/models/detection/postprocessor/base.py +144 -0
  29. onnxtr/models/detection/predictor/__init__.py +1 -0
  30. onnxtr/models/detection/predictor/base.py +54 -0
  31. onnxtr/models/detection/zoo.py +73 -0
  32. onnxtr/models/engine.py +50 -0
  33. onnxtr/models/predictor/__init__.py +1 -0
  34. onnxtr/models/predictor/base.py +175 -0
  35. onnxtr/models/predictor/predictor.py +145 -0
  36. onnxtr/models/preprocessor/__init__.py +1 -0
  37. onnxtr/models/preprocessor/base.py +118 -0
  38. onnxtr/models/recognition/__init__.py +2 -0
  39. onnxtr/models/recognition/core.py +28 -0
  40. onnxtr/models/recognition/models/__init__.py +5 -0
  41. onnxtr/models/recognition/models/crnn.py +226 -0
  42. onnxtr/models/recognition/models/master.py +145 -0
  43. onnxtr/models/recognition/models/parseq.py +134 -0
  44. onnxtr/models/recognition/models/sar.py +134 -0
  45. onnxtr/models/recognition/models/vitstr.py +166 -0
  46. onnxtr/models/recognition/predictor/__init__.py +1 -0
  47. onnxtr/models/recognition/predictor/_utils.py +86 -0
  48. onnxtr/models/recognition/predictor/base.py +79 -0
  49. onnxtr/models/recognition/utils.py +89 -0
  50. onnxtr/models/recognition/zoo.py +69 -0
  51. onnxtr/models/zoo.py +114 -0
  52. onnxtr/transforms/__init__.py +1 -0
  53. onnxtr/transforms/base.py +112 -0
  54. onnxtr/utils/__init__.py +4 -0
  55. onnxtr/utils/common_types.py +18 -0
  56. onnxtr/utils/data.py +126 -0
  57. onnxtr/utils/fonts.py +41 -0
  58. onnxtr/utils/geometry.py +498 -0
  59. onnxtr/utils/multithreading.py +50 -0
  60. onnxtr/utils/reconstitution.py +70 -0
  61. onnxtr/utils/repr.py +64 -0
  62. onnxtr/utils/visualization.py +291 -0
  63. onnxtr/utils/vocabs.py +71 -0
  64. onnxtr/version.py +1 -0
  65. onnxtr-0.1.0.dist-info/LICENSE +201 -0
  66. onnxtr-0.1.0.dist-info/METADATA +481 -0
  67. onnxtr-0.1.0.dist-info/RECORD +70 -0
  68. onnxtr-0.1.0.dist-info/WHEEL +5 -0
  69. onnxtr-0.1.0.dist-info/top_level.txt +2 -0
  70. onnxtr-0.1.0.dist-info/zip-safe +1 -0
@@ -0,0 +1,481 @@
1
+ Metadata-Version: 2.1
2
+ Name: onnxtr
3
+ Version: 0.1.0
4
+ Summary: Onnx Text Recognition (OnnxTR): docTR Onnx-Wrapper for high-performance OCR on documents.
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/OnnxTR
210
+ Project-URL: tracker, https://github.com/felixdittrich92/OnnxTR/issues
211
+ Project-URL: changelog, https://github.com/felixdittrich92/OnnxTR/releases
212
+ Keywords: OCR,deep learning,computer vision,onnx,text detection,text recognition,docTR,document analysis,document 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.9
222
+ Classifier: Programming Language :: Python :: 3.10
223
+ Classifier: Programming Language :: Python :: 3.11
224
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
225
+ Requires-Python: <4,>=3.9.0
226
+ Description-Content-Type: text/markdown
227
+ License-File: LICENSE
228
+ Requires-Dist: numpy <2.0.0,>=1.16.0
229
+ Requires-Dist: scipy <2.0.0,>=1.4.0
230
+ Requires-Dist: onnx <2.0.0,>=1.12.0
231
+ Requires-Dist: onnxruntime >=1.11.0
232
+ Requires-Dist: opencv-python <5.0.0,>=4.5.0
233
+ Requires-Dist: pypdfium2 <5.0.0,>=4.0.0
234
+ Requires-Dist: pyclipper <2.0.0,>=1.2.0
235
+ Requires-Dist: shapely <3.0.0,>=1.6.0
236
+ Requires-Dist: rapidfuzz <4.0.0,>=3.0.0
237
+ Requires-Dist: langdetect <2.0.0,>=1.0.9
238
+ Requires-Dist: Pillow >=9.2.0
239
+ Requires-Dist: defusedxml >=0.7.0
240
+ Requires-Dist: anyascii >=0.3.2
241
+ Requires-Dist: tqdm >=4.30.0
242
+ Provides-Extra: dev
243
+ Requires-Dist: weasyprint >=55.0 ; extra == 'dev'
244
+ Requires-Dist: matplotlib >=3.1.0 ; extra == 'dev'
245
+ Requires-Dist: mplcursors >=0.3 ; extra == 'dev'
246
+ Requires-Dist: pytest >=5.3.2 ; extra == 'dev'
247
+ Requires-Dist: coverage[toml] >=4.5.4 ; extra == 'dev'
248
+ Requires-Dist: requests >=2.20.0 ; extra == 'dev'
249
+ Requires-Dist: ruff >=0.1.5 ; extra == 'dev'
250
+ Requires-Dist: mypy >=0.812 ; extra == 'dev'
251
+ Requires-Dist: pre-commit >=2.17.0 ; extra == 'dev'
252
+ Provides-Extra: gpu
253
+ Requires-Dist: onnxruntime-gpu >=1.11.0 ; extra == 'gpu'
254
+ Provides-Extra: html
255
+ Requires-Dist: weasyprint >=55.0 ; extra == 'html'
256
+ Provides-Extra: quality
257
+ Requires-Dist: ruff >=0.1.5 ; extra == 'quality'
258
+ Requires-Dist: mypy >=0.812 ; extra == 'quality'
259
+ Requires-Dist: pre-commit >=2.17.0 ; extra == 'quality'
260
+ Provides-Extra: testing
261
+ Requires-Dist: pytest >=5.3.2 ; extra == 'testing'
262
+ Requires-Dist: coverage[toml] >=4.5.4 ; extra == 'testing'
263
+ Requires-Dist: requests >=2.20.0 ; extra == 'testing'
264
+ Provides-Extra: viz
265
+ Requires-Dist: matplotlib >=3.1.0 ; extra == 'viz'
266
+ Requires-Dist: mplcursors >=0.3 ; extra == 'viz'
267
+
268
+ <p align="center">
269
+ <img src="https://github.com/felixdittrich92/OnnxTR/raw/main/docs/images/logo.jpg" width="40%">
270
+ </p>
271
+
272
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
273
+ ![Build Status](https://github.com/felixdittrich92/onnxtr/workflows/builds/badge.svg)
274
+ [![codecov](https://codecov.io/gh/felixdittrich92/OnnxTR/graph/badge.svg?token=WVFRCQBOLI)](https://codecov.io/gh/felixdittrich92/OnnxTR)
275
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4fff4d764bb14fb8b4f4afeb9587231b)](https://app.codacy.com/gh/felixdittrich92/OnnxTR/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
276
+ [![CodeFactor](https://www.codefactor.io/repository/github/felixdittrich92/onnxtr/badge)](https://www.codefactor.io/repository/github/felixdittrich92/onnxtr)
277
+ [![Pypi](https://img.shields.io/badge/pypi-v0.0.1-blue.svg)](https://pypi.org/project/OnnxTR/)
278
+
279
+ > :warning: Please note that this is wrapper around the [doctr](https://github.com/mindee/doctr) library to provide a Onnx pipeline for docTR. For feature requests, which are not directly related to the Onnx pipeline, please refer to the base project.
280
+
281
+ **Optical Character Recognition made seamless & accessible to anyone, powered by Onnx**
282
+
283
+ What you can expect from this repository:
284
+
285
+ - efficient ways to parse textual information (localize and identify each word) from your documents
286
+ - a Onnx pipeline for docTR, a wrapper around the [doctr](https://github.com/mindee/doctr) library
287
+ - more lightweight package with faster inference latency and less required resources
288
+
289
+ ![OCR_example](https://github.com/felixdittrich92/OnnxTR/raw/main/docs/images/ocr.png)
290
+
291
+ ## Installation
292
+
293
+ ### Prerequisites
294
+
295
+ Python 3.9 (or higher) and [pip](https://pip.pypa.io/en/stable/) are required to install OnnxTR.
296
+
297
+ ### Latest release
298
+
299
+ You can then install the latest release of the package using [pypi](https://pypi.org/project/OnnxTR/) as follows:
300
+
301
+ **NOTE:** For GPU support please take a look at: [ONNX Runtime](https://onnxruntime.ai/getting-started). Currently supported execution providers by default are: CPU, CUDA
302
+
303
+ ```shell
304
+ pip install OnnxTR
305
+ # with gpu support
306
+ pip install "OnnxTR[gpu]"
307
+ # with HTML support
308
+ pip install "OnnxTR[html]"
309
+ # with support for visualization
310
+ pip install "OnnxTR[viz]"
311
+ # with support for all dependencies
312
+ pip install "OnnxTR[html, gpu, viz]"
313
+ ```
314
+
315
+ ### Reading files
316
+
317
+ Documents can be interpreted from PDF / Images / Webpages / Multiple page images using the following code snippet:
318
+
319
+ ```python
320
+ from onnxtr.io import DocumentFile
321
+ # PDF
322
+ pdf_doc = DocumentFile.from_pdf("path/to/your/doc.pdf")
323
+ # Image
324
+ single_img_doc = DocumentFile.from_images("path/to/your/img.jpg")
325
+ # Webpage (requires `weasyprint` to be installed)
326
+ webpage_doc = DocumentFile.from_url("https://www.yoursite.com")
327
+ # Multiple page images
328
+ multi_img_doc = DocumentFile.from_images(["path/to/page1.jpg", "path/to/page2.jpg"])
329
+ ```
330
+
331
+ ### Putting it together
332
+
333
+ Let's use the default pretrained model for an example:
334
+
335
+ ```python
336
+ from onnxtr.io import DocumentFile
337
+ from onnxtr.models import ocr_predictor
338
+
339
+ model = ocr_predictor(
340
+ det_arch='fast_base', # detection architecture
341
+ rec_arch='vitstr_base', # recognition architecture
342
+ det_bs=4, # detection batch size
343
+ reco_bs=1024, # recognition batch size
344
+ assume_straight_pages=True, # set to `False` if the pages are not straight (rotation, perspective, etc.) (default: True)
345
+ straighten_pages=False, # set to `True` if the pages should be straightened before final processing (default: False)
346
+ preserve_aspect_ratio=True, # set to `False` if the aspect ratio should not be preserved (default: True)
347
+ symmetric_pad=True, # set to `False` to disable symmetric padding (default: True)
348
+ # DocumentBuilder specific parameters
349
+ resolve_lines=True, # whether words should be automatically grouped into lines (default: True)
350
+ resolve_blocks=True, # whether lines should be automatically grouped into blocks (default: True)
351
+ paragraph_break=0.035, # relative length of the minimum space separating paragraphs (default: 0.035)
352
+ )
353
+ # PDF
354
+ doc = DocumentFile.from_pdf("path/to/your/doc.pdf")
355
+ # Analyze
356
+ result = model(doc)
357
+ # Display the result (requires matplotlib & mplcursors to be installed)
358
+ result.show()
359
+ ```
360
+
361
+ ![Visualization sample](https://github.com/felixdittrich92/OnnxTR/raw/main/docs/images/doctr_example_script.gif)
362
+
363
+ Or even rebuild the original document from its predictions:
364
+
365
+ ```python
366
+ import matplotlib.pyplot as plt
367
+
368
+ synthetic_pages = result.synthesize()
369
+ plt.imshow(synthetic_pages[0]); plt.axis('off'); plt.show()
370
+ ```
371
+
372
+ ![Synthesis sample](https://github.com/felixdittrich92/OnnxTR/raw/main/docs/images/synthesized_sample.png)
373
+
374
+ The `ocr_predictor` returns a `Document` object with a nested structure (with `Page`, `Block`, `Line`, `Word`, `Artefact`).
375
+ To get a better understanding of the document model, check out [documentation](https://mindee.github.io/doctr/modules/io.html#document-structure):
376
+
377
+ You can also export them as a nested dict, more appropriate for JSON format / render it or export as XML (hocr format):
378
+
379
+ ```python
380
+ json_output = result.export() # nested dict
381
+ text_output = result.render() # human-readable text
382
+ xml_output = result.export_as_xml() # hocr format
383
+ for output in xml_output:
384
+ xml_bytes_string = output[0]
385
+ xml_element = output[1]
386
+
387
+ ```
388
+
389
+ ## Loading custom exported models
390
+
391
+ You can also load docTR custom exported models:
392
+ For exporting please take a look at the [doctr documentation](https://mindee.github.io/doctr/using_doctr/using_model_export.html#export-to-onnx).
393
+
394
+ ```python
395
+ from onnxtr.models import ocr_predictor, linknet_resnet18, parseq
396
+
397
+ reco_model = parseq("path_to_custom_model.onnx", vocab="ABC")
398
+ det_model = linknet_resnet18("path_to_custom_model.onnx")
399
+ model = ocr_predictor(det_model=det_model, reco_model=reco_model)
400
+ ```
401
+
402
+ ## Models architectures
403
+
404
+ Credits where it's due: this repository is implementing, among others, architectures from published research papers.
405
+
406
+ ### Text Detection
407
+
408
+ - DBNet: [Real-time Scene Text Detection with Differentiable Binarization](https://arxiv.org/pdf/1911.08947.pdf).
409
+ - LinkNet: [LinkNet: Exploiting Encoder Representations for Efficient Semantic Segmentation](https://arxiv.org/pdf/1707.03718.pdf)
410
+ - FAST: [FAST: Faster Arbitrarily-Shaped Text Detector with Minimalist Kernel Representation](https://arxiv.org/pdf/2111.02394.pdf)
411
+
412
+ ### Text Recognition
413
+
414
+ - CRNN: [An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition](https://arxiv.org/pdf/1507.05717.pdf).
415
+ - SAR: [Show, Attend and Read:A Simple and Strong Baseline for Irregular Text Recognition](https://arxiv.org/pdf/1811.00751.pdf).
416
+ - MASTER: [MASTER: Multi-Aspect Non-local Network for Scene Text Recognition](https://arxiv.org/pdf/1910.02562.pdf).
417
+ - ViTSTR: [Vision Transformer for Fast and Efficient Scene Text Recognition](https://arxiv.org/pdf/2105.08582.pdf).
418
+ - PARSeq: [Scene Text Recognition with Permuted Autoregressive Sequence Models](https://arxiv.org/pdf/2207.06966).
419
+
420
+ ```python
421
+ predictor = ocr_predictor()
422
+ predictor.list_archs()
423
+ {
424
+ 'detection archs':
425
+ [
426
+ 'db_resnet34',
427
+ 'db_resnet50',
428
+ 'db_mobilenet_v3_large',
429
+ 'linknet_resnet18',
430
+ 'linknet_resnet34',
431
+ 'linknet_resnet50',
432
+ 'fast_tiny',
433
+ 'fast_small',
434
+ 'fast_base'
435
+ ],
436
+ 'recognition archs':
437
+ [
438
+ 'crnn_vgg16_bn',
439
+ 'crnn_mobilenet_v3_small',
440
+ 'crnn_mobilenet_v3_large',
441
+ 'sar_resnet31',
442
+ 'master',
443
+ 'vitstr_small',
444
+ 'vitstr_base',
445
+ 'parseq'
446
+ ]
447
+ }
448
+ ```
449
+
450
+ ### Documentation
451
+
452
+ This repository is in sync with the [doctr](https://github.com/mindee/doctr) library, which provides a high-level API to perform OCR on documents.
453
+ This repository stays up-to-date with the latest features and improvements from the base project.
454
+ So we can refer to the [doctr documentation](https://mindee.github.io/doctr/) for more detailed information.
455
+
456
+ NOTE:
457
+
458
+ - `pretrained` is the default in OnnxTR, and not available as a parameter.
459
+ - docTR specific environment variables (e.g.: DOCTR_CACHE_DIR -> ONNXTR_CACHE_DIR) needs to be replaced with `ONNXTR_` prefix.
460
+
461
+ ### Benchmarks
462
+
463
+ COMING SOON
464
+
465
+ ## Citation
466
+
467
+ If you wish to cite please refer to the base project citation, feel free to use this [BibTeX](http://www.bibtex.org/) reference:
468
+
469
+ ```bibtex
470
+ @misc{doctr2021,
471
+ title={docTR: Document Text Recognition},
472
+ author={Mindee},
473
+ year={2021},
474
+ publisher = {GitHub},
475
+ howpublished = {\url{https://github.com/mindee/doctr}}
476
+ }
477
+ ```
478
+
479
+ ## License
480
+
481
+ Distributed under the Apache 2.0 License. See [`LICENSE`](https://github.com/felixdittrich92/OnnxTR?tab=Apache-2.0-1-ov-file#readme) for more information.
@@ -0,0 +1,70 @@
1
+ onnxtr/__init__.py,sha256=h7Wc2tuHLsaoCk5xNpEFEK-g11A6SJA7nAasA76TQ_Y,100
2
+ onnxtr/file_utils.py,sha256=WjUKalEdR53aoeIY4e-ihy3r7J_C9qFxL40JHGPfutc,1107
3
+ onnxtr/version.py,sha256=wC2oqFtrOUdONUyrZY5FqyMyRDiF3ryABp7mW73C87o,23
4
+ onnxtr/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ onnxtr/contrib/artefacts.py,sha256=tdmfhvfXVRYEH7uj4_hqf2cuUGoTieyNK8bXsD3zHwo,5383
6
+ onnxtr/contrib/base.py,sha256=PoCKtOIgj7u4xl-V0eBVh-QmVeTyk_eEggFHQ8R34AI,3445
7
+ onnxtr/io/__init__.py,sha256=kS7tKGFvzxOCWBOun-Y8n9CsziwRKNynjwpZEUUI03M,106
8
+ onnxtr/io/elements.py,sha256=Gm_rNVUhRNMAJFhiw-DejbG6-AXCoCcTyZAoYeTpfW4,16994
9
+ onnxtr/io/html.py,sha256=Em_7PjZ56SugJ9bjjcWLCMVe5ee6uUMKeZovNxJFAXw,737
10
+ onnxtr/io/image.py,sha256=4tLTh2bGdA0ohh3a6mV6xD0KqNOtIVi5lJ06XSmeyMI,1759
11
+ onnxtr/io/pdf.py,sha256=6ETj8qnUmRLeHP32m0lMJ8EwCaZVEtRoweFGx4Qkrbg,1339
12
+ onnxtr/io/reader.py,sha256=BA7DPhW-Gkmce_ZfzrOl4H3pSXVy2JBeQEuY3pWrBFg,2852
13
+ onnxtr/models/__init__.py,sha256=CzdiA34zjFq4a22XvgzG_Bojosi9aN5jeRCizRyh_7o,101
14
+ onnxtr/models/_utils.py,sha256=RnSmj70gFU9CCJlsCYiVULEs7L8MhogkLf2Xu_7wBhM,4824
15
+ onnxtr/models/builder.py,sha256=byUpCs9x5RS2lqNXLECR5GELqd1yF-MEg_09OGWj20Q,13642
16
+ onnxtr/models/engine.py,sha256=2SwzcWCf2s4ti1mHqLF0lqLDw3wpM9FYjdEdtK5MYJ4,2140
17
+ onnxtr/models/zoo.py,sha256=FTG6KCv-4G90N-m0fZhRDOFiyd_sFzLZuBw4bg2ecvI,4302
18
+ onnxtr/models/classification/__init__.py,sha256=h1bZs55iLJBMATtzS4ntTKwfD6OGXBiiqGv_hEnOFnE,41
19
+ onnxtr/models/classification/zoo.py,sha256=yiDTEZCHLBu6WUwQVnQipKhjngPs6OgTeNt4MX8z9m4,2748
20
+ onnxtr/models/classification/models/__init__.py,sha256=rohbM6ZQslfYchi7feZwwh-sX3XXRUhgtEJQeurAytQ,24
21
+ onnxtr/models/classification/models/mobilenet.py,sha256=9SzYYpn1XOUFHZHzKM0BtvSh08WXeAhMeebt3E1eAmQ,3677
22
+ onnxtr/models/classification/predictor/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
23
+ onnxtr/models/classification/predictor/base.py,sha256=9-5i1Uj0EdNQBeSOhaQjGz78Gr0IAr3JZhoKVMA_il4,2009
24
+ onnxtr/models/detection/__init__.py,sha256=h1bZs55iLJBMATtzS4ntTKwfD6OGXBiiqGv_hEnOFnE,41
25
+ onnxtr/models/detection/core.py,sha256=ZmVDHLJ1l4LQ8rFSKc7enXDkGcOWrcQv4H0SJWyLsag,3584
26
+ onnxtr/models/detection/zoo.py,sha256=GfwvVAT3bbx-1zccqDO-jzOzzL5Sj3D06zbd_x6dUOo,2257
27
+ onnxtr/models/detection/models/__init__.py,sha256=6Ea6knYrVCR2jAmPlsVWmCdHe-c6lSRETSAuZGfhx8I,85
28
+ onnxtr/models/detection/models/differentiable_binarization.py,sha256=fu1Mn8i38vIyW98YKdPnwXRcvk_-OlkOmcez7wef8l4,5157
29
+ onnxtr/models/detection/models/fast.py,sha256=40P_q5TWUnY9iIyi-pAqnvauQ5KeqIAco2NGGF4plrg,5101
30
+ onnxtr/models/detection/models/linknet.py,sha256=e9uZZB5S3GYImGroHyZ4oonb_ULxL0VAXd_yDuqG1K0,5194
31
+ onnxtr/models/detection/postprocessor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
+ onnxtr/models/detection/postprocessor/base.py,sha256=U8FgqveZt2qPHI0aUnIEeX370zGUEWUxL6EPqhFZnRI,5714
33
+ onnxtr/models/detection/predictor/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
34
+ onnxtr/models/detection/predictor/base.py,sha256=K0fSTFnA8-fGL9F3HzW3nqnEqO5YKbhFf2TvpUOe_Tw,1744
35
+ onnxtr/models/predictor/__init__.py,sha256=XL25XkRkgyK7mldF-CWhg2MMakSdP5vLpDLwL59hphk,25
36
+ onnxtr/models/predictor/base.py,sha256=nrIE6rvxA3LbeUbQ-e3wkochO66OJT3BP-NW_OyHUyw,7555
37
+ onnxtr/models/predictor/predictor.py,sha256=sfwqRzabqavlI6ty_Z6jGm64olmmQBLQGU39_nulQZs,6045
38
+ onnxtr/models/preprocessor/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
39
+ onnxtr/models/preprocessor/base.py,sha256=f0t0rMCzvuxwgq7jlKvcVWyjeDOx7yCLUw52quEaETM,3990
40
+ onnxtr/models/recognition/__init__.py,sha256=h1bZs55iLJBMATtzS4ntTKwfD6OGXBiiqGv_hEnOFnE,41
41
+ onnxtr/models/recognition/core.py,sha256=0Q1dVXqRcDUr_ycT5tpoSH9-zuDF58GtnmxWpUS8Ibo,739
42
+ onnxtr/models/recognition/utils.py,sha256=04abbjx-_OuF5iEANWIAOK3tQQl1tExPmBQx4IG04Lc,3569
43
+ onnxtr/models/recognition/zoo.py,sha256=FC8kHSr66s5D-Ltb8dnNI-x3HLdy5LZhZeiWMV69J9k,2115
44
+ onnxtr/models/recognition/models/__init__.py,sha256=IXfiuzzkft8O1CpBZWYTpFw19y49mt5rJ_iGSdaWiU0,105
45
+ onnxtr/models/recognition/models/crnn.py,sha256=Y1lmvCAN_r-ciZNHRIZWHLhv60j2zcR1XoRC5r8_BD0,7375
46
+ onnxtr/models/recognition/models/master.py,sha256=4FiWWBtezb7WjhDvnzauZ-iL6_rKashoqbs-9JfHlvM,4009
47
+ onnxtr/models/recognition/models/parseq.py,sha256=qYtXWC8jXnIKViKTLp-WvcEOoU_DPkZ-_KHVhoKgUmw,3765
48
+ onnxtr/models/recognition/models/sar.py,sha256=c0hRZ5dXl9sijkXZXtUnu9cB4DjUFc1MMzriDBhor78,3815
49
+ onnxtr/models/recognition/models/vitstr.py,sha256=jID2RJs5O81b4jBGjkeSNPQ2PTbon-_U8ZDGfCoGcwY,4880
50
+ onnxtr/models/recognition/predictor/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
51
+ onnxtr/models/recognition/predictor/_utils.py,sha256=ZNm5I7ibiWfTlz302uiifCkUOu65YWa-oUBUMPrrUuQ,3406
52
+ onnxtr/models/recognition/predictor/base.py,sha256=YvqSNEM3rCEttxl6hsC9zl1R97N9zO2WZfD5_-nfkR0,2483
53
+ onnxtr/transforms/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
54
+ onnxtr/transforms/base.py,sha256=KohBfq5qNkw9aznZtlGlphNlfKSRBhm5An6TcUiFA7M,3965
55
+ onnxtr/utils/__init__.py,sha256=pESRJKtcQyjRxiMgZPhtPYeLbCj-YSGyMVRHTbcMONU,94
56
+ onnxtr/utils/common_types.py,sha256=eC_NyIwbo9qVF33LiNPqHKfyabWq9mYEKD9gAloo5UU,601
57
+ onnxtr/utils/data.py,sha256=Dh0mgeHJhyPwmm63J90uDVmIYbrp63hh1_SnYLnpgJI,4354
58
+ onnxtr/utils/fonts.py,sha256=OiOHFwkjN4L7QBrzMi7Ex7qj_KcTEJ1sHEJWSfiGNZU,1281
59
+ onnxtr/utils/geometry.py,sha256=PX3e5Cjmb3huwhj2qoMII-8mCxjfWLVzR4O3kSzOdXA,17002
60
+ onnxtr/utils/multithreading.py,sha256=30T7AylM3rb52ZEI3Pk1pfB0VYraTbc7yO2vNODVVFY,2011
61
+ onnxtr/utils/reconstitution.py,sha256=Hx1_ddLevKLzuxXc19UelPdsGlAwqi4f6vRSYKHDUB4,2617
62
+ onnxtr/utils/repr.py,sha256=kfbjGL6KymGT8spo2UL4FJXZ0XRwa7CO7Y1dTVR8dIk,2129
63
+ onnxtr/utils/visualization.py,sha256=CX09qvDnNIw3BFW5F3jM4R9OcpLWAeZyoDyTAOGRvls,9925
64
+ onnxtr/utils/vocabs.py,sha256=SCQ4XQjbHSxunj1tg2iHRiPfE8OaTAMhcJbKq5BNvFs,3138
65
+ onnxtr-0.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
66
+ onnxtr-0.1.0.dist-info/METADATA,sha256=k4DicngL3zLNaAWV2yRaF82MbJ6XdpAh9D3X0OWBS3Y,24645
67
+ onnxtr-0.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
68
+ onnxtr-0.1.0.dist-info/top_level.txt,sha256=48aR9EH095hmgye7CNuxAW3o_cj4TjhWmuw3jEMdTs0,12
69
+ onnxtr-0.1.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
70
+ onnxtr-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ docs
2
+ onnxtr
@@ -0,0 +1 @@
1
+