onnxtr 0.7.1__py3-none-any.whl → 0.8.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.
- onnxtr/models/_utils.py +2 -2
- onnxtr/models/detection/core.py +1 -1
- onnxtr/models/engine.py +19 -5
- onnxtr/models/recognition/models/crnn.py +3 -3
- onnxtr/utils/vocabs.py +0 -2
- onnxtr/version.py +1 -1
- {onnxtr-0.7.1.dist-info → onnxtr-0.8.0.dist-info}/METADATA +31 -3
- {onnxtr-0.7.1.dist-info → onnxtr-0.8.0.dist-info}/RECORD +12 -12
- {onnxtr-0.7.1.dist-info → onnxtr-0.8.0.dist-info}/WHEEL +0 -0
- {onnxtr-0.7.1.dist-info → onnxtr-0.8.0.dist-info}/licenses/LICENSE +0 -0
- {onnxtr-0.7.1.dist-info → onnxtr-0.8.0.dist-info}/top_level.txt +0 -0
- {onnxtr-0.7.1.dist-info → onnxtr-0.8.0.dist-info}/zip-safe +0 -0
onnxtr/models/_utils.py
CHANGED
|
@@ -62,7 +62,7 @@ def estimate_orientation(
|
|
|
62
62
|
thresh = img.astype(np.uint8)
|
|
63
63
|
|
|
64
64
|
page_orientation, orientation_confidence = general_page_orientation or (None, 0.0)
|
|
65
|
-
if page_orientation and orientation_confidence >= min_confidence:
|
|
65
|
+
if page_orientation is not None and orientation_confidence >= min_confidence:
|
|
66
66
|
# We rotate the image to the general orientation which improves the detection
|
|
67
67
|
# No expand needed bitmap is already padded
|
|
68
68
|
thresh = rotate_image(thresh, -page_orientation)
|
|
@@ -99,7 +99,7 @@ def estimate_orientation(
|
|
|
99
99
|
estimated_angle = -round(median) if abs(median) != 0 else 0
|
|
100
100
|
|
|
101
101
|
# combine with the general orientation and the estimated angle
|
|
102
|
-
if page_orientation and orientation_confidence >= min_confidence:
|
|
102
|
+
if page_orientation is not None and orientation_confidence >= min_confidence:
|
|
103
103
|
# special case where the estimated angle is mostly wrong:
|
|
104
104
|
# case 1: - and + swapped
|
|
105
105
|
# case 2: estimated angle is completely wrong
|
onnxtr/models/detection/core.py
CHANGED
|
@@ -53,7 +53,7 @@ class DetectionPostProcessor(NestedObject):
|
|
|
53
53
|
|
|
54
54
|
else:
|
|
55
55
|
mask: np.ndarray = np.zeros((h, w), np.int32)
|
|
56
|
-
cv2.fillPoly(mask, [points.astype(np.int32)], 1.0)
|
|
56
|
+
cv2.fillPoly(mask, [points.astype(np.int32)], 1.0)
|
|
57
57
|
product = pred * mask
|
|
58
58
|
return np.sum(product) / np.count_nonzero(product)
|
|
59
59
|
|
onnxtr/models/engine.py
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
|
-
from
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from typing import Any, TypeAlias
|
|
9
10
|
|
|
10
11
|
import numpy as np
|
|
11
12
|
from onnxruntime import (
|
|
12
13
|
ExecutionMode,
|
|
13
14
|
GraphOptimizationLevel,
|
|
14
15
|
InferenceSession,
|
|
16
|
+
RunOptions,
|
|
15
17
|
SessionOptions,
|
|
16
18
|
get_available_providers,
|
|
17
19
|
get_device,
|
|
@@ -23,7 +25,9 @@ set_default_logger_severity(int(os.getenv("ORT_LOG_SEVERITY_LEVEL", 4)))
|
|
|
23
25
|
from onnxtr.utils.data import download_from_url
|
|
24
26
|
from onnxtr.utils.geometry import shape_translate
|
|
25
27
|
|
|
26
|
-
__all__ = ["EngineConfig"]
|
|
28
|
+
__all__ = ["EngineConfig", "RunOptionsProvider"]
|
|
29
|
+
|
|
30
|
+
RunOptionsProvider: TypeAlias = Callable[[RunOptions], RunOptions]
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
class EngineConfig:
|
|
@@ -38,9 +42,11 @@ class EngineConfig:
|
|
|
38
42
|
self,
|
|
39
43
|
providers: list[tuple[str, dict[str, Any]]] | list[str] | None = None,
|
|
40
44
|
session_options: SessionOptions | None = None,
|
|
45
|
+
run_options_provider: RunOptionsProvider | None = None,
|
|
41
46
|
):
|
|
42
47
|
self._providers = providers or self._init_providers()
|
|
43
48
|
self._session_options = session_options or self._init_sess_opts()
|
|
49
|
+
self.run_options_provider = run_options_provider
|
|
44
50
|
|
|
45
51
|
def _init_providers(self) -> list[tuple[str, dict[str, Any]]]:
|
|
46
52
|
providers: Any = [("CPUExecutionProvider", {"arena_extend_strategy": "kSameAsRequested"})]
|
|
@@ -79,7 +85,7 @@ class EngineConfig:
|
|
|
79
85
|
return self._session_options
|
|
80
86
|
|
|
81
87
|
def __repr__(self) -> str:
|
|
82
|
-
return f"EngineConfig(providers={self.providers}"
|
|
88
|
+
return f"EngineConfig(providers={self.providers})"
|
|
83
89
|
|
|
84
90
|
|
|
85
91
|
class Engine:
|
|
@@ -100,6 +106,7 @@ class Engine:
|
|
|
100
106
|
self.model_path = archive_path
|
|
101
107
|
self.session_options = engine_cfg.session_options
|
|
102
108
|
self.providers = engine_cfg.providers
|
|
109
|
+
self.run_options_provider = engine_cfg.run_options_provider
|
|
103
110
|
self.runtime = InferenceSession(archive_path, providers=self.providers, sess_options=self.session_options)
|
|
104
111
|
self.runtime_inputs = self.runtime.get_inputs()[0]
|
|
105
112
|
self.tf_exported = int(self.runtime_inputs.shape[-1]) == 3
|
|
@@ -109,6 +116,9 @@ class Engine:
|
|
|
109
116
|
self.output_name = [output.name for output in self.runtime.get_outputs()]
|
|
110
117
|
|
|
111
118
|
def run(self, inputs: np.ndarray) -> np.ndarray:
|
|
119
|
+
run_options = RunOptions()
|
|
120
|
+
if self.run_options_provider is not None:
|
|
121
|
+
run_options = self.run_options_provider(run_options)
|
|
112
122
|
if self.tf_exported:
|
|
113
123
|
inputs = shape_translate(inputs, format="BHWC") # sanity check
|
|
114
124
|
else:
|
|
@@ -117,8 +127,12 @@ class Engine:
|
|
|
117
127
|
inputs = np.broadcast_to(inputs, (self.fixed_batch_size, *inputs.shape))
|
|
118
128
|
# combine the results
|
|
119
129
|
logits = np.concatenate(
|
|
120
|
-
[
|
|
130
|
+
[
|
|
131
|
+
self.runtime.run(self.output_name, {self.runtime_inputs.name: batch}, run_options=run_options)[0]
|
|
132
|
+
for batch in inputs
|
|
133
|
+
],
|
|
134
|
+
axis=0,
|
|
121
135
|
)
|
|
122
136
|
else:
|
|
123
|
-
logits = self.runtime.run(self.output_name, {self.runtime_inputs.name: inputs})[0]
|
|
137
|
+
logits = self.runtime.run(self.output_name, {self.runtime_inputs.name: inputs}, run_options=run_options)[0]
|
|
124
138
|
return shape_translate(logits, format="BHWC")
|
|
@@ -22,9 +22,9 @@ default_cfgs: dict[str, dict[str, Any]] = {
|
|
|
22
22
|
"mean": (0.694, 0.695, 0.693),
|
|
23
23
|
"std": (0.299, 0.296, 0.301),
|
|
24
24
|
"input_shape": (3, 32, 128),
|
|
25
|
-
"vocab": VOCABS["
|
|
26
|
-
"url": "https://github.com/felixdittrich92/OnnxTR/releases/download/v0.
|
|
27
|
-
"url_8_bit": "https://github.com/felixdittrich92/OnnxTR/releases/download/v0.1
|
|
25
|
+
"vocab": VOCABS["french"],
|
|
26
|
+
"url": "https://github.com/felixdittrich92/OnnxTR/releases/download/v0.7.1/crnn_vgg16_bn-743599aa.onnx",
|
|
27
|
+
"url_8_bit": "https://github.com/felixdittrich92/OnnxTR/releases/download/v0.7.1/crnn_vgg16_bn_static_8_bit-df1b594d.onnx",
|
|
28
28
|
},
|
|
29
29
|
"crnn_mobilenet_v3_small": {
|
|
30
30
|
"mean": (0.694, 0.695, 0.693),
|
onnxtr/utils/vocabs.py
CHANGED
|
@@ -264,8 +264,6 @@ VOCABS["estonian"] = VOCABS["english"] + "šžõäöüŠŽÕÄÖÜ"
|
|
|
264
264
|
VOCABS["esperanto"] = re.sub(r"[QqWwXxYy]", "", VOCABS["english"]) + "ĉĝĥĵŝŭĈĜĤĴŜŬ" + "₷"
|
|
265
265
|
|
|
266
266
|
VOCABS["french"] = VOCABS["english"] + "àâéèêëîïôùûüçÀÂÉÈÊËÎÏÔÙÛÜÇ"
|
|
267
|
-
# NOTE: legacy french is outdated, but kept for compatibility
|
|
268
|
-
VOCABS["legacy_french"] = VOCABS["latin"] + "°" + "àâéèêëîïôùûçÀÂÉÈËÎÏÔÙÛÇ" + _BASE_VOCABS["currency"]
|
|
269
267
|
|
|
270
268
|
VOCABS["finnish"] = VOCABS["english"] + "äöÄÖ"
|
|
271
269
|
|
onnxtr/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = 'v0.
|
|
1
|
+
__version__ = 'v0.8.0'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: onnxtr
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Onnx Text Recognition (OnnxTR): docTR Onnx-Wrapper for high-performance OCR on documents.
|
|
5
5
|
Author-email: Felix Dittrich <felixdittrich92@gmail.com>
|
|
6
6
|
Maintainer: Felix Dittrich
|
|
@@ -264,6 +264,7 @@ Requires-Dist: pytest>=5.3.2; extra == "testing"
|
|
|
264
264
|
Requires-Dist: coverage[toml]>=4.5.4; extra == "testing"
|
|
265
265
|
Requires-Dist: requests>=2.20.0; extra == "testing"
|
|
266
266
|
Requires-Dist: pytest-memray>=1.7.0; extra == "testing"
|
|
267
|
+
Requires-Dist: psutil>=7.0.0; extra == "testing"
|
|
267
268
|
Provides-Extra: quality
|
|
268
269
|
Requires-Dist: ruff>=0.1.5; extra == "quality"
|
|
269
270
|
Requires-Dist: mypy>=0.812; extra == "quality"
|
|
@@ -278,6 +279,7 @@ Requires-Dist: pytest>=5.3.2; extra == "dev"
|
|
|
278
279
|
Requires-Dist: coverage[toml]>=4.5.4; extra == "dev"
|
|
279
280
|
Requires-Dist: requests>=2.20.0; extra == "dev"
|
|
280
281
|
Requires-Dist: pytest-memray>=1.7.0; extra == "dev"
|
|
282
|
+
Requires-Dist: psutil>=7.0.0; extra == "dev"
|
|
281
283
|
Requires-Dist: ruff>=0.1.5; extra == "dev"
|
|
282
284
|
Requires-Dist: mypy>=0.812; extra == "dev"
|
|
283
285
|
Requires-Dist: pre-commit>=2.17.0; extra == "dev"
|
|
@@ -292,8 +294,8 @@ Dynamic: license-file
|
|
|
292
294
|
[](https://codecov.io/gh/felixdittrich92/OnnxTR)
|
|
293
295
|
[](https://app.codacy.com/gh/felixdittrich92/OnnxTR/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
294
296
|
[](https://www.codefactor.io/repository/github/felixdittrich92/onnxtr)
|
|
295
|
-
[](https://socket.dev/pypi/package/onnxtr/overview/0.8.0/tar-gz)
|
|
298
|
+
[](https://pypi.org/project/OnnxTR/)
|
|
297
299
|
[](https://github.com/felixdittrich92/OnnxTR/pkgs/container/onnxtr)
|
|
298
300
|
[](https://huggingface.co/spaces/Felix92/OnnxTR-OCR)
|
|
299
301
|

|
|
@@ -480,6 +482,32 @@ predictor = ocr_predictor(
|
|
|
480
482
|
)
|
|
481
483
|
```
|
|
482
484
|
|
|
485
|
+
You can also dynamically configure whether the memory arena should shrink:
|
|
486
|
+
|
|
487
|
+
```python
|
|
488
|
+
from random import random
|
|
489
|
+
from onnxruntime import RunOptions, SessionOptions
|
|
490
|
+
|
|
491
|
+
from onnxtr.models import ocr_predictor, EngineConfig
|
|
492
|
+
|
|
493
|
+
def arena_shrinkage_handler(run_options: RunOptions) -> RunOptions:
|
|
494
|
+
"""
|
|
495
|
+
Shrink the memory arena on 10% of inference runs.
|
|
496
|
+
"""
|
|
497
|
+
if random() < 0.1:
|
|
498
|
+
run_options.add_run_config_entry("memory.enable_memory_arena_shrinkage", "cpu:0")
|
|
499
|
+
return run_options
|
|
500
|
+
|
|
501
|
+
engine_config = EngineConfig(run_options_provider=arena_shrinkage_handler)
|
|
502
|
+
engine_config.session_options.enable_mem_pattern = False
|
|
503
|
+
|
|
504
|
+
predictor = ocr_predictor(
|
|
505
|
+
det_engine_cfg=engine_config,
|
|
506
|
+
reco_engine_cfg=engine_config,
|
|
507
|
+
clf_engine_cfg=engine_config
|
|
508
|
+
)
|
|
509
|
+
```
|
|
510
|
+
|
|
483
511
|
</details>
|
|
484
512
|
|
|
485
513
|
## Loading custom exported models
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
onnxtr/__init__.py,sha256=h7Wc2tuHLsaoCk5xNpEFEK-g11A6SJA7nAasA76TQ_Y,100
|
|
2
2
|
onnxtr/file_utils.py,sha256=rlflwU-KTHQ6wD1GU2EqPJs4y7gTyZSUnhtx9w2lIOk,1067
|
|
3
3
|
onnxtr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
onnxtr/version.py,sha256=
|
|
4
|
+
onnxtr/version.py,sha256=XbvKmQHvfaLsOHsQx8r-8Tg2eqiGheb-FcQ7cNGg5ro,23
|
|
5
5
|
onnxtr/contrib/__init__.py,sha256=0Jo052I1DIdbNVYQBg213UJBNH3UKZIOcn2HVusQlj4,39
|
|
6
6
|
onnxtr/contrib/artefacts.py,sha256=4uJyXrl2YEjeWaGC8pAVC5227eVzb34vTSbAe0fzGbw,5323
|
|
7
7
|
onnxtr/contrib/base.py,sha256=SPPWd8SVwZr4kGPI-yM8UdQguEZ0awRBUZGjGKZEC-U,3135
|
|
@@ -12,9 +12,9 @@ onnxtr/io/image.py,sha256=ehOcXzH1eFjwLO3pwiV3bUwGcn4SdW-FO9DVbUjWw2M,1700
|
|
|
12
12
|
onnxtr/io/pdf.py,sha256=cO_e9MWh2uCu20a9eLqp3y3GS9idpROkOuNkCU5yE8U,1327
|
|
13
13
|
onnxtr/io/reader.py,sha256=JBDoGXaQsiV3eZxDu4Sd8aeULIEmLV5oNGqGXLAmtBk,2755
|
|
14
14
|
onnxtr/models/__init__.py,sha256=QTfZlqUyv1d7NUCbGIUFM1DLOOXe-cqHZ7uaKkGdXvk,157
|
|
15
|
-
onnxtr/models/_utils.py,sha256=
|
|
15
|
+
onnxtr/models/_utils.py,sha256=IqXlismua45W3Uo451oVNrnMnUCrxKoRqKJ5TKyypYE,6448
|
|
16
16
|
onnxtr/models/builder.py,sha256=aaMHLZl8fayeWsXHsvSy5Tq2yQWTO0gpj4Ob4kNZ0xk,14076
|
|
17
|
-
onnxtr/models/engine.py,sha256=
|
|
17
|
+
onnxtr/models/engine.py,sha256=FafLMq_qtNqyQSPO-pvYiaX9BM5YINENhQdp02EWpu0,5732
|
|
18
18
|
onnxtr/models/zoo.py,sha256=44H7NfE4DWH7KgmF8vod9fMlPnxw41dwjpwjuIJkLHg,5303
|
|
19
19
|
onnxtr/models/classification/__init__.py,sha256=h1bZs55iLJBMATtzS4ntTKwfD6OGXBiiqGv_hEnOFnE,41
|
|
20
20
|
onnxtr/models/classification/zoo.py,sha256=4hD51Mdf5gkSoQ4g9zTBvurbBdrsaFFEl5WFpptBtNk,4271
|
|
@@ -23,7 +23,7 @@ onnxtr/models/classification/models/mobilenet.py,sha256=pRI97DvBpBE-h2VymUG6sw_J
|
|
|
23
23
|
onnxtr/models/classification/predictor/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
|
|
24
24
|
onnxtr/models/classification/predictor/base.py,sha256=hpLYmhn8PCbx46zYBM8rZiy2vabpN3YkviwmmbVaqRo,2313
|
|
25
25
|
onnxtr/models/detection/__init__.py,sha256=h1bZs55iLJBMATtzS4ntTKwfD6OGXBiiqGv_hEnOFnE,41
|
|
26
|
-
onnxtr/models/detection/core.py,sha256=
|
|
26
|
+
onnxtr/models/detection/core.py,sha256=0oTo-NxtsvVwXqCpNHv98uiXoOcUk8WsIRi5X65bnc8,3466
|
|
27
27
|
onnxtr/models/detection/zoo.py,sha256=RbzG9nR0Oa9bV0vwEBer2GDJMg1XvthpRLBxD2MsUvQ,3385
|
|
28
28
|
onnxtr/models/detection/_utils/__init__.py,sha256=oPkIYbySSbLsOk02wVPNO9bUuywC47YjaenfyTwfOsw,20
|
|
29
29
|
onnxtr/models/detection/_utils/base.py,sha256=MUn3cHUSq-dIKAA021ZUrTm0SLpAC9qsiw1BAWvcppc,2300
|
|
@@ -47,7 +47,7 @@ onnxtr/models/recognition/core.py,sha256=V6DMa3ABT0amr9vPSQSyo0dZqK-Y8qmA__XWhOx
|
|
|
47
47
|
onnxtr/models/recognition/utils.py,sha256=jsKZl7XbGKCgEhdH4xYDdf9xrrDR0vS3RqbwGIg17z0,3756
|
|
48
48
|
onnxtr/models/recognition/zoo.py,sha256=nNDf60Et6wE60cJhcqwxNbCPQfcv2pgQIK6KeGVH0WE,3018
|
|
49
49
|
onnxtr/models/recognition/models/__init__.py,sha256=hbjiDSCgh_EUEM7q9aSbcK7ffszMvsDWW89-MVN21Vk,126
|
|
50
|
-
onnxtr/models/recognition/models/crnn.py,sha256=
|
|
50
|
+
onnxtr/models/recognition/models/crnn.py,sha256=fZDrHp6ojs_-r1VZm9J8jMiRQ4lA760pBZXTzzi0Jrk,8779
|
|
51
51
|
onnxtr/models/recognition/models/master.py,sha256=H_KcoJCK8nElyID5FKJdld5xapu5ZOWVcH5_H68_N1I,4669
|
|
52
52
|
onnxtr/models/recognition/models/parseq.py,sha256=qe7lavwFT37SPLSMWoPaoCYo7yrTYGcCYqQraTwIuQY,4512
|
|
53
53
|
onnxtr/models/recognition/models/sar.py,sha256=5v0VOPACvB_-I_kDh57pA00GmunIh6frD_4I6ojSjiQ,4523
|
|
@@ -67,10 +67,10 @@ onnxtr/utils/multithreading.py,sha256=P8LXpaZSKRYsYZw6SRlWWXiQMDswk8zEgDSbCYVHzS
|
|
|
67
67
|
onnxtr/utils/reconstitution.py,sha256=2SUkaReD5eJ5NFs7V7Z0m4N4lUr8QB7oH1mSHTC3vLA,6119
|
|
68
68
|
onnxtr/utils/repr.py,sha256=lAcKRShXLpJ2DvsS2qf3vYq0lJrMJa30kLYXmfN3rV0,2105
|
|
69
69
|
onnxtr/utils/visualization.py,sha256=MImlxVKOLXPriJYSrBfjZfJw0GEZ1gT8eni3KXZHrXk,9831
|
|
70
|
-
onnxtr/utils/vocabs.py,sha256=
|
|
71
|
-
onnxtr-0.
|
|
72
|
-
onnxtr-0.
|
|
73
|
-
onnxtr-0.
|
|
74
|
-
onnxtr-0.
|
|
75
|
-
onnxtr-0.
|
|
76
|
-
onnxtr-0.
|
|
70
|
+
onnxtr/utils/vocabs.py,sha256=i7LIv6tUiTXMcqHZfDgU43knJ-9zBptF6loXdft4KY4,99049
|
|
71
|
+
onnxtr-0.8.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
72
|
+
onnxtr-0.8.0.dist-info/METADATA,sha256=JLbYn1isqfSmHlTpKVpTxFmx0HW1YQpxEeVPv7ID29s,35915
|
|
73
|
+
onnxtr-0.8.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
74
|
+
onnxtr-0.8.0.dist-info/top_level.txt,sha256=r_MSUTpspp4pWEEWvly-s7ZkfCg1KwrK6-kBlXkWKU8,7
|
|
75
|
+
onnxtr-0.8.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
76
|
+
onnxtr-0.8.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|