deepdoctection 1.3.0__tar.gz → 1.5.0__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.
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/PKG-INFO +13 -12
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/pyproject.toml +15 -14
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/__init__.py +12 -5
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/config.py +8 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/factory.py +4 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/conf_dd_one.yaml +1 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/__init__.py +1 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/accmetric.py +1 -1
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/eval.py +93 -33
- deepdoctection-1.5.0/src/deepdoctection/eval/record_align.py +579 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/pdftext.py +1 -1
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/anngen.py +4 -2
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/lm.py +3 -3
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/order.py +61 -23
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/segment.py +2 -2
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/train/__init__.py +3 -3
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/PKG-INFO +13 -12
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/SOURCES.txt +1 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/requires.txt +9 -9
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/README.md +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/setup.cfg +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/__init__.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/dd.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/__init__.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/conf_tesseract.yaml +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/profiles.jsonl +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/base.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/cocometric.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/registry.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/tedsmetric.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/__init__.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/base.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/d2detect.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/deskew.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/doctrocr.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/hfdetr.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/hflayoutlm.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/hflm.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/model.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/tessocr.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/texocr.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/__init__.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/base.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/common.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/concurrency.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/doctectionpipe.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/language.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/layout.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/refine.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/registry.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/sub_layout.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/text.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/transform.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/py.typed +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/train/d2_frcnn_train.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/train/hf_detr_train.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection/train/hf_layoutlm_train.py +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/dependency_links.txt +0 -0
- {deepdoctection-1.3.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deepdoctection
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: Repository for Document AI - server/inference core package
|
|
5
5
|
Author: Dr. Janis Meyer
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -11,27 +11,28 @@ Classifier: Development Status :: 4 - Beta
|
|
|
11
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
13
|
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
18
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
-
Requires-Python: >=3.
|
|
19
|
+
Requires-Python: >=3.11
|
|
19
20
|
Description-Content-Type: text/markdown
|
|
20
|
-
Requires-Dist: dd-core[full]>=1.0
|
|
21
|
+
Requires-Dist: dd-core[full]>=1.5.0
|
|
21
22
|
Requires-Dist: huggingface_hub>=1.0
|
|
22
23
|
Provides-Extra: full
|
|
23
|
-
Requires-Dist: dd-datasets[full]>=1.0
|
|
24
|
-
Requires-Dist: boto3
|
|
24
|
+
Requires-Dist: dd-datasets[full]>=1.5.0; extra == "full"
|
|
25
|
+
Requires-Dist: boto3>=1.34.102; extra == "full"
|
|
25
26
|
Requires-Dist: pdfplumber>=0.11.0; extra == "full"
|
|
26
27
|
Requires-Dist: jdeskew>=0.2.2; extra == "full"
|
|
27
28
|
Requires-Dist: networkx>=2.7.1; extra == "full"
|
|
28
29
|
Requires-Dist: apted==1.0.3; extra == "full"
|
|
29
30
|
Requires-Dist: distance==0.1.3; extra == "full"
|
|
30
|
-
Requires-Dist: lxml>=
|
|
31
|
+
Requires-Dist: lxml>=6.1.0; extra == "full"
|
|
31
32
|
Requires-Dist: pycocotools>=2.0.2; extra == "full"
|
|
32
33
|
Requires-Dist: timm>=0.9.16; extra == "full"
|
|
33
|
-
Requires-Dist: transformers>=5.
|
|
34
|
-
Requires-Dist: accelerate>=
|
|
34
|
+
Requires-Dist: transformers>=5.10.0; extra == "full"
|
|
35
|
+
Requires-Dist: accelerate>=1.15.0; extra == "full"
|
|
35
36
|
Requires-Dist: python-doctr>=1.0.0; extra == "full"
|
|
36
37
|
Provides-Extra: types
|
|
37
38
|
Requires-Dist: dd_core[types]; extra == "types"
|
|
@@ -39,7 +40,7 @@ Requires-Dist: lxml-stubs>=0.5.1; extra == "types"
|
|
|
39
40
|
Provides-Extra: dev
|
|
40
41
|
Requires-Dist: black==25.11.0; extra == "dev"
|
|
41
42
|
Requires-Dist: isort==7.0.0; extra == "dev"
|
|
42
|
-
Requires-Dist: pylint==4.0.
|
|
43
|
+
Requires-Dist: pylint==4.0.9; extra == "dev"
|
|
43
44
|
Requires-Dist: mypy==1.4.1; extra == "dev"
|
|
44
45
|
Requires-Dist: types-PyYAML>=6.0.12.12; extra == "dev"
|
|
45
46
|
Requires-Dist: types-termcolor>=1.1.3; extra == "dev"
|
|
@@ -49,10 +50,10 @@ Requires-Dist: types-Pillow>=10.2.0.20240406; extra == "dev"
|
|
|
49
50
|
Requires-Dist: types-urllib3>=1.26.25.14; extra == "dev"
|
|
50
51
|
Requires-Dist: lxml-stubs>=0.5.1; extra == "dev"
|
|
51
52
|
Provides-Extra: test
|
|
52
|
-
Requires-Dist: pytest==9.0.
|
|
53
|
+
Requires-Dist: pytest==9.0.3; extra == "test"
|
|
53
54
|
Requires-Dist: pytest-cov; extra == "test"
|
|
54
55
|
Provides-Extra: docs
|
|
55
|
-
Requires-Dist: mkdocs-material==9.7.
|
|
56
|
+
Requires-Dist: mkdocs-material==9.7.7; extra == "docs"
|
|
56
57
|
Requires-Dist: mkdocstrings-python==1.19.0; extra == "docs"
|
|
57
58
|
Requires-Dist: griffe==1.13; extra == "docs"
|
|
58
59
|
|
|
@@ -4,47 +4,48 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "deepdoctection"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.5.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{name = "Dr. Janis Meyer"}
|
|
10
10
|
]
|
|
11
11
|
description = "Repository for Document AI - server/inference core package"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
license = {text = "Apache License 2.0"}
|
|
14
|
-
requires-python = ">=3.
|
|
14
|
+
requires-python = ">=3.11"
|
|
15
15
|
classifiers = [
|
|
16
16
|
"Development Status :: 4 - Beta",
|
|
17
17
|
"License :: OSI Approved :: Apache Software License",
|
|
18
18
|
"Natural Language :: English",
|
|
19
19
|
"Operating System :: POSIX :: Linux",
|
|
20
|
-
"Programming Language :: Python :: 3.10",
|
|
21
20
|
"Programming Language :: Python :: 3.11",
|
|
22
21
|
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
23
24
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
25
|
]
|
|
25
26
|
|
|
26
27
|
dependencies = [
|
|
27
|
-
"dd-core[full]>=1.0
|
|
28
|
+
"dd-core[full]>=1.5.0",
|
|
28
29
|
"huggingface_hub>=1.0",
|
|
29
30
|
]
|
|
30
31
|
|
|
31
32
|
[project.optional-dependencies]
|
|
32
33
|
full = [
|
|
33
|
-
"dd-datasets[full]>=1.0
|
|
34
|
+
"dd-datasets[full]>=1.5.0",
|
|
34
35
|
# Additional dependencies/ Non DL predictors
|
|
35
|
-
"boto3
|
|
36
|
+
"boto3>=1.34.102",
|
|
36
37
|
"pdfplumber>=0.11.0",
|
|
37
38
|
"jdeskew>=0.2.2",
|
|
38
39
|
"networkx>=2.7.1",
|
|
39
40
|
# Some libs for evals
|
|
40
41
|
"apted==1.0.3",
|
|
41
42
|
"distance==0.1.3",
|
|
42
|
-
"lxml>=
|
|
43
|
+
"lxml>=6.1.0",
|
|
43
44
|
"pycocotools>=2.0.2",
|
|
44
45
|
# DL dependencies
|
|
45
46
|
"timm>=0.9.16",
|
|
46
|
-
"transformers>=5.
|
|
47
|
-
"accelerate>=
|
|
47
|
+
"transformers>=5.10.0",
|
|
48
|
+
"accelerate>=1.15.0",
|
|
48
49
|
"python-doctr>=1.0.0",
|
|
49
50
|
]
|
|
50
51
|
|
|
@@ -56,7 +57,7 @@ types = [
|
|
|
56
57
|
dev = [
|
|
57
58
|
"black==25.11.0",
|
|
58
59
|
"isort==7.0.0",
|
|
59
|
-
"pylint==4.0.
|
|
60
|
+
"pylint==4.0.9",
|
|
60
61
|
"mypy==1.4.1",
|
|
61
62
|
"types-PyYAML>=6.0.12.12",
|
|
62
63
|
"types-termcolor>=1.1.3",
|
|
@@ -68,12 +69,12 @@ dev = [
|
|
|
68
69
|
]
|
|
69
70
|
|
|
70
71
|
test = [
|
|
71
|
-
"pytest==9.0.
|
|
72
|
+
"pytest==9.0.3",
|
|
72
73
|
"pytest-cov",
|
|
73
74
|
]
|
|
74
75
|
|
|
75
76
|
docs = [
|
|
76
|
-
"mkdocs-material==9.7.
|
|
77
|
+
"mkdocs-material==9.7.7",
|
|
77
78
|
"mkdocstrings-python==1.19.0",
|
|
78
79
|
"griffe==1.13"
|
|
79
80
|
]
|
|
@@ -94,14 +95,14 @@ deepdoctection = ["py.typed", "configs/*.yaml", "configs/*.jsonl"]
|
|
|
94
95
|
|
|
95
96
|
[tool.black]
|
|
96
97
|
line-length = 120
|
|
97
|
-
target-version = ['
|
|
98
|
+
target-version = ['py311']
|
|
98
99
|
|
|
99
100
|
[tool.isort]
|
|
100
101
|
profile = "black"
|
|
101
102
|
line_length = 120
|
|
102
103
|
|
|
103
104
|
[tool.mypy]
|
|
104
|
-
python_version = "3.
|
|
105
|
+
python_version = "3.11"
|
|
105
106
|
warn_return_any = true
|
|
106
107
|
warn_unused_configs = true
|
|
107
108
|
ignore_missing_imports = true
|
|
@@ -12,7 +12,7 @@ from dd_core.utils.env_info import collect_env_info
|
|
|
12
12
|
from dd_core.utils.file_utils import _LazyModule
|
|
13
13
|
from dd_core.utils.logger import LoggingRecord, logger
|
|
14
14
|
|
|
15
|
-
__version__ = "1.
|
|
15
|
+
__version__ = "1.5.0"
|
|
16
16
|
_IMPORT_STRUCTURE = {
|
|
17
17
|
"analyzer": ["config_sanity_checks", "get_dd_analyzer", "ServiceFactory", "update_cfg_from_defaults"],
|
|
18
18
|
"eval": [
|
|
@@ -29,6 +29,17 @@ _IMPORT_STRUCTURE = {
|
|
|
29
29
|
"Evaluator",
|
|
30
30
|
"metric_registry",
|
|
31
31
|
"get_metric",
|
|
32
|
+
"bag_similarity",
|
|
33
|
+
"align",
|
|
34
|
+
"Counts",
|
|
35
|
+
"field_counts",
|
|
36
|
+
"RecordAlignMetric",
|
|
37
|
+
"RecordAlignPrecisionMetric",
|
|
38
|
+
"RecordAlignRecallMetric",
|
|
39
|
+
"RecordAlignF1Metric",
|
|
40
|
+
"RecordAlignPrecisionMetricMicro",
|
|
41
|
+
"RecordAlignRecallMetricMicro",
|
|
42
|
+
"RecordAlignF1MetricMicro",
|
|
32
43
|
"TableTree",
|
|
33
44
|
"CustomConfig",
|
|
34
45
|
"TEDS",
|
|
@@ -57,7 +68,6 @@ _IMPORT_STRUCTURE = {
|
|
|
57
68
|
"DoctrTextRecognizer",
|
|
58
69
|
"DocTrRotationTransformer",
|
|
59
70
|
"HFDetrDerivedDetector",
|
|
60
|
-
"get_tokenizer_from_architecture",
|
|
61
71
|
"HFLayoutLmTokenClassifierBase",
|
|
62
72
|
"HFLayoutLmTokenClassifier",
|
|
63
73
|
"HFLayoutLmv2TokenClassifier",
|
|
@@ -83,9 +93,6 @@ _IMPORT_STRUCTURE = {
|
|
|
83
93
|
"pipe": [
|
|
84
94
|
"DatapointManager",
|
|
85
95
|
"PipelineComponent",
|
|
86
|
-
"PredictorPipelineComponent",
|
|
87
|
-
"LanguageModelPipelineComponent",
|
|
88
|
-
"ImageTransformPipelineComponent",
|
|
89
96
|
"Pipeline",
|
|
90
97
|
"DetectResultGenerator",
|
|
91
98
|
"SubImageLayoutService",
|
|
@@ -404,6 +404,10 @@ The following weights configure each stage for TensorFlow and PyTorch.
|
|
|
404
404
|
Defines the spacing threshold that indicates a paragraph break in vertically
|
|
405
405
|
arranged text blocks. Helps determine reading order in multi-column, broken layouts.
|
|
406
406
|
|
|
407
|
+
TEXT_ORDERING.RIGHT_TO_LEFT:
|
|
408
|
+
If set to True, words within a line and columns lying next to each other are read from right to left
|
|
409
|
+
(e.g. for Hebrew or Arabic documents). Lines and text blocks are still read from top to bottom.
|
|
410
|
+
|
|
407
411
|
---
|
|
408
412
|
## Layout Linking Configuration
|
|
409
413
|
|
|
@@ -834,6 +838,10 @@ cfg.TEXT_ORDERING.HEIGHT_TOLERANCE = 2.0
|
|
|
834
838
|
# Helps determine reading order in multi-column, broken layouts.
|
|
835
839
|
cfg.TEXT_ORDERING.PARAGRAPH_BREAK = 0.035
|
|
836
840
|
|
|
841
|
+
# If set to True, words within a line and columns lying next to each other are read from right to left
|
|
842
|
+
# (e.g. for Hebrew or Arabic documents). Lines and text blocks are still read from top to bottom.
|
|
843
|
+
cfg.TEXT_ORDERING.RIGHT_TO_LEFT = False
|
|
844
|
+
|
|
837
845
|
# Configuration for linking spatially related layout sections
|
|
838
846
|
# (e.g., associating figures with their captions) based on proximity.
|
|
839
847
|
# The distance is calculated using the center points of the layout elements.
|
|
@@ -1194,6 +1194,7 @@ class ServiceFactory:
|
|
|
1194
1194
|
"broken_line_tolerance": config.TEXT_ORDERING.BROKEN_LINE_TOLERANCE,
|
|
1195
1195
|
"height_tolerance": config.TEXT_ORDERING.HEIGHT_TOLERANCE,
|
|
1196
1196
|
"paragraph_break": config.TEXT_ORDERING.PARAGRAPH_BREAK,
|
|
1197
|
+
"right_to_left": config.TEXT_ORDERING.RIGHT_TO_LEFT,
|
|
1197
1198
|
}
|
|
1198
1199
|
|
|
1199
1200
|
@staticmethod
|
|
@@ -1206,6 +1207,7 @@ class ServiceFactory:
|
|
|
1206
1207
|
broken_line_tolerance: float,
|
|
1207
1208
|
height_tolerance: float,
|
|
1208
1209
|
paragraph_break: float,
|
|
1210
|
+
right_to_left: bool = False,
|
|
1209
1211
|
) -> TextOrderService:
|
|
1210
1212
|
"""
|
|
1211
1213
|
Building a text order service.
|
|
@@ -1219,6 +1221,7 @@ class ServiceFactory:
|
|
|
1219
1221
|
broken_line_tolerance: Broken line tolerance for text ordering.
|
|
1220
1222
|
height_tolerance: Height tolerance for text ordering.
|
|
1221
1223
|
paragraph_break: Paragraph break threshold.
|
|
1224
|
+
right_to_left: Whether words within a line and neighbouring columns are read from right to left.
|
|
1222
1225
|
|
|
1223
1226
|
Returns:
|
|
1224
1227
|
TextOrderService: Text order service instance.
|
|
@@ -1232,6 +1235,7 @@ class ServiceFactory:
|
|
|
1232
1235
|
broken_line_tolerance=broken_line_tolerance,
|
|
1233
1236
|
height_tolerance=height_tolerance,
|
|
1234
1237
|
paragraph_break=paragraph_break,
|
|
1238
|
+
right_to_left=right_to_left,
|
|
1235
1239
|
)
|
|
1236
1240
|
|
|
1237
1241
|
@staticmethod
|
|
@@ -69,6 +69,11 @@ class Evaluator:
|
|
|
69
69
|
erasing process and after that passing the predictor. Predicted and gt datapoints will be converted into the
|
|
70
70
|
required metric input format and dumped into lists. Both lists will be passed to `MetricBase.get_distance`.
|
|
71
71
|
|
|
72
|
+
Alternatively, if predictions have already been generated elsewhere and saved as a dataset (e.g. via
|
|
73
|
+
`DocumentDatasetFactory.make` reading back saved `doc.Document` JSON), pass that dataset as `predictions_dataset`
|
|
74
|
+
instead of `component_or_pipeline`. In this mode no prediction step is run: both datasets' dataflows are built
|
|
75
|
+
and passed directly to the metric.
|
|
76
|
+
|
|
72
77
|
Note:
|
|
73
78
|
You can evaluate the predictor on a subset of categories by filtering the ground truth dataset. When using
|
|
74
79
|
the coco metric all predicted objects that are not in the set of filtered objects will be not taken into
|
|
@@ -90,53 +95,85 @@ class Evaluator:
|
|
|
90
95
|
output = evaluator.run(max_datapoints=10)
|
|
91
96
|
```
|
|
92
97
|
|
|
98
|
+
Example (evaluating against predictions saved elsewhere):
|
|
99
|
+
```python
|
|
100
|
+
gt_dataset = get_dataset("publaynet")
|
|
101
|
+
predictions_dataset = DocumentDatasetFactory.make(
|
|
102
|
+
name="my_predictions", location="my_predictions_dir",
|
|
103
|
+
dataset_type=DatasetKind.OBJECT_DETECTION, init_categories=[...],
|
|
104
|
+
)
|
|
105
|
+
coco_metric = metric_registry.get("coco")
|
|
106
|
+
evaluator = Evaluator(gt_dataset, metric=coco_metric, predictions_dataset=predictions_dataset)
|
|
107
|
+
|
|
108
|
+
output = evaluator.run()
|
|
109
|
+
```
|
|
110
|
+
|
|
93
111
|
For another example check the script in `Evaluation` of table recognition`
|
|
94
112
|
"""
|
|
95
113
|
|
|
96
114
|
def __init__(
|
|
97
115
|
self,
|
|
98
116
|
dataset: DatasetBase,
|
|
99
|
-
component_or_pipeline: Union[PipelineComponent, DoctectionPipe],
|
|
100
|
-
metric: Union[Type[MetricBase], MetricBase],
|
|
117
|
+
component_or_pipeline: Optional[Union[PipelineComponent, DoctectionPipe]] = None,
|
|
118
|
+
metric: Union[Type[MetricBase], MetricBase] = None, # type: ignore[assignment]
|
|
101
119
|
num_threads: int = 2,
|
|
102
120
|
run: Optional[wandb.sdk.wandb_run.Run] = None,
|
|
121
|
+
predictions_dataset: Optional[DatasetBase] = None,
|
|
103
122
|
) -> None:
|
|
104
123
|
"""
|
|
105
|
-
Evaluating a pipeline component on a dataset with a given metric
|
|
124
|
+
Evaluating a pipeline component on a dataset with a given metric, or evaluating a dataset of
|
|
125
|
+
precomputed predictions against a ground truth dataset.
|
|
106
126
|
|
|
107
127
|
Args:
|
|
108
|
-
dataset: dataset
|
|
109
|
-
component_or_pipeline: A pipeline component with predictor and annotation factory.
|
|
128
|
+
dataset: Ground truth dataset.
|
|
129
|
+
component_or_pipeline: A pipeline component with predictor and annotation factory. Mutually
|
|
130
|
+
exclusive with `predictions_dataset`.
|
|
110
131
|
metric: metric
|
|
132
|
+
predictions_dataset: A dataset of already computed predictions, e.g. built via
|
|
133
|
+
`DocumentDatasetFactory.make` from saved `doc.Document` JSON. When given, no
|
|
134
|
+
prediction step is run: both dataflows are passed directly to the metric.
|
|
135
|
+
Mutually exclusive with `component_or_pipeline`.
|
|
136
|
+
|
|
137
|
+
Raises:
|
|
138
|
+
ValueError: If both or neither of `component_or_pipeline` and `predictions_dataset` are given.
|
|
111
139
|
"""
|
|
112
140
|
|
|
141
|
+
if component_or_pipeline is not None and predictions_dataset is not None:
|
|
142
|
+
raise ValueError("Pass either component_or_pipeline or predictions_dataset, but not both")
|
|
143
|
+
if component_or_pipeline is None and predictions_dataset is None:
|
|
144
|
+
raise ValueError("component_or_pipeline or predictions_dataset must be provided")
|
|
145
|
+
|
|
113
146
|
self.dataset = dataset
|
|
114
147
|
self.pipe_component: Optional[MultiThreadPipelineComponent] = None
|
|
115
148
|
self.pipe: Optional[DoctectionPipe] = None
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
149
|
+
self.predictions_dataset: Optional[DatasetBase] = None
|
|
150
|
+
|
|
151
|
+
if component_or_pipeline is not None:
|
|
152
|
+
# when passing a component, we will process prediction on num_threads
|
|
153
|
+
if isinstance(component_or_pipeline, PipelineComponent):
|
|
154
|
+
logger.info(
|
|
155
|
+
LoggingRecord(
|
|
156
|
+
f"Building multi threading pipeline component to increase prediction throughput. "
|
|
157
|
+
f"Using {num_threads} threads"
|
|
158
|
+
)
|
|
123
159
|
)
|
|
124
|
-
|
|
125
|
-
pipeline_components: list[PipelineComponent] = []
|
|
160
|
+
pipeline_components: list[PipelineComponent] = []
|
|
126
161
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
162
|
+
for _ in range(num_threads - 1):
|
|
163
|
+
copy_pipe_component = component_or_pipeline.clone()
|
|
164
|
+
pipeline_components.append(copy_pipe_component)
|
|
130
165
|
|
|
131
|
-
|
|
166
|
+
pipeline_components.append(component_or_pipeline)
|
|
132
167
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
168
|
+
self.pipe_component = MultiThreadPipelineComponent(
|
|
169
|
+
pipeline_components=pipeline_components,
|
|
170
|
+
pre_proc_func=maybe_load_image, # type:ignore
|
|
171
|
+
post_proc_func=maybe_remove_image, # type:ignore
|
|
172
|
+
)
|
|
173
|
+
else:
|
|
174
|
+
self.pipe = component_or_pipeline
|
|
138
175
|
else:
|
|
139
|
-
self.
|
|
176
|
+
self.predictions_dataset = predictions_dataset
|
|
140
177
|
|
|
141
178
|
self.metric = metric
|
|
142
179
|
if not isinstance(metric, MetricBase):
|
|
@@ -199,18 +236,27 @@ class Evaluator:
|
|
|
199
236
|
Args:
|
|
200
237
|
output_as_dict: Return result in a list or dict.
|
|
201
238
|
dataflow_build_kwargs: Pass the necessary arguments in order to build the dataflow, e.g. `split`,
|
|
202
|
-
`build_mode`, `max_datapoints` etc.
|
|
239
|
+
`build_mode`, `max_datapoints` etc. When `predictions_dataset` was passed to
|
|
240
|
+
the constructor, the same kwargs are passed to both dataflow builds; a
|
|
241
|
+
builder ignores keys it does not recognize.
|
|
203
242
|
|
|
204
243
|
Returns:
|
|
205
244
|
dict with metric results.
|
|
206
245
|
"""
|
|
207
246
|
|
|
208
247
|
df_gt = self.dataset.dataflow.build(**dataflow_build_kwargs)
|
|
209
|
-
df_pr = self.dataset.dataflow.build(**dataflow_build_kwargs)
|
|
210
248
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
249
|
+
if self.predictions_dataset is not None:
|
|
250
|
+
df_pr = self.predictions_dataset.dataflow.build(**dataflow_build_kwargs)
|
|
251
|
+
if self.wandb_table_agent is not None:
|
|
252
|
+
df_pr_list = CacheData(df_pr).get_cache()
|
|
253
|
+
df_pr_list = [self.wandb_table_agent.dump(dp) for dp in df_pr_list]
|
|
254
|
+
df_pr = DataFromList(df_pr_list)
|
|
255
|
+
else:
|
|
256
|
+
df_pr = self.dataset.dataflow.build(**dataflow_build_kwargs)
|
|
257
|
+
df_pr = MapData(df_pr, deepcopy)
|
|
258
|
+
df_pr = self._clean_up_predict_dataflow_annotations(df_pr)
|
|
259
|
+
df_pr = self._run_pipe_or_component(df_pr)
|
|
214
260
|
|
|
215
261
|
logger.info(LoggingRecord("Starting evaluation..."))
|
|
216
262
|
result = self.metric.get_distance(df_gt, df_pr, self.dataset.dataflow.categories)
|
|
@@ -226,6 +272,17 @@ class Evaluator:
|
|
|
226
272
|
|
|
227
273
|
def _sanity_checks(self) -> None:
|
|
228
274
|
assert self.dataset.dataflow.categories is not None
|
|
275
|
+
if self.predictions_dataset is not None:
|
|
276
|
+
assert self.predictions_dataset.dataflow.categories is not None
|
|
277
|
+
gt_cats = set(self.dataset.dataflow.categories.get_categories(as_dict=False, filtered=True))
|
|
278
|
+
pr_cats = set(self.predictions_dataset.dataflow.categories.get_categories(as_dict=False, filtered=True))
|
|
279
|
+
if gt_cats != pr_cats:
|
|
280
|
+
logger.warning(
|
|
281
|
+
LoggingRecord(
|
|
282
|
+
f"Category mismatch between ground truth and predictions dataset. "
|
|
283
|
+
f"gt only: {gt_cats - pr_cats}, predictions only: {pr_cats - gt_cats}"
|
|
284
|
+
)
|
|
285
|
+
)
|
|
229
286
|
|
|
230
287
|
def _run_pipe_or_component(self, df_pr: DataFlow) -> DataFlow:
|
|
231
288
|
if self.pipe_component:
|
|
@@ -296,6 +353,12 @@ class Evaluator:
|
|
|
296
353
|
Image as `np.array`
|
|
297
354
|
"""
|
|
298
355
|
|
|
356
|
+
if self.pipe_component is None and self.pipe is None:
|
|
357
|
+
raise ValueError(
|
|
358
|
+
"Neither pipe_component nor pipe has been defined; compare() is not supported when "
|
|
359
|
+
"Evaluator was constructed with predictions_dataset"
|
|
360
|
+
)
|
|
361
|
+
|
|
299
362
|
show_tables = kwargs.pop("show_tables", True)
|
|
300
363
|
show_layouts = kwargs.pop("show_layouts", True)
|
|
301
364
|
show_table_structure = kwargs.pop("show_table_structure", True)
|
|
@@ -323,11 +386,8 @@ class Evaluator:
|
|
|
323
386
|
pipe_component = self.pipe_component.pipe_components[0]
|
|
324
387
|
df_pr = pipe_component.predict_dataflow(df_pr)
|
|
325
388
|
df_pr = page_parsing_component.predict_dataflow(df_pr)
|
|
326
|
-
|
|
327
|
-
elif self.pipe:
|
|
328
|
-
df_pr = self.pipe.analyze(dataset_dataflow=df_pr)
|
|
329
389
|
else:
|
|
330
|
-
|
|
390
|
+
df_pr = self.pipe.analyze(dataset_dataflow=df_pr) # type: ignore
|
|
331
391
|
|
|
332
392
|
df_pr.reset_state()
|
|
333
393
|
df_gt.reset_state()
|