onnxtr 0.3.1__tar.gz → 0.3.2__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.
Files changed (80) hide show
  1. {onnxtr-0.3.1 → onnxtr-0.3.2}/PKG-INFO +1 -1
  2. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/transforms/base.py +33 -46
  3. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/fonts.py +5 -3
  4. onnxtr-0.3.2/onnxtr/version.py +1 -0
  5. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr.egg-info/PKG-INFO +1 -1
  6. {onnxtr-0.3.1 → onnxtr-0.3.2}/setup.py +1 -1
  7. onnxtr-0.3.1/onnxtr/version.py +0 -1
  8. {onnxtr-0.3.1 → onnxtr-0.3.2}/LICENSE +0 -0
  9. {onnxtr-0.3.1 → onnxtr-0.3.2}/README.md +0 -0
  10. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/__init__.py +0 -0
  11. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/contrib/__init__.py +0 -0
  12. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/contrib/artefacts.py +0 -0
  13. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/contrib/base.py +0 -0
  14. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/file_utils.py +0 -0
  15. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/io/__init__.py +0 -0
  16. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/io/elements.py +0 -0
  17. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/io/html.py +0 -0
  18. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/io/image.py +0 -0
  19. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/io/pdf.py +0 -0
  20. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/io/reader.py +0 -0
  21. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/__init__.py +0 -0
  22. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/_utils.py +0 -0
  23. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/builder.py +0 -0
  24. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/classification/__init__.py +0 -0
  25. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/classification/models/__init__.py +0 -0
  26. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/classification/models/mobilenet.py +0 -0
  27. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/classification/predictor/__init__.py +0 -0
  28. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/classification/predictor/base.py +0 -0
  29. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/classification/zoo.py +0 -0
  30. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/__init__.py +0 -0
  31. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/_utils/__init__.py +0 -0
  32. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/_utils/base.py +0 -0
  33. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/core.py +0 -0
  34. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/models/__init__.py +0 -0
  35. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/models/differentiable_binarization.py +0 -0
  36. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/models/fast.py +0 -0
  37. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/models/linknet.py +0 -0
  38. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/postprocessor/__init__.py +0 -0
  39. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/postprocessor/base.py +0 -0
  40. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/predictor/__init__.py +0 -0
  41. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/predictor/base.py +0 -0
  42. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/detection/zoo.py +0 -0
  43. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/engine.py +0 -0
  44. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/predictor/__init__.py +0 -0
  45. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/predictor/base.py +0 -0
  46. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/predictor/predictor.py +0 -0
  47. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/preprocessor/__init__.py +0 -0
  48. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/preprocessor/base.py +6 -6
  49. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/__init__.py +0 -0
  50. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/core.py +0 -0
  51. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/models/__init__.py +0 -0
  52. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/models/crnn.py +0 -0
  53. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/models/master.py +0 -0
  54. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/models/parseq.py +0 -0
  55. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/models/sar.py +0 -0
  56. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/models/vitstr.py +0 -0
  57. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/predictor/__init__.py +0 -0
  58. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/predictor/_utils.py +0 -0
  59. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/predictor/base.py +0 -0
  60. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/utils.py +0 -0
  61. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/recognition/zoo.py +0 -0
  62. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/models/zoo.py +0 -0
  63. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/py.typed +0 -0
  64. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/transforms/__init__.py +0 -0
  65. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/__init__.py +0 -0
  66. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/common_types.py +0 -0
  67. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/data.py +0 -0
  68. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/geometry.py +0 -0
  69. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/multithreading.py +0 -0
  70. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/reconstitution.py +0 -0
  71. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/repr.py +0 -0
  72. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/visualization.py +0 -0
  73. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr/utils/vocabs.py +0 -0
  74. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr.egg-info/SOURCES.txt +0 -0
  75. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr.egg-info/dependency_links.txt +0 -0
  76. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr.egg-info/requires.txt +0 -0
  77. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr.egg-info/top_level.txt +0 -0
  78. {onnxtr-0.3.1 → onnxtr-0.3.2}/onnxtr.egg-info/zip-safe +0 -0
  79. {onnxtr-0.3.1 → onnxtr-0.3.2}/pyproject.toml +0 -0
  80. {onnxtr-0.3.1 → onnxtr-0.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: onnxtr
3
- Version: 0.3.1
3
+ Version: 0.3.2
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
@@ -5,8 +5,8 @@
5
5
 
6
6
  from typing import Tuple, Union
7
7
 
8
- import cv2
9
8
  import numpy as np
9
+ from PIL import Image, ImageOps
10
10
 
11
11
  __all__ = ["Resize", "Normalize"]
12
12
 
@@ -17,64 +17,51 @@ class Resize:
17
17
  def __init__(
18
18
  self,
19
19
  size: Union[int, Tuple[int, int]],
20
- interpolation=cv2.INTER_LINEAR,
20
+ interpolation=Image.Resampling.BILINEAR,
21
21
  preserve_aspect_ratio: bool = False,
22
22
  symmetric_pad: bool = False,
23
23
  ) -> None:
24
- super().__init__()
25
- self.size = size
24
+ self.size = size if isinstance(size, tuple) else (size, size)
26
25
  self.interpolation = interpolation
27
26
  self.preserve_aspect_ratio = preserve_aspect_ratio
28
27
  self.symmetric_pad = symmetric_pad
29
28
  self.output_size = size if isinstance(size, tuple) else (size, size)
30
29
 
31
- if not isinstance(self.size, (int, tuple, list)):
32
- raise AssertionError("size should be either a tuple, a list or an int")
30
+ if not isinstance(self.size, (tuple, int)):
31
+ raise AssertionError("size should be either a tuple or an int")
33
32
 
34
- def __call__(
35
- self,
36
- img: np.ndarray,
37
- ) -> np.ndarray:
38
- if img.ndim == 3:
39
- h, w = img.shape[0:2]
40
- else:
41
- h, w = img.shape[1:3]
42
- sh, sw = self.size if isinstance(self.size, tuple) else (self.size, self.size)
33
+ def __call__(self, img: np.ndarray) -> np.ndarray:
34
+ img = (img * 255).astype(np.uint8) if img.dtype != np.uint8 else img
35
+ h, w = img.shape[:2] if img.ndim == 3 else img.shape[1:3]
36
+ sh, sw = self.size
43
37
 
44
- # Calculate aspect ratio of the image
45
- aspect = w / h
38
+ if not self.preserve_aspect_ratio:
39
+ return np.array(Image.fromarray(img).resize((sw, sh), resample=self.interpolation))
46
40
 
47
- # Compute scaling and padding sizes
48
- if self.preserve_aspect_ratio:
49
- if aspect > 1: # Horizontal image
50
- new_w = sw
51
- new_h = int(sw / aspect)
52
- elif aspect < 1: # Vertical image
53
- new_h = sh
54
- new_w = int(sh * aspect)
55
- else: # Square image
56
- new_h, new_w = sh, sw
57
-
58
- img_resized = cv2.resize(img, (new_w, new_h), interpolation=self.interpolation)
59
-
60
- # Calculate padding
61
- pad_top = max((sh - new_h) // 2, 0)
62
- pad_bottom = max(sh - new_h - pad_top, 0)
63
- pad_left = max((sw - new_w) // 2, 0)
64
- pad_right = max(sw - new_w - pad_left, 0)
65
-
66
- # Pad the image
67
- img_resized = cv2.copyMakeBorder( # type: ignore[call-overload]
68
- img_resized, pad_top, pad_bottom, pad_left, pad_right, borderType=cv2.BORDER_CONSTANT, value=0
69
- )
70
-
71
- # Ensure the image matches the target size by resizing it again if needed
72
- img_resized = cv2.resize(img_resized, (sw, sh), interpolation=self.interpolation)
41
+ actual_ratio = h / w
42
+ target_ratio = sh / sw
43
+
44
+ if target_ratio == actual_ratio:
45
+ return np.array(Image.fromarray(img).resize((sw, sh), resample=self.interpolation))
46
+
47
+ if actual_ratio > target_ratio:
48
+ tmp_size = (int(sh / actual_ratio), sh)
73
49
  else:
74
- # Resize the image without preserving aspect ratio
75
- img_resized = cv2.resize(img, (sw, sh), interpolation=self.interpolation)
50
+ tmp_size = (sw, int(sw * actual_ratio))
51
+
52
+ img_resized = Image.fromarray(img).resize(tmp_size, resample=self.interpolation)
53
+ pad_left = pad_top = 0
54
+ pad_right = sw - img_resized.width
55
+ pad_bottom = sh - img_resized.height
56
+
57
+ if self.symmetric_pad:
58
+ pad_left = pad_right // 2
59
+ pad_right -= pad_left
60
+ pad_top = pad_bottom // 2
61
+ pad_bottom -= pad_top
76
62
 
77
- return img_resized
63
+ img_resized = ImageOps.expand(img_resized, (pad_left, pad_top, pad_right, pad_bottom))
64
+ return np.array(img_resized)
78
65
 
79
66
  def __repr__(self) -> str:
80
67
  interpolate_str = self.interpolation
@@ -5,14 +5,16 @@
5
5
 
6
6
  import logging
7
7
  import platform
8
- from typing import Optional
8
+ from typing import Optional, Union
9
9
 
10
10
  from PIL import ImageFont
11
11
 
12
12
  __all__ = ["get_font"]
13
13
 
14
14
 
15
- def get_font(font_family: Optional[str] = None, font_size: int = 13) -> ImageFont.ImageFont:
15
+ def get_font(
16
+ font_family: Optional[str] = None, font_size: int = 13
17
+ ) -> Union[ImageFont.FreeTypeFont, ImageFont.ImageFont]:
16
18
  """Resolves a compatible ImageFont for the system
17
19
 
18
20
  Args:
@@ -29,7 +31,7 @@ def get_font(font_family: Optional[str] = None, font_size: int = 13) -> ImageFon
29
31
  try:
30
32
  font = ImageFont.truetype("FreeMono.ttf" if platform.system() == "Linux" else "Arial.ttf", font_size)
31
33
  except OSError: # pragma: no cover
32
- font = ImageFont.load_default()
34
+ font = ImageFont.load_default() # type: ignore[assignment]
33
35
  logging.warning(
34
36
  "unable to load recommended font family. Loading default PIL font,"
35
37
  "font size issues may be expected."
@@ -0,0 +1 @@
1
+ __version__ = 'v0.3.2'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: onnxtr
3
- Version: 0.3.1
3
+ Version: 0.3.2
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
@@ -9,7 +9,7 @@ from pathlib import Path
9
9
  from setuptools import setup
10
10
 
11
11
  PKG_NAME = "onnxtr"
12
- VERSION = os.getenv("BUILD_VERSION", "0.3.1a0")
12
+ VERSION = os.getenv("BUILD_VERSION", "0.3.2a0")
13
13
 
14
14
 
15
15
  if __name__ == "__main__":
@@ -1 +0,0 @@
1
- __version__ = 'v0.3.1'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -67,11 +67,12 @@ class PreProcessor(NestedObject):
67
67
  if x.dtype not in (np.uint8, np.float32):
68
68
  raise TypeError("unsupported data type for numpy.ndarray")
69
69
  x = shape_translate(x, "HWC")
70
+
71
+ # Resizing
72
+ x = self.resize(x)
70
73
  # Data type & 255 division
71
74
  if x.dtype == np.uint8:
72
75
  x = x.astype(np.float32) / 255.0
73
- # Resizing
74
- x = self.resize(x)
75
76
 
76
77
  return x
77
78
 
@@ -95,13 +96,12 @@ class PreProcessor(NestedObject):
95
96
  raise TypeError("unsupported data type for numpy.ndarray")
96
97
  x = shape_translate(x, "BHWC")
97
98
 
98
- # Data type & 255 division
99
- if x.dtype == np.uint8:
100
- x = x.astype(np.float32) / 255.0
101
99
  # Resizing
102
100
  if (x.shape[1], x.shape[2]) != self.resize.output_size:
103
101
  x = np.array([self.resize(sample) for sample in x])
104
-
102
+ # Data type & 255 division
103
+ if x.dtype == np.uint8:
104
+ x = x.astype(np.float32) / 255.0
105
105
  batches = [x]
106
106
 
107
107
  elif isinstance(x, list) and all(isinstance(sample, np.ndarray) for sample in x):
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes