deepdoctection 0.31__py3-none-any.whl → 0.33__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.

Potentially problematic release.


This version of deepdoctection might be problematic. Click here for more details.

Files changed (131) hide show
  1. deepdoctection/__init__.py +16 -29
  2. deepdoctection/analyzer/dd.py +70 -59
  3. deepdoctection/configs/conf_dd_one.yaml +34 -31
  4. deepdoctection/dataflow/common.py +9 -5
  5. deepdoctection/dataflow/custom.py +5 -5
  6. deepdoctection/dataflow/custom_serialize.py +75 -18
  7. deepdoctection/dataflow/parallel_map.py +3 -3
  8. deepdoctection/dataflow/serialize.py +4 -4
  9. deepdoctection/dataflow/stats.py +3 -3
  10. deepdoctection/datapoint/annotation.py +41 -56
  11. deepdoctection/datapoint/box.py +9 -8
  12. deepdoctection/datapoint/convert.py +6 -6
  13. deepdoctection/datapoint/image.py +56 -44
  14. deepdoctection/datapoint/view.py +245 -150
  15. deepdoctection/datasets/__init__.py +1 -4
  16. deepdoctection/datasets/adapter.py +35 -26
  17. deepdoctection/datasets/base.py +14 -12
  18. deepdoctection/datasets/dataflow_builder.py +3 -3
  19. deepdoctection/datasets/info.py +24 -26
  20. deepdoctection/datasets/instances/doclaynet.py +51 -51
  21. deepdoctection/datasets/instances/fintabnet.py +46 -46
  22. deepdoctection/datasets/instances/funsd.py +25 -24
  23. deepdoctection/datasets/instances/iiitar13k.py +13 -10
  24. deepdoctection/datasets/instances/layouttest.py +4 -3
  25. deepdoctection/datasets/instances/publaynet.py +5 -5
  26. deepdoctection/datasets/instances/pubtables1m.py +24 -21
  27. deepdoctection/datasets/instances/pubtabnet.py +32 -30
  28. deepdoctection/datasets/instances/rvlcdip.py +30 -30
  29. deepdoctection/datasets/instances/xfund.py +26 -26
  30. deepdoctection/datasets/save.py +6 -6
  31. deepdoctection/eval/__init__.py +1 -4
  32. deepdoctection/eval/accmetric.py +32 -33
  33. deepdoctection/eval/base.py +8 -9
  34. deepdoctection/eval/cocometric.py +15 -13
  35. deepdoctection/eval/eval.py +41 -37
  36. deepdoctection/eval/tedsmetric.py +30 -23
  37. deepdoctection/eval/tp_eval_callback.py +16 -19
  38. deepdoctection/extern/__init__.py +2 -7
  39. deepdoctection/extern/base.py +339 -134
  40. deepdoctection/extern/d2detect.py +85 -113
  41. deepdoctection/extern/deskew.py +14 -11
  42. deepdoctection/extern/doctrocr.py +141 -130
  43. deepdoctection/extern/fastlang.py +27 -18
  44. deepdoctection/extern/hfdetr.py +71 -62
  45. deepdoctection/extern/hflayoutlm.py +504 -211
  46. deepdoctection/extern/hflm.py +230 -0
  47. deepdoctection/extern/model.py +488 -302
  48. deepdoctection/extern/pdftext.py +23 -19
  49. deepdoctection/extern/pt/__init__.py +1 -3
  50. deepdoctection/extern/pt/nms.py +6 -2
  51. deepdoctection/extern/pt/ptutils.py +29 -19
  52. deepdoctection/extern/tessocr.py +39 -38
  53. deepdoctection/extern/texocr.py +18 -18
  54. deepdoctection/extern/tp/tfutils.py +57 -9
  55. deepdoctection/extern/tp/tpcompat.py +21 -14
  56. deepdoctection/extern/tp/tpfrcnn/__init__.py +20 -0
  57. deepdoctection/extern/tp/tpfrcnn/common.py +7 -3
  58. deepdoctection/extern/tp/tpfrcnn/config/__init__.py +20 -0
  59. deepdoctection/extern/tp/tpfrcnn/config/config.py +13 -10
  60. deepdoctection/extern/tp/tpfrcnn/modeling/__init__.py +20 -0
  61. deepdoctection/extern/tp/tpfrcnn/modeling/backbone.py +18 -8
  62. deepdoctection/extern/tp/tpfrcnn/modeling/generalized_rcnn.py +12 -6
  63. deepdoctection/extern/tp/tpfrcnn/modeling/model_box.py +14 -9
  64. deepdoctection/extern/tp/tpfrcnn/modeling/model_cascade.py +8 -5
  65. deepdoctection/extern/tp/tpfrcnn/modeling/model_fpn.py +22 -17
  66. deepdoctection/extern/tp/tpfrcnn/modeling/model_frcnn.py +21 -14
  67. deepdoctection/extern/tp/tpfrcnn/modeling/model_mrcnn.py +19 -11
  68. deepdoctection/extern/tp/tpfrcnn/modeling/model_rpn.py +15 -10
  69. deepdoctection/extern/tp/tpfrcnn/predict.py +9 -4
  70. deepdoctection/extern/tp/tpfrcnn/preproc.py +12 -8
  71. deepdoctection/extern/tp/tpfrcnn/utils/__init__.py +20 -0
  72. deepdoctection/extern/tp/tpfrcnn/utils/box_ops.py +10 -2
  73. deepdoctection/extern/tpdetect.py +45 -53
  74. deepdoctection/mapper/__init__.py +3 -8
  75. deepdoctection/mapper/cats.py +27 -29
  76. deepdoctection/mapper/cocostruct.py +10 -10
  77. deepdoctection/mapper/d2struct.py +27 -26
  78. deepdoctection/mapper/hfstruct.py +13 -8
  79. deepdoctection/mapper/laylmstruct.py +178 -37
  80. deepdoctection/mapper/maputils.py +12 -11
  81. deepdoctection/mapper/match.py +2 -2
  82. deepdoctection/mapper/misc.py +11 -9
  83. deepdoctection/mapper/pascalstruct.py +4 -4
  84. deepdoctection/mapper/prodigystruct.py +5 -5
  85. deepdoctection/mapper/pubstruct.py +84 -92
  86. deepdoctection/mapper/tpstruct.py +5 -5
  87. deepdoctection/mapper/xfundstruct.py +33 -33
  88. deepdoctection/pipe/__init__.py +1 -1
  89. deepdoctection/pipe/anngen.py +12 -14
  90. deepdoctection/pipe/base.py +52 -106
  91. deepdoctection/pipe/common.py +72 -59
  92. deepdoctection/pipe/concurrency.py +16 -11
  93. deepdoctection/pipe/doctectionpipe.py +24 -21
  94. deepdoctection/pipe/language.py +20 -25
  95. deepdoctection/pipe/layout.py +20 -16
  96. deepdoctection/pipe/lm.py +75 -105
  97. deepdoctection/pipe/order.py +194 -89
  98. deepdoctection/pipe/refine.py +111 -124
  99. deepdoctection/pipe/segment.py +156 -161
  100. deepdoctection/pipe/{cell.py → sub_layout.py} +50 -40
  101. deepdoctection/pipe/text.py +37 -36
  102. deepdoctection/pipe/transform.py +19 -16
  103. deepdoctection/train/__init__.py +6 -12
  104. deepdoctection/train/d2_frcnn_train.py +48 -41
  105. deepdoctection/train/hf_detr_train.py +41 -30
  106. deepdoctection/train/hf_layoutlm_train.py +153 -135
  107. deepdoctection/train/tp_frcnn_train.py +32 -31
  108. deepdoctection/utils/concurrency.py +1 -1
  109. deepdoctection/utils/context.py +13 -6
  110. deepdoctection/utils/develop.py +4 -4
  111. deepdoctection/utils/env_info.py +87 -125
  112. deepdoctection/utils/file_utils.py +6 -11
  113. deepdoctection/utils/fs.py +22 -18
  114. deepdoctection/utils/identifier.py +2 -2
  115. deepdoctection/utils/logger.py +16 -15
  116. deepdoctection/utils/metacfg.py +7 -7
  117. deepdoctection/utils/mocks.py +93 -0
  118. deepdoctection/utils/pdf_utils.py +11 -11
  119. deepdoctection/utils/settings.py +185 -181
  120. deepdoctection/utils/tqdm.py +1 -1
  121. deepdoctection/utils/transform.py +14 -9
  122. deepdoctection/utils/types.py +104 -0
  123. deepdoctection/utils/utils.py +7 -7
  124. deepdoctection/utils/viz.py +74 -72
  125. {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/METADATA +30 -21
  126. deepdoctection-0.33.dist-info/RECORD +146 -0
  127. {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/WHEEL +1 -1
  128. deepdoctection/utils/detection_types.py +0 -68
  129. deepdoctection-0.31.dist-info/RECORD +0 -144
  130. {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/LICENSE +0 -0
  131. {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/top_level.txt +0 -0
@@ -18,11 +18,12 @@
18
18
  """
19
19
  Module for funcs and constants that maintain general settings
20
20
  """
21
+ from __future__ import annotations
21
22
 
22
23
  import os
23
24
  from enum import Enum
24
25
  from pathlib import Path
25
- from typing import Dict, List, Optional, Tuple, Union
26
+ from typing import Optional, Union
26
27
 
27
28
  import catalogue # type: ignore
28
29
 
@@ -34,7 +35,7 @@ class ObjectTypes(str, Enum):
34
35
  return f"<{self.__class__.__name__}.{self.name}>"
35
36
 
36
37
  @classmethod
37
- def from_value(cls, value: str) -> "ObjectTypes":
38
+ def from_value(cls, value: str) -> ObjectTypes:
38
39
  """Getting the enum member from a given string value
39
40
 
40
41
  :param value: string value to get the enum member
@@ -56,262 +57,265 @@ object_types_registry = catalogue.create("deepdoctection", "settings", entry_poi
56
57
  class DefaultType(ObjectTypes):
57
58
  """Type for default member"""
58
59
 
59
- default_type = "default_type"
60
+ DEFAULT_TYPE = "default_type"
60
61
 
61
62
 
62
63
  @object_types_registry.register("PageType")
63
64
  class PageType(ObjectTypes):
64
65
  """Type for document page properties"""
65
66
 
66
- document_type = "document_type"
67
- language = "language"
68
- angle = "angle"
67
+ DOCUMENT_TYPE = "document_type"
68
+ LANGUAGE = "language"
69
+ ANGLE = "angle"
69
70
 
70
71
 
71
72
  @object_types_registry.register("SummaryType")
72
73
  class SummaryType(ObjectTypes):
73
74
  """Summary type member"""
74
75
 
75
- summary = "summary"
76
+ SUMMARY = "summary"
76
77
 
77
78
 
78
79
  @object_types_registry.register("DocumentType")
79
80
  class DocumentType(ObjectTypes):
80
81
  """Document types"""
81
82
 
82
- letter = "letter"
83
- form = "form"
84
- email = "email"
85
- handwritten = "handwritten"
86
- advertisement = "advertisement"
87
- scientific_report = "scientific_report"
88
- scientific_publication = "scientific_publication"
89
- specification = "specification"
90
- file_folder = "file_folder"
91
- news_article = "news_article"
92
- budget = "budget"
93
- invoice = "invoice"
94
- presentation = "presentation"
95
- questionnaire = "questionnaire"
96
- resume = "resume"
97
- memo = "memo"
98
- financial_report = "financial_report"
99
- laws_and_regulations = "laws_and_regulations"
100
- government_tenders = "government_tenders"
101
- manuals = "manuals"
102
- patents = "patents"
83
+ LETTER = "letter"
84
+ FORM = "form"
85
+ EMAIL = "email"
86
+ HANDWRITTEN = "handwritten"
87
+ ADVERTISEMENT = "advertisement"
88
+ SCIENTIFIC_REPORT = "scientific_report"
89
+ SCIENTIFIC_PUBLICATION = "scientific_publication"
90
+ SPECIFICATION = "specification"
91
+ FILE_FOLDER = "file_folder"
92
+ NEWS_ARTICLE = "news_article"
93
+ BUDGET = "budget"
94
+ INVOICE = "invoice"
95
+ PRESENTATION = "presentation"
96
+ QUESTIONNAIRE = "questionnaire"
97
+ RESUME = "resume"
98
+ MEMO = "memo"
99
+ FINANCIAL_REPORT = "financial_report"
100
+ LAWS_AND_REGULATIONS = "laws_and_regulations"
101
+ GOVERNMENT_TENDERS = "government_tenders"
102
+ MANUALS = "manuals"
103
+ PATENTS = "patents"
103
104
 
104
105
 
105
106
  @object_types_registry.register("LayoutType")
106
107
  class LayoutType(ObjectTypes):
107
108
  """Layout types"""
108
109
 
109
- table = "table"
110
- table_rotated = "table_rotated"
111
- figure = "figure"
112
- list = "list"
113
- text = "text"
114
- title = "title" # type: ignore
115
- logo = "logo"
116
- signature = "signature"
117
- caption = "caption"
118
- footnote = "footnote"
119
- formula = "formula"
120
- page_footer = "page_footer"
121
- page_header = "page_header"
122
- section_header = "section_header"
123
- page = "page"
124
- cell = "cell"
125
- row = "row"
126
- column = "column"
127
- word = "word"
128
- line = "line"
129
- background = "background"
110
+ TABLE = "table"
111
+ TABLE_ROTATED = "table_rotated"
112
+ FIGURE = "figure"
113
+ LIST = "list"
114
+ TEXT = "text"
115
+ TITLE = "title"
116
+ LOGO = "logo"
117
+ SIGNATURE = "signature"
118
+ CAPTION = "caption"
119
+ FOOTNOTE = "footnote"
120
+ FORMULA = "formula"
121
+ PAGE_FOOTER = "page_footer"
122
+ PAGE_HEADER = "page_header"
123
+ SECTION_HEADER = "section_header"
124
+ PAGE = "page"
125
+ CELL = "cell"
126
+ ROW = "row"
127
+ COLUMN = "column"
128
+ WORD = "word"
129
+ LINE = "line"
130
+ BACKGROUND = "background"
131
+ PAGE_NUMBER = "page_number"
132
+ KEY_VALUE_AREA = "key_value_area"
130
133
 
131
134
 
132
135
  @object_types_registry.register("TableType")
133
136
  class TableType(ObjectTypes):
134
137
  """Types for table properties"""
135
138
 
136
- item = "item"
137
- number_of_rows = "number_of_rows"
138
- number_of_columns = "number_of_columns"
139
- max_row_span = "max_row_span"
140
- max_col_span = "max_col_span"
141
- html = "html"
139
+ ITEM = "item"
140
+ NUMBER_OF_ROWS = "number_of_rows"
141
+ NUMBER_OF_COLUMNS = "number_of_columns"
142
+ MAX_ROW_SPAN = "max_row_span"
143
+ MAX_COL_SPAN = "max_col_span"
144
+ HTML = "html"
142
145
 
143
146
 
144
147
  @object_types_registry.register("CellType")
145
148
  class CellType(ObjectTypes):
146
149
  """Types for cell properties"""
147
150
 
148
- header = "header"
149
- body = "body"
150
- row_number = "row_number"
151
- row_span = "row_span"
152
- row_header = "row_header"
153
- projected_row_header = "projected_row_header"
154
- column_number = "column_number"
155
- column_span = "column_span"
156
- column_header = "column_header"
157
- spanning = "spanning"
151
+ HEADER = "header"
152
+ BODY = "body"
153
+ ROW_NUMBER = "row_number"
154
+ ROW_SPAN = "row_span"
155
+ ROW_HEADER = "row_header"
156
+ PROJECTED_ROW_HEADER = "projected_row_header"
157
+ COLUMN_NUMBER = "column_number"
158
+ COLUMN_SPAN = "column_span"
159
+ COLUMN_HEADER = "column_header"
160
+ SPANNING = "spanning"
158
161
 
159
162
 
160
163
  @object_types_registry.register("WordType")
161
164
  class WordType(ObjectTypes):
162
165
  """Types for word properties"""
163
166
 
164
- characters = "characters"
165
- block = "block"
166
- token_class = "token_class"
167
- tag = "tag"
168
- token_tag = "token_tag"
169
- text_line = "text_line"
170
- character_type = "character_type"
171
- printed = "printed"
172
- handwritten = "handwritten"
167
+ CHARACTERS = "characters"
168
+ BLOCK = "block"
169
+ TOKEN_CLASS = "token_class"
170
+ TAG = "tag"
171
+ TOKEN_TAG = "token_tag"
172
+ TEXT_LINE = "text_line"
173
+ CHARACTER_TYPE = "character_type"
174
+ PRINTED = "printed"
175
+ HANDWRITTEN = "handwritten"
173
176
 
174
177
 
175
178
  @object_types_registry.register("TokenClasses")
176
179
  class TokenClasses(ObjectTypes):
177
180
  """Types for token classes"""
178
181
 
179
- header = "header"
180
- question = "question"
181
- answer = "answer"
182
- other = "other"
182
+ HEADER = "header"
183
+ QUESTION = "question"
184
+ ANSWER = "answer"
185
+ OTHER = "other"
183
186
 
184
187
 
185
188
  @object_types_registry.register("BioTag")
186
189
  class BioTag(ObjectTypes):
187
190
  """Types for tags"""
188
191
 
189
- begin = "B"
190
- inside = "I"
191
- outside = "O"
192
- single = "S"
193
- end = "E"
192
+ BEGIN = "B"
193
+ INSIDE = "I"
194
+ OUTSIDE = "O"
195
+ SINGLE = "S"
196
+ END = "E"
194
197
 
195
198
 
196
199
  @object_types_registry.register("TokenClassWithTag")
197
200
  class TokenClassWithTag(ObjectTypes):
198
201
  """Types for token classes with tags, e.g. B-answer"""
199
202
 
200
- b_answer = "B-answer"
201
- b_header = "B-header"
202
- b_question = "B-question"
203
- e_answer = "E-answer"
204
- e_header = "E-header"
205
- e_question = "E-question"
206
- i_answer = "I-answer"
207
- i_header = "I-header"
208
- i_question = "I-question"
209
- s_answer = "S-answer"
210
- s_header = "S-header"
211
- s_question = "S-question"
203
+ B_ANSWER = "B-answer"
204
+ B_HEADER = "B-header"
205
+ B_QUESTION = "B-question"
206
+ E_ANSWER = "E-answer"
207
+ E_HEADER = "E-header"
208
+ E_QUESTION = "E-question"
209
+ I_ANSWER = "I-answer"
210
+ I_HEADER = "I-header"
211
+ I_QUESTION = "I-question"
212
+ S_ANSWER = "S-answer"
213
+ S_HEADER = "S-header"
214
+ S_QUESTION = "S-question"
212
215
 
213
216
 
214
217
  @object_types_registry.register("Relationships")
215
218
  class Relationships(ObjectTypes):
216
219
  """Types for describing relationships between types"""
217
220
 
218
- child = "child"
219
- reading_order = "reading_order"
220
- semantic_entity_link = "semantic_entity_link"
221
+ CHILD = "child"
222
+ READING_ORDER = "reading_order"
223
+ SEMANTIC_ENTITY_LINK = "semantic_entity_link"
221
224
 
222
225
 
223
226
  @object_types_registry.register("Languages")
224
227
  class Languages(ObjectTypes):
225
228
  """Language types"""
226
229
 
227
- english = "eng"
228
- russian = "rus"
229
- german = "deu"
230
- french = "fre"
231
- italian = "ita"
232
- japanese = "jpn"
233
- spanish = "spa"
234
- cebuano = "ceb"
235
- turkish = "tur"
236
- portuguese = "por"
237
- ukrainian = "ukr"
238
- esperanto = "epo"
239
- polish = "pol"
240
- swedish = "swe"
241
- dutch = "dut"
242
- hebrew = "heb"
243
- chinese = "chi"
244
- hungarian = "hun"
245
- arabic = "ara"
246
- catalan = "cat"
247
- finnish = "fin"
248
- czech = "cze"
249
- persian = "per"
250
- serbian = "srp"
251
- greek = "gre"
252
- vietnamese = "vie"
253
- bulgarian = "bul"
254
- korean = "kor"
255
- norwegian = "nor"
256
- macedonian = "mac"
257
- romanian = "rum"
258
- indonesian = "ind"
259
- thai = "tha"
260
- armenian = "arm"
261
- danish = "dan"
262
- tamil = "tam"
263
- hindi = "hin"
264
- croatian = "hrv"
265
- belarusian = "bel"
266
- georgian = "geo"
267
- telugu = "tel"
268
- kazakh = "kaz"
269
- waray = "war"
270
- lithuanian = "lit"
271
- scottish = "glg"
272
- slovak = "slo"
273
- benin = "ben"
274
- basque = "baq"
275
- slovenian = "slv"
276
- malayalam = "mal"
277
- marathi = "mar"
278
- estonian = "est"
279
- azerbaijani = "aze"
280
- albanian = "alb"
281
- latin = "lat"
282
- bosnian = "bos"
283
- norwegian_nynorsk = "nno"
284
- urdu = "urd"
285
- not_defined = "nn"
230
+ ENGLISH = "eng"
231
+ RUSSIAN = "rus"
232
+ GERMAN = "deu"
233
+ FRENCH = "fre"
234
+ ITALIAN = "ita"
235
+ JAPANESE = "jpn"
236
+ SPANISH = "spa"
237
+ CEBUANO = "ceb"
238
+ TURKISH = "tur"
239
+ PORTUGUESE = "por"
240
+ UKRAINIAN = "ukr"
241
+ ESPERANTO = "epo"
242
+ POLISH = "pol"
243
+ SWEDISH = "swe"
244
+ DUTCH = "dut"
245
+ HEBREW = "heb"
246
+ CHINESE = "chi"
247
+ HUNGARIAN = "hun"
248
+ ARABIC = "ara"
249
+ CATALAN = "cat"
250
+ FINNISH = "fin"
251
+ CZECH = "cze"
252
+ PERSIAN = "per"
253
+ SERBIAN = "srp"
254
+ GREEK = "gre"
255
+ VIETNAMESE = "vie"
256
+ BULGARIAN = "bul"
257
+ KOREAN = "kor"
258
+ NORWEGIAN = "nor"
259
+ MACEDONIAN = "mac"
260
+ ROMANIAN = "rum"
261
+ INDONESIAN = "ind"
262
+ THAI = "tha"
263
+ ARMENIAN = "arm"
264
+ DANISH = "dan"
265
+ TAMIL = "tam"
266
+ HINDI = "hin"
267
+ CROATIAN = "hrv"
268
+ BELARUSIAN = "bel"
269
+ GEORGIAN = "geo"
270
+ TELUGU = "tel"
271
+ KAZAKH = "kaz"
272
+ WARAY = "war"
273
+ LITHUANIAN = "lit"
274
+ SCOTTISH = "glg"
275
+ SLOVAK = "slo"
276
+ BENIN = "ben"
277
+ BASQUE = "baq"
278
+ SLOVENIAN = "slv"
279
+ MALAYALAM = "mal"
280
+ MARATHI = "mar"
281
+ ESTONIAN = "est"
282
+ AZERBAIJANI = "aze"
283
+ ALBANIAN = "alb"
284
+ LATIN = "lat"
285
+ BOSNIAN = "bos"
286
+ NORWEGIAN_NOVOSIBIRSK = "nno"
287
+ URDU = "urd"
288
+ NOT_DEFINED = "nn"
286
289
 
287
290
 
288
291
  @object_types_registry.register("DatasetType")
289
292
  class DatasetType(ObjectTypes):
290
293
  """Dataset types"""
291
294
 
292
- object_detection = "object_detection"
293
- sequence_classification = "sequence_classification"
294
- token_classification = "token_classification"
295
- publaynet = "publaynet"
295
+ OBJECT_DETECTION = "object_detection"
296
+ SEQUENCE_CLASSIFICATION = "sequence_classification"
297
+ TOKEN_CLASSIFICATION = "token_classification"
298
+ PUBLAYNET = "publaynet"
299
+ DEFAULT = "default"
296
300
 
297
301
 
298
302
  _TOKEN_AND_TAG_TO_TOKEN_CLASS_WITH_TAG = {
299
- (TokenClasses.header, BioTag.begin): TokenClassWithTag.b_header,
300
- (TokenClasses.header, BioTag.inside): TokenClassWithTag.i_header,
301
- (TokenClasses.header, BioTag.end): TokenClassWithTag.e_header,
302
- (TokenClasses.header, BioTag.single): TokenClassWithTag.s_header,
303
- (TokenClasses.answer, BioTag.begin): TokenClassWithTag.b_answer,
304
- (TokenClasses.answer, BioTag.inside): TokenClassWithTag.i_answer,
305
- (TokenClasses.answer, BioTag.end): TokenClassWithTag.e_answer,
306
- (TokenClasses.answer, BioTag.single): TokenClassWithTag.s_answer,
307
- (TokenClasses.question, BioTag.begin): TokenClassWithTag.b_question,
308
- (TokenClasses.question, BioTag.inside): TokenClassWithTag.i_question,
309
- (TokenClasses.question, BioTag.end): TokenClassWithTag.e_question,
310
- (TokenClasses.question, BioTag.single): TokenClassWithTag.s_question,
311
- (TokenClasses.other, BioTag.outside): BioTag.outside,
312
- (TokenClasses.header, BioTag.outside): BioTag.outside,
313
- (TokenClasses.answer, BioTag.outside): BioTag.outside,
314
- (TokenClasses.question, BioTag.outside): BioTag.outside,
303
+ (TokenClasses.HEADER, BioTag.BEGIN): TokenClassWithTag.B_HEADER,
304
+ (TokenClasses.HEADER, BioTag.INSIDE): TokenClassWithTag.I_HEADER,
305
+ (TokenClasses.HEADER, BioTag.END): TokenClassWithTag.E_HEADER,
306
+ (TokenClasses.HEADER, BioTag.SINGLE): TokenClassWithTag.S_HEADER,
307
+ (TokenClasses.ANSWER, BioTag.BEGIN): TokenClassWithTag.B_ANSWER,
308
+ (TokenClasses.ANSWER, BioTag.INSIDE): TokenClassWithTag.I_ANSWER,
309
+ (TokenClasses.ANSWER, BioTag.END): TokenClassWithTag.E_ANSWER,
310
+ (TokenClasses.ANSWER, BioTag.SINGLE): TokenClassWithTag.S_ANSWER,
311
+ (TokenClasses.QUESTION, BioTag.BEGIN): TokenClassWithTag.B_QUESTION,
312
+ (TokenClasses.QUESTION, BioTag.INSIDE): TokenClassWithTag.I_QUESTION,
313
+ (TokenClasses.QUESTION, BioTag.END): TokenClassWithTag.E_QUESTION,
314
+ (TokenClasses.QUESTION, BioTag.SINGLE): TokenClassWithTag.S_QUESTION,
315
+ (TokenClasses.OTHER, BioTag.OUTSIDE): BioTag.OUTSIDE,
316
+ (TokenClasses.HEADER, BioTag.OUTSIDE): BioTag.OUTSIDE,
317
+ (TokenClasses.ANSWER, BioTag.OUTSIDE): BioTag.OUTSIDE,
318
+ (TokenClasses.QUESTION, BioTag.OUTSIDE): BioTag.OUTSIDE,
315
319
  }
316
320
 
317
321
 
@@ -333,7 +337,7 @@ def token_class_tag_to_token_class_with_tag(token: ObjectTypes, tag: ObjectTypes
333
337
 
334
338
  def token_class_with_tag_to_token_class_and_tag(
335
339
  token_class_with_tag: ObjectTypes,
336
- ) -> Optional[Tuple[ObjectTypes, ObjectTypes]]:
340
+ ) -> Optional[tuple[ObjectTypes, ObjectTypes]]:
337
341
  """
338
342
  This is the reverse mapping from TokenClassWithTag members to TokenClasses and BioTag
339
343
 
@@ -357,7 +361,7 @@ def update_all_types_dict() -> None:
357
361
  _ALL_TYPES_DICT.update({e.value: e for e in obj})
358
362
 
359
363
 
360
- _OLD_TO_NEW_OBJ_TYPE: Dict[str, str] = {
364
+ _OLD_TO_NEW_OBJ_TYPE: dict[str, str] = {
361
365
  "DOC_CLASS": "document_type",
362
366
  "CHARS": "characters",
363
367
  "BIO_TAG": "tag",
@@ -380,10 +384,10 @@ def _get_new_obj_type_str(obj_type: str) -> str:
380
384
  return _OLD_TO_NEW_OBJ_TYPE.get(obj_type, obj_type)
381
385
 
382
386
 
383
- _BLACK_LIST: List[str] = ["B", "I", "O", "E", "S"]
387
+ _BLACK_LIST: list[str] = ["B", "I", "O", "E", "S"]
384
388
 
385
389
 
386
- def _get_black_list() -> List[str]:
390
+ def _get_black_list() -> list[str]:
387
391
  return _BLACK_LIST
388
392
 
389
393
 
@@ -23,7 +23,7 @@ from typing import Dict, Optional, Union
23
23
 
24
24
  from tqdm import tqdm
25
25
 
26
- from .detection_types import TqdmType
26
+ from .types import TqdmType
27
27
 
28
28
  __all__ = ["get_tqdm", "get_tqdm_default_kwargs"]
29
29
 
@@ -21,6 +21,8 @@ of coordinates. Most have the ideas have been taken from
21
21
  <https://github.com/tensorpack/dataflow/blob/master/dataflow/dataflow/imgaug/transform.py> .
22
22
  """
23
23
 
24
+ from __future__ import annotations
25
+
24
26
  from abc import ABC, abstractmethod
25
27
  from typing import Literal, Optional, Union
26
28
 
@@ -28,7 +30,7 @@ import numpy as np
28
30
  import numpy.typing as npt
29
31
  from numpy import float32
30
32
 
31
- from .detection_types import ImageType
33
+ from .types import PixelValues
32
34
  from .viz import viz_handler
33
35
 
34
36
  __all__ = ["ResizeTransform", "InferenceResize", "PadTransform", "normalize_image"]
@@ -45,7 +47,7 @@ class BaseTransform(ABC):
45
47
  """
46
48
 
47
49
  @abstractmethod
48
- def apply_image(self, img: ImageType) -> ImageType:
50
+ def apply_image(self, img: PixelValues) -> PixelValues:
49
51
  """The transformation that should be applied to the image"""
50
52
  raise NotImplementedError()
51
53
 
@@ -77,7 +79,7 @@ class ResizeTransform(BaseTransform):
77
79
  self.new_w = int(new_w)
78
80
  self.interp = interp
79
81
 
80
- def apply_image(self, img: ImageType) -> ImageType:
82
+ def apply_image(self, img: PixelValues) -> PixelValues:
81
83
  assert img.shape[:2] == (self.h, self.w)
82
84
  ret = viz_handler.resize(img, self.new_w, self.new_h, self.interp)
83
85
  if img.ndim == 3 and ret.ndim == 2:
@@ -85,7 +87,8 @@ class ResizeTransform(BaseTransform):
85
87
  return ret
86
88
 
87
89
  def apply_coords(self, coords: npt.NDArray[float32]) -> npt.NDArray[float32]:
88
- """Transformation that should be applied to coordinates"""
90
+ """Transformation that should be applied to coordinates. Coords are supposed to to be passed as
91
+ np array of points"""
89
92
  coords[:, 0] = coords[:, 0] * (self.new_w * 1.0 / self.w)
90
93
  coords[:, 1] = coords[:, 1] * (self.new_h * 1.0 / self.h)
91
94
  return coords
@@ -106,7 +109,7 @@ class InferenceResize:
106
109
  self.max_size = max_size
107
110
  self.interp = interp
108
111
 
109
- def get_transform(self, img: ImageType) -> ResizeTransform:
112
+ def get_transform(self, img: PixelValues) -> ResizeTransform:
110
113
  """
111
114
  get transform
112
115
  """
@@ -129,7 +132,9 @@ class InferenceResize:
129
132
  return ResizeTransform(h, w, new_h, new_w, self.interp)
130
133
 
131
134
 
132
- def normalize_image(image: ImageType, pixel_mean: npt.NDArray[float32], pixel_std: npt.NDArray[float32]) -> ImageType:
135
+ def normalize_image(
136
+ image: PixelValues, pixel_mean: npt.NDArray[float32], pixel_std: npt.NDArray[float32]
137
+ ) -> PixelValues:
133
138
  """
134
139
  Preprocess pixel values of an image by rescaling.
135
140
 
@@ -140,7 +145,7 @@ def normalize_image(image: ImageType, pixel_mean: npt.NDArray[float32], pixel_st
140
145
  return (image - pixel_mean) * (1.0 / pixel_std)
141
146
 
142
147
 
143
- def pad_image(image: ImageType, top: int, right: int, bottom: int, left: int) -> ImageType:
148
+ def pad_image(image: PixelValues, top: int, right: int, bottom: int, left: int) -> PixelValues:
144
149
  """Pad an image with white color and with given top/bottom/right/left pixel values. Only white padding is
145
150
  currently supported
146
151
 
@@ -181,7 +186,7 @@ class PadTransform(BaseTransform):
181
186
  self.image_height: Optional[int] = None
182
187
  self.mode = mode
183
188
 
184
- def apply_image(self, img: ImageType) -> ImageType:
189
+ def apply_image(self, img: PixelValues) -> PixelValues:
185
190
  """Apply padding to image"""
186
191
  self.image_width = img.shape[1]
187
192
  self.image_height = img.shape[0]
@@ -214,6 +219,6 @@ class PadTransform(BaseTransform):
214
219
  coords[:, 1] = np.maximum(coords[:, 1] - self.top, np.zeros(coords[:, 1].shape))
215
220
  return coords
216
221
 
217
- def clone(self) -> "PadTransform":
222
+ def clone(self) -> PadTransform:
218
223
  """clone"""
219
224
  return self.__class__(self.top, self.right, self.bottom, self.left, self.mode)