deepdoctection 0.33__py3-none-any.whl → 0.35__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 +11 -12
- deepdoctection/analyzer/__init__.py +1 -0
- deepdoctection/analyzer/_config.py +150 -0
- deepdoctection/analyzer/dd.py +42 -358
- deepdoctection/analyzer/factory.py +522 -0
- deepdoctection/configs/conf_dd_one.yaml +1 -0
- deepdoctection/datapoint/annotation.py +41 -3
- deepdoctection/datapoint/convert.py +6 -4
- deepdoctection/datapoint/image.py +132 -46
- deepdoctection/datapoint/view.py +2 -1
- deepdoctection/datasets/base.py +1 -1
- deepdoctection/datasets/instances/fintabnet.py +1 -1
- deepdoctection/datasets/instances/xfund.py +29 -7
- deepdoctection/eval/eval.py +7 -1
- deepdoctection/extern/model.py +2 -1
- deepdoctection/extern/pdftext.py +96 -5
- deepdoctection/extern/tessocr.py +1 -0
- deepdoctection/mapper/cats.py +11 -13
- deepdoctection/mapper/cocostruct.py +6 -2
- deepdoctection/mapper/d2struct.py +2 -1
- deepdoctection/mapper/laylmstruct.py +1 -1
- deepdoctection/mapper/match.py +31 -0
- deepdoctection/mapper/misc.py +1 -1
- deepdoctection/mapper/prodigystruct.py +1 -1
- deepdoctection/pipe/anngen.py +27 -0
- deepdoctection/pipe/base.py +23 -0
- deepdoctection/pipe/common.py +123 -38
- deepdoctection/pipe/segment.py +1 -1
- deepdoctection/pipe/sub_layout.py +1 -1
- deepdoctection/utils/env_info.py +31 -2
- deepdoctection/utils/file_utils.py +19 -0
- deepdoctection/utils/fs.py +27 -4
- deepdoctection/utils/metacfg.py +12 -0
- deepdoctection/utils/pdf_utils.py +114 -6
- deepdoctection/utils/settings.py +3 -0
- {deepdoctection-0.33.dist-info → deepdoctection-0.35.dist-info}/METADATA +20 -11
- {deepdoctection-0.33.dist-info → deepdoctection-0.35.dist-info}/RECORD +40 -38
- {deepdoctection-0.33.dist-info → deepdoctection-0.35.dist-info}/WHEEL +1 -1
- {deepdoctection-0.33.dist-info → deepdoctection-0.35.dist-info}/LICENSE +0 -0
- {deepdoctection-0.33.dist-info → deepdoctection-0.35.dist-info}/top_level.txt +0 -0
deepdoctection/__init__.py
CHANGED
|
@@ -15,30 +15,22 @@ if importlib.util.find_spec("dotenv") is not None:
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
# pylint: disable=wrong-import-position
|
|
18
|
-
import os
|
|
19
18
|
import sys
|
|
20
19
|
from typing import TYPE_CHECKING
|
|
21
20
|
|
|
22
|
-
from .utils.env_info import collect_env_info
|
|
21
|
+
from .utils.env_info import auto_select_pdf_render_framework, collect_env_info
|
|
23
22
|
from .utils.file_utils import _LazyModule, get_tf_version, pytorch_available, tf_available
|
|
24
23
|
from .utils.logger import LoggingRecord, logger
|
|
25
24
|
|
|
26
25
|
# pylint: enable=wrong-import-position
|
|
27
26
|
|
|
28
|
-
__version__ = 0.
|
|
27
|
+
__version__ = 0.35
|
|
29
28
|
|
|
30
29
|
_IMPORT_STRUCTURE = {
|
|
31
30
|
"analyzer": [
|
|
32
|
-
"maybe_copy_config_to_cache",
|
|
33
31
|
"config_sanity_checks",
|
|
34
|
-
"build_detector",
|
|
35
|
-
"build_padder",
|
|
36
|
-
"build_service",
|
|
37
|
-
"build_sub_image_service",
|
|
38
|
-
"build_ocr",
|
|
39
|
-
"build_doctr_word",
|
|
40
32
|
"get_dd_analyzer",
|
|
41
|
-
"
|
|
33
|
+
"ServiceFactory"
|
|
42
34
|
],
|
|
43
35
|
"configs": [],
|
|
44
36
|
"dataflow": [
|
|
@@ -76,6 +68,7 @@ _IMPORT_STRUCTURE = {
|
|
|
76
68
|
],
|
|
77
69
|
"datapoint": [
|
|
78
70
|
"ann_from_dict",
|
|
71
|
+
"AnnotationMap",
|
|
79
72
|
"Annotation",
|
|
80
73
|
"CategoryAnnotation",
|
|
81
74
|
"ImageAnnotation",
|
|
@@ -198,6 +191,7 @@ _IMPORT_STRUCTURE = {
|
|
|
198
191
|
"print_model_infos",
|
|
199
192
|
"ModelDownloadManager",
|
|
200
193
|
"PdfPlumberTextDetector",
|
|
194
|
+
"Pdfmium2TextDetector",
|
|
201
195
|
"TesseractOcrDetector",
|
|
202
196
|
"TesseractRotationTransformer",
|
|
203
197
|
"TextractOcrDetector",
|
|
@@ -237,6 +231,7 @@ _IMPORT_STRUCTURE = {
|
|
|
237
231
|
"LabelSummarizer",
|
|
238
232
|
"curry",
|
|
239
233
|
"match_anns_by_intersection",
|
|
234
|
+
"match_anns_by_distance",
|
|
240
235
|
"to_image",
|
|
241
236
|
"maybe_load_image",
|
|
242
237
|
"maybe_remove_image",
|
|
@@ -265,6 +260,8 @@ _IMPORT_STRUCTURE = {
|
|
|
265
260
|
"DetectResultGenerator",
|
|
266
261
|
"SubImageLayoutService",
|
|
267
262
|
"ImageCroppingService",
|
|
263
|
+
"IntersectionMatcher",
|
|
264
|
+
"NeighbourMatcher",
|
|
268
265
|
"MatchingService",
|
|
269
266
|
"PageParsingService",
|
|
270
267
|
"AnnotationNmsService",
|
|
@@ -302,6 +299,7 @@ _IMPORT_STRUCTURE = {
|
|
|
302
299
|
"timed_operation",
|
|
303
300
|
"collect_env_info",
|
|
304
301
|
"auto_select_viz_library",
|
|
302
|
+
"auto_select_pdf_render_framework",
|
|
305
303
|
"get_tensorflow_requirement",
|
|
306
304
|
"tf_addons_available",
|
|
307
305
|
"get_tf_addons_requirements",
|
|
@@ -364,6 +362,7 @@ _IMPORT_STRUCTURE = {
|
|
|
364
362
|
"get_configs_dir_path",
|
|
365
363
|
"get_weights_dir_path",
|
|
366
364
|
"get_dataset_dir_path",
|
|
365
|
+
"maybe_copy_config_to_cache",
|
|
367
366
|
"is_uuid_like",
|
|
368
367
|
"get_uuid_from_str",
|
|
369
368
|
"get_uuid",
|
|
@@ -424,7 +423,7 @@ _IMPORT_STRUCTURE = {
|
|
|
424
423
|
# Setting some environment variables so that standard functions can be invoked with available hardware
|
|
425
424
|
env_info = collect_env_info()
|
|
426
425
|
logger.debug(LoggingRecord(msg=env_info))
|
|
427
|
-
|
|
426
|
+
auto_select_pdf_render_framework()
|
|
428
427
|
|
|
429
428
|
# Direct imports for type-checking
|
|
430
429
|
if TYPE_CHECKING:
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# File: config.py
|
|
3
|
+
|
|
4
|
+
# Copyright 2024 Dr. Janis Meyer. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
"""Pipeline configuration for deepdoctection analyzer. Do not change the defaults in this file. """
|
|
19
|
+
|
|
20
|
+
from ..utils.metacfg import AttrDict
|
|
21
|
+
from ..utils.settings import CellType, LayoutType
|
|
22
|
+
|
|
23
|
+
cfg = AttrDict()
|
|
24
|
+
|
|
25
|
+
cfg.LANGUAGE = None
|
|
26
|
+
cfg.LIB = None
|
|
27
|
+
cfg.DEVICE = None
|
|
28
|
+
cfg.USE_ROTATOR = False
|
|
29
|
+
cfg.USE_LAYOUT = True
|
|
30
|
+
cfg.USE_TABLE_SEGMENTATION = True
|
|
31
|
+
|
|
32
|
+
cfg.TF.LAYOUT.WEIGHTS = "layout/model-800000_inf_only.data-00000-of-00001"
|
|
33
|
+
cfg.TF.LAYOUT.FILTER = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
cfg.TF.CELL.WEIGHTS = "cell/model-1800000_inf_only.data-00000-of-00001"
|
|
37
|
+
cfg.TF.CELL.FILTER = None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
cfg.TF.ITEM.WEIGHTS = "item/model-1620000_inf_only.data-00000-of-00001"
|
|
41
|
+
cfg.TF.ITEM.FILTER = None
|
|
42
|
+
|
|
43
|
+
cfg.PT.LAYOUT.WEIGHTS = "layout/d2_model_0829999_layout_inf_only.pt"
|
|
44
|
+
cfg.PT.LAYOUT.WEIGHTS_TS = "layout/d2_model_0829999_layout_inf_only.ts"
|
|
45
|
+
cfg.PT.LAYOUT.FILTER = None
|
|
46
|
+
cfg.PT.LAYOUT.PAD.TOP = 60
|
|
47
|
+
cfg.PT.LAYOUT.PAD.RIGHT = 60
|
|
48
|
+
cfg.PT.LAYOUT.PAD.BOTTOM = 60
|
|
49
|
+
cfg.PT.LAYOUT.PAD.LEFT = 60
|
|
50
|
+
|
|
51
|
+
cfg.PT.ITEM.WEIGHTS = "item/d2_model_1639999_item_inf_only.pt"
|
|
52
|
+
cfg.PT.ITEM.WEIGHTS_TS = "item/d2_model_1639999_item_inf_only.ts"
|
|
53
|
+
cfg.PT.ITEM.FILTER = None
|
|
54
|
+
cfg.PT.ITEM.PAD.TOP = 60
|
|
55
|
+
cfg.PT.ITEM.PAD.RIGHT = 60
|
|
56
|
+
cfg.PT.ITEM.PAD.BOTTOM = 60
|
|
57
|
+
cfg.PT.ITEM.PAD.LEFT = 60
|
|
58
|
+
|
|
59
|
+
cfg.PT.CELL.WEIGHTS = "cell/d2_model_1849999_cell_inf_only.pt"
|
|
60
|
+
cfg.PT.CELL.WEIGHTS_TS = "cell/d2_model_1849999_cell_inf_only.ts"
|
|
61
|
+
cfg.PT.CELL.FILTER = None
|
|
62
|
+
|
|
63
|
+
cfg.USE_LAYOUT_NMS = False
|
|
64
|
+
cfg.LAYOUT_NMS_PAIRS.COMBINATIONS = None
|
|
65
|
+
cfg.LAYOUT_NMS_PAIRS.THRESHOLDS = None
|
|
66
|
+
cfg.LAYOUT_NMS_PAIRS.PRIORITY = None
|
|
67
|
+
|
|
68
|
+
cfg.SEGMENTATION.ASSIGNMENT_RULE = "ioa"
|
|
69
|
+
cfg.SEGMENTATION.THRESHOLD_ROWS = 0.4
|
|
70
|
+
cfg.SEGMENTATION.THRESHOLD_COLS = 0.4
|
|
71
|
+
cfg.SEGMENTATION.FULL_TABLE_TILING = True
|
|
72
|
+
cfg.SEGMENTATION.REMOVE_IOU_THRESHOLD_ROWS = 0.001
|
|
73
|
+
cfg.SEGMENTATION.REMOVE_IOU_THRESHOLD_COLS = 0.001
|
|
74
|
+
cfg.SEGMENTATION.CELL_CATEGORY_ID = 12
|
|
75
|
+
cfg.SEGMENTATION.TABLE_NAME = LayoutType.TABLE
|
|
76
|
+
cfg.SEGMENTATION.PUBTABLES_CELL_NAMES = [
|
|
77
|
+
CellType.SPANNING,
|
|
78
|
+
CellType.ROW_HEADER,
|
|
79
|
+
CellType.COLUMN_HEADER,
|
|
80
|
+
CellType.PROJECTED_ROW_HEADER,
|
|
81
|
+
LayoutType.CELL,
|
|
82
|
+
]
|
|
83
|
+
cfg.SEGMENTATION.PUBTABLES_SPANNING_CELL_NAMES = [
|
|
84
|
+
CellType.SPANNING,
|
|
85
|
+
CellType.ROW_HEADER,
|
|
86
|
+
CellType.COLUMN_HEADER,
|
|
87
|
+
CellType.PROJECTED_ROW_HEADER,
|
|
88
|
+
]
|
|
89
|
+
cfg.SEGMENTATION.PUBTABLES_ITEM_NAMES = [LayoutType.ROW, LayoutType.COLUMN]
|
|
90
|
+
cfg.SEGMENTATION.PUBTABLES_SUB_ITEM_NAMES = [CellType.ROW_NUMBER, CellType.COLUMN_NUMBER]
|
|
91
|
+
cfg.SEGMENTATION.CELL_NAMES = [CellType.HEADER, CellType.BODY, LayoutType.CELL]
|
|
92
|
+
cfg.SEGMENTATION.ITEM_NAMES = [LayoutType.ROW, LayoutType.COLUMN]
|
|
93
|
+
cfg.SEGMENTATION.SUB_ITEM_NAMES = [CellType.ROW_NUMBER, CellType.COLUMN_NUMBER]
|
|
94
|
+
|
|
95
|
+
cfg.SEGMENTATION.STRETCH_RULE = "equal"
|
|
96
|
+
|
|
97
|
+
cfg.USE_TABLE_REFINEMENT = True
|
|
98
|
+
cfg.USE_PDF_MINER = False
|
|
99
|
+
|
|
100
|
+
cfg.PDF_MINER.X_TOLERANCE = 3
|
|
101
|
+
cfg.PDF_MINER.Y_TOLERANCE = 3
|
|
102
|
+
|
|
103
|
+
cfg.USE_OCR = True
|
|
104
|
+
|
|
105
|
+
cfg.OCR.USE_TESSERACT = True
|
|
106
|
+
cfg.OCR.USE_DOCTR = False
|
|
107
|
+
cfg.OCR.USE_TEXTRACT = False
|
|
108
|
+
cfg.OCR.CONFIG.TESSERACT = "dd/conf_tesseract.yaml"
|
|
109
|
+
|
|
110
|
+
cfg.OCR.WEIGHTS.DOCTR_WORD.TF = "doctr/db_resnet50/tf/db_resnet50-adcafc63.zip"
|
|
111
|
+
cfg.OCR.WEIGHTS.DOCTR_WORD.PT = "doctr/db_resnet50/pt/db_resnet50-ac60cadc.pt"
|
|
112
|
+
cfg.OCR.WEIGHTS.DOCTR_RECOGNITION.TF = "doctr/crnn_vgg16_bn/tf/crnn_vgg16_bn-76b7f2c6.zip"
|
|
113
|
+
cfg.OCR.WEIGHTS.DOCTR_RECOGNITION.PT = "doctr/crnn_vgg16_bn/pt/crnn_vgg16_bn-9762b0b0.pt"
|
|
114
|
+
|
|
115
|
+
cfg.TEXT_CONTAINER = LayoutType.WORD
|
|
116
|
+
cfg.WORD_MATCHING.PARENTAL_CATEGORIES = [
|
|
117
|
+
LayoutType.TEXT,
|
|
118
|
+
LayoutType.TITLE,
|
|
119
|
+
LayoutType.LIST,
|
|
120
|
+
LayoutType.CELL,
|
|
121
|
+
CellType.COLUMN_HEADER,
|
|
122
|
+
CellType.PROJECTED_ROW_HEADER,
|
|
123
|
+
CellType.SPANNING,
|
|
124
|
+
CellType.ROW_HEADER,
|
|
125
|
+
]
|
|
126
|
+
cfg.WORD_MATCHING.RULE = "ioa"
|
|
127
|
+
cfg.WORD_MATCHING.THRESHOLD = 0.6
|
|
128
|
+
cfg.WORD_MATCHING.MAX_PARENT_ONLY = True
|
|
129
|
+
|
|
130
|
+
cfg.TEXT_ORDERING.TEXT_BLOCK_CATEGORIES = [
|
|
131
|
+
LayoutType.TEXT,
|
|
132
|
+
LayoutType.TITLE,
|
|
133
|
+
LayoutType.LIST,
|
|
134
|
+
LayoutType.CELL,
|
|
135
|
+
CellType.COLUMN_HEADER,
|
|
136
|
+
CellType.PROJECTED_ROW_HEADER,
|
|
137
|
+
CellType.SPANNING,
|
|
138
|
+
CellType.ROW_HEADER,
|
|
139
|
+
]
|
|
140
|
+
cfg.TEXT_ORDERING.FLOATING_TEXT_BLOCK_CATEGORIES = [
|
|
141
|
+
LayoutType.TEXT,
|
|
142
|
+
LayoutType.TITLE,
|
|
143
|
+
LayoutType.LIST,
|
|
144
|
+
]
|
|
145
|
+
cfg.TEXT_ORDERING.INCLUDE_RESIDUAL_TEXT_CONTAINER = False
|
|
146
|
+
cfg.TEXT_ORDERING.STARTING_POINT_TOLERANCE = 0.005
|
|
147
|
+
cfg.TEXT_ORDERING.BROKEN_LINE_TOLERANCE = 0.003
|
|
148
|
+
cfg.TEXT_ORDERING.HEIGHT_TOLERANCE = 2.0
|
|
149
|
+
cfg.TEXT_ORDERING.PARAGRAPH_BREAK = 0.035
|
|
150
|
+
cfg.freeze()
|