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.
- deepdoctection/__init__.py +16 -29
- deepdoctection/analyzer/dd.py +70 -59
- deepdoctection/configs/conf_dd_one.yaml +34 -31
- deepdoctection/dataflow/common.py +9 -5
- deepdoctection/dataflow/custom.py +5 -5
- deepdoctection/dataflow/custom_serialize.py +75 -18
- deepdoctection/dataflow/parallel_map.py +3 -3
- deepdoctection/dataflow/serialize.py +4 -4
- deepdoctection/dataflow/stats.py +3 -3
- deepdoctection/datapoint/annotation.py +41 -56
- deepdoctection/datapoint/box.py +9 -8
- deepdoctection/datapoint/convert.py +6 -6
- deepdoctection/datapoint/image.py +56 -44
- deepdoctection/datapoint/view.py +245 -150
- deepdoctection/datasets/__init__.py +1 -4
- deepdoctection/datasets/adapter.py +35 -26
- deepdoctection/datasets/base.py +14 -12
- deepdoctection/datasets/dataflow_builder.py +3 -3
- deepdoctection/datasets/info.py +24 -26
- deepdoctection/datasets/instances/doclaynet.py +51 -51
- deepdoctection/datasets/instances/fintabnet.py +46 -46
- deepdoctection/datasets/instances/funsd.py +25 -24
- deepdoctection/datasets/instances/iiitar13k.py +13 -10
- deepdoctection/datasets/instances/layouttest.py +4 -3
- deepdoctection/datasets/instances/publaynet.py +5 -5
- deepdoctection/datasets/instances/pubtables1m.py +24 -21
- deepdoctection/datasets/instances/pubtabnet.py +32 -30
- deepdoctection/datasets/instances/rvlcdip.py +30 -30
- deepdoctection/datasets/instances/xfund.py +26 -26
- deepdoctection/datasets/save.py +6 -6
- deepdoctection/eval/__init__.py +1 -4
- deepdoctection/eval/accmetric.py +32 -33
- deepdoctection/eval/base.py +8 -9
- deepdoctection/eval/cocometric.py +15 -13
- deepdoctection/eval/eval.py +41 -37
- deepdoctection/eval/tedsmetric.py +30 -23
- deepdoctection/eval/tp_eval_callback.py +16 -19
- deepdoctection/extern/__init__.py +2 -7
- deepdoctection/extern/base.py +339 -134
- deepdoctection/extern/d2detect.py +85 -113
- deepdoctection/extern/deskew.py +14 -11
- deepdoctection/extern/doctrocr.py +141 -130
- deepdoctection/extern/fastlang.py +27 -18
- deepdoctection/extern/hfdetr.py +71 -62
- deepdoctection/extern/hflayoutlm.py +504 -211
- deepdoctection/extern/hflm.py +230 -0
- deepdoctection/extern/model.py +488 -302
- deepdoctection/extern/pdftext.py +23 -19
- deepdoctection/extern/pt/__init__.py +1 -3
- deepdoctection/extern/pt/nms.py +6 -2
- deepdoctection/extern/pt/ptutils.py +29 -19
- deepdoctection/extern/tessocr.py +39 -38
- deepdoctection/extern/texocr.py +18 -18
- deepdoctection/extern/tp/tfutils.py +57 -9
- deepdoctection/extern/tp/tpcompat.py +21 -14
- deepdoctection/extern/tp/tpfrcnn/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/common.py +7 -3
- deepdoctection/extern/tp/tpfrcnn/config/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/config/config.py +13 -10
- deepdoctection/extern/tp/tpfrcnn/modeling/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/modeling/backbone.py +18 -8
- deepdoctection/extern/tp/tpfrcnn/modeling/generalized_rcnn.py +12 -6
- deepdoctection/extern/tp/tpfrcnn/modeling/model_box.py +14 -9
- deepdoctection/extern/tp/tpfrcnn/modeling/model_cascade.py +8 -5
- deepdoctection/extern/tp/tpfrcnn/modeling/model_fpn.py +22 -17
- deepdoctection/extern/tp/tpfrcnn/modeling/model_frcnn.py +21 -14
- deepdoctection/extern/tp/tpfrcnn/modeling/model_mrcnn.py +19 -11
- deepdoctection/extern/tp/tpfrcnn/modeling/model_rpn.py +15 -10
- deepdoctection/extern/tp/tpfrcnn/predict.py +9 -4
- deepdoctection/extern/tp/tpfrcnn/preproc.py +12 -8
- deepdoctection/extern/tp/tpfrcnn/utils/__init__.py +20 -0
- deepdoctection/extern/tp/tpfrcnn/utils/box_ops.py +10 -2
- deepdoctection/extern/tpdetect.py +45 -53
- deepdoctection/mapper/__init__.py +3 -8
- deepdoctection/mapper/cats.py +27 -29
- deepdoctection/mapper/cocostruct.py +10 -10
- deepdoctection/mapper/d2struct.py +27 -26
- deepdoctection/mapper/hfstruct.py +13 -8
- deepdoctection/mapper/laylmstruct.py +178 -37
- deepdoctection/mapper/maputils.py +12 -11
- deepdoctection/mapper/match.py +2 -2
- deepdoctection/mapper/misc.py +11 -9
- deepdoctection/mapper/pascalstruct.py +4 -4
- deepdoctection/mapper/prodigystruct.py +5 -5
- deepdoctection/mapper/pubstruct.py +84 -92
- deepdoctection/mapper/tpstruct.py +5 -5
- deepdoctection/mapper/xfundstruct.py +33 -33
- deepdoctection/pipe/__init__.py +1 -1
- deepdoctection/pipe/anngen.py +12 -14
- deepdoctection/pipe/base.py +52 -106
- deepdoctection/pipe/common.py +72 -59
- deepdoctection/pipe/concurrency.py +16 -11
- deepdoctection/pipe/doctectionpipe.py +24 -21
- deepdoctection/pipe/language.py +20 -25
- deepdoctection/pipe/layout.py +20 -16
- deepdoctection/pipe/lm.py +75 -105
- deepdoctection/pipe/order.py +194 -89
- deepdoctection/pipe/refine.py +111 -124
- deepdoctection/pipe/segment.py +156 -161
- deepdoctection/pipe/{cell.py → sub_layout.py} +50 -40
- deepdoctection/pipe/text.py +37 -36
- deepdoctection/pipe/transform.py +19 -16
- deepdoctection/train/__init__.py +6 -12
- deepdoctection/train/d2_frcnn_train.py +48 -41
- deepdoctection/train/hf_detr_train.py +41 -30
- deepdoctection/train/hf_layoutlm_train.py +153 -135
- deepdoctection/train/tp_frcnn_train.py +32 -31
- deepdoctection/utils/concurrency.py +1 -1
- deepdoctection/utils/context.py +13 -6
- deepdoctection/utils/develop.py +4 -4
- deepdoctection/utils/env_info.py +87 -125
- deepdoctection/utils/file_utils.py +6 -11
- deepdoctection/utils/fs.py +22 -18
- deepdoctection/utils/identifier.py +2 -2
- deepdoctection/utils/logger.py +16 -15
- deepdoctection/utils/metacfg.py +7 -7
- deepdoctection/utils/mocks.py +93 -0
- deepdoctection/utils/pdf_utils.py +11 -11
- deepdoctection/utils/settings.py +185 -181
- deepdoctection/utils/tqdm.py +1 -1
- deepdoctection/utils/transform.py +14 -9
- deepdoctection/utils/types.py +104 -0
- deepdoctection/utils/utils.py +7 -7
- deepdoctection/utils/viz.py +74 -72
- {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/METADATA +30 -21
- deepdoctection-0.33.dist-info/RECORD +146 -0
- {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/WHEEL +1 -1
- deepdoctection/utils/detection_types.py +0 -68
- deepdoctection-0.31.dist-info/RECORD +0 -144
- {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/LICENSE +0 -0
- {deepdoctection-0.31.dist-info → deepdoctection-0.33.dist-info}/top_level.txt +0 -0
deepdoctection/utils/settings.py
CHANGED
|
@@ -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
|
|
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) ->
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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.
|
|
300
|
-
(TokenClasses.
|
|
301
|
-
(TokenClasses.
|
|
302
|
-
(TokenClasses.
|
|
303
|
-
(TokenClasses.
|
|
304
|
-
(TokenClasses.
|
|
305
|
-
(TokenClasses.
|
|
306
|
-
(TokenClasses.
|
|
307
|
-
(TokenClasses.
|
|
308
|
-
(TokenClasses.
|
|
309
|
-
(TokenClasses.
|
|
310
|
-
(TokenClasses.
|
|
311
|
-
(TokenClasses.
|
|
312
|
-
(TokenClasses.
|
|
313
|
-
(TokenClasses.
|
|
314
|
-
(TokenClasses.
|
|
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[
|
|
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:
|
|
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:
|
|
387
|
+
_BLACK_LIST: list[str] = ["B", "I", "O", "E", "S"]
|
|
384
388
|
|
|
385
389
|
|
|
386
|
-
def _get_black_list() ->
|
|
390
|
+
def _get_black_list() -> list[str]:
|
|
387
391
|
return _BLACK_LIST
|
|
388
392
|
|
|
389
393
|
|
deepdoctection/utils/tqdm.py
CHANGED
|
@@ -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 .
|
|
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:
|
|
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:
|
|
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:
|
|
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(
|
|
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:
|
|
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:
|
|
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) ->
|
|
222
|
+
def clone(self) -> PadTransform:
|
|
218
223
|
"""clone"""
|
|
219
224
|
return self.__class__(self.top, self.right, self.bottom, self.left, self.mode)
|