deepdoctection 0.42.1__py3-none-any.whl → 0.43.1__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 +4 -2
- deepdoctection/analyzer/__init__.py +2 -1
- deepdoctection/analyzer/config.py +919 -0
- deepdoctection/analyzer/dd.py +36 -62
- deepdoctection/analyzer/factory.py +311 -141
- deepdoctection/configs/conf_dd_one.yaml +100 -44
- deepdoctection/configs/profiles.jsonl +32 -0
- deepdoctection/dataflow/__init__.py +9 -6
- deepdoctection/dataflow/base.py +33 -15
- deepdoctection/dataflow/common.py +96 -75
- deepdoctection/dataflow/custom.py +36 -29
- deepdoctection/dataflow/custom_serialize.py +135 -91
- deepdoctection/dataflow/parallel_map.py +33 -31
- deepdoctection/dataflow/serialize.py +15 -10
- deepdoctection/dataflow/stats.py +41 -28
- deepdoctection/datapoint/__init__.py +4 -6
- deepdoctection/datapoint/annotation.py +104 -66
- deepdoctection/datapoint/box.py +190 -130
- deepdoctection/datapoint/convert.py +66 -39
- deepdoctection/datapoint/image.py +151 -95
- deepdoctection/datapoint/view.py +383 -236
- deepdoctection/datasets/__init__.py +2 -6
- deepdoctection/datasets/adapter.py +11 -11
- deepdoctection/datasets/base.py +118 -81
- deepdoctection/datasets/dataflow_builder.py +18 -12
- deepdoctection/datasets/info.py +76 -57
- deepdoctection/datasets/instances/__init__.py +6 -2
- deepdoctection/datasets/instances/doclaynet.py +17 -14
- deepdoctection/datasets/instances/fintabnet.py +16 -22
- deepdoctection/datasets/instances/funsd.py +11 -6
- deepdoctection/datasets/instances/iiitar13k.py +9 -9
- deepdoctection/datasets/instances/layouttest.py +9 -9
- deepdoctection/datasets/instances/publaynet.py +9 -9
- deepdoctection/datasets/instances/pubtables1m.py +13 -13
- deepdoctection/datasets/instances/pubtabnet.py +13 -15
- deepdoctection/datasets/instances/rvlcdip.py +8 -8
- deepdoctection/datasets/instances/xfund.py +11 -9
- deepdoctection/datasets/registry.py +18 -11
- deepdoctection/datasets/save.py +12 -11
- deepdoctection/eval/__init__.py +3 -2
- deepdoctection/eval/accmetric.py +72 -52
- deepdoctection/eval/base.py +29 -10
- deepdoctection/eval/cocometric.py +14 -12
- deepdoctection/eval/eval.py +56 -41
- deepdoctection/eval/registry.py +6 -3
- deepdoctection/eval/tedsmetric.py +24 -9
- deepdoctection/eval/tp_eval_callback.py +13 -12
- deepdoctection/extern/__init__.py +1 -1
- deepdoctection/extern/base.py +176 -97
- deepdoctection/extern/d2detect.py +127 -92
- deepdoctection/extern/deskew.py +19 -10
- deepdoctection/extern/doctrocr.py +162 -108
- deepdoctection/extern/fastlang.py +25 -17
- deepdoctection/extern/hfdetr.py +137 -60
- deepdoctection/extern/hflayoutlm.py +329 -248
- deepdoctection/extern/hflm.py +67 -33
- deepdoctection/extern/model.py +108 -762
- deepdoctection/extern/pdftext.py +37 -12
- deepdoctection/extern/pt/nms.py +15 -1
- deepdoctection/extern/pt/ptutils.py +13 -9
- deepdoctection/extern/tessocr.py +87 -54
- deepdoctection/extern/texocr.py +29 -14
- deepdoctection/extern/tp/tfutils.py +36 -8
- deepdoctection/extern/tp/tpcompat.py +54 -16
- deepdoctection/extern/tp/tpfrcnn/config/config.py +20 -4
- deepdoctection/extern/tpdetect.py +4 -2
- deepdoctection/mapper/__init__.py +1 -1
- deepdoctection/mapper/cats.py +117 -76
- deepdoctection/mapper/cocostruct.py +35 -17
- deepdoctection/mapper/d2struct.py +56 -29
- deepdoctection/mapper/hfstruct.py +32 -19
- deepdoctection/mapper/laylmstruct.py +221 -185
- deepdoctection/mapper/maputils.py +71 -35
- deepdoctection/mapper/match.py +76 -62
- deepdoctection/mapper/misc.py +68 -44
- deepdoctection/mapper/pascalstruct.py +13 -12
- deepdoctection/mapper/prodigystruct.py +33 -19
- deepdoctection/mapper/pubstruct.py +42 -32
- deepdoctection/mapper/tpstruct.py +39 -19
- deepdoctection/mapper/xfundstruct.py +20 -13
- deepdoctection/pipe/__init__.py +1 -2
- deepdoctection/pipe/anngen.py +104 -62
- deepdoctection/pipe/base.py +226 -107
- deepdoctection/pipe/common.py +206 -123
- deepdoctection/pipe/concurrency.py +74 -47
- deepdoctection/pipe/doctectionpipe.py +108 -47
- deepdoctection/pipe/language.py +41 -24
- deepdoctection/pipe/layout.py +45 -18
- deepdoctection/pipe/lm.py +146 -78
- deepdoctection/pipe/order.py +205 -119
- deepdoctection/pipe/refine.py +111 -63
- deepdoctection/pipe/registry.py +1 -1
- deepdoctection/pipe/segment.py +213 -142
- deepdoctection/pipe/sub_layout.py +76 -46
- deepdoctection/pipe/text.py +52 -33
- deepdoctection/pipe/transform.py +8 -6
- deepdoctection/train/d2_frcnn_train.py +87 -69
- deepdoctection/train/hf_detr_train.py +72 -40
- deepdoctection/train/hf_layoutlm_train.py +85 -46
- deepdoctection/train/tp_frcnn_train.py +56 -28
- deepdoctection/utils/concurrency.py +59 -16
- deepdoctection/utils/context.py +40 -19
- deepdoctection/utils/develop.py +26 -17
- deepdoctection/utils/env_info.py +86 -37
- deepdoctection/utils/error.py +16 -10
- deepdoctection/utils/file_utils.py +246 -71
- deepdoctection/utils/fs.py +162 -43
- deepdoctection/utils/identifier.py +29 -16
- deepdoctection/utils/logger.py +49 -32
- deepdoctection/utils/metacfg.py +83 -21
- deepdoctection/utils/pdf_utils.py +119 -62
- deepdoctection/utils/settings.py +24 -10
- deepdoctection/utils/tqdm.py +10 -5
- deepdoctection/utils/transform.py +182 -46
- deepdoctection/utils/utils.py +61 -28
- deepdoctection/utils/viz.py +150 -104
- deepdoctection-0.43.1.dist-info/METADATA +376 -0
- deepdoctection-0.43.1.dist-info/RECORD +149 -0
- deepdoctection/analyzer/_config.py +0 -146
- deepdoctection-0.42.1.dist-info/METADATA +0 -431
- deepdoctection-0.42.1.dist-info/RECORD +0 -148
- {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.1.dist-info}/WHEEL +0 -0
- {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.1.dist-info}/licenses/LICENSE +0 -0
- {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.1.dist-info}/top_level.txt +0 -0
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
|
|
18
18
|
"""
|
|
19
|
-
|
|
19
|
+
Mapping annotations from Pubtabnet structure to Image structure.
|
|
20
20
|
"""
|
|
21
21
|
import itertools
|
|
22
22
|
import os
|
|
@@ -103,13 +103,16 @@ def _end_of_header(html: Sequence[str]) -> int:
|
|
|
103
103
|
|
|
104
104
|
def tile_table(row_spans: Sequence[Sequence[int]], col_spans: Sequence[Sequence[int]]) -> list[list[int]]:
|
|
105
105
|
"""
|
|
106
|
-
Tiles a table according the row and column span scheme. A table can be represented as a list of
|
|
107
|
-
inner list has the same length. Each cell with a cell id can be located according to their row and column
|
|
108
|
-
that scheme
|
|
106
|
+
Tiles a table according to the row and column span scheme. A table can be represented as a list of lists, where
|
|
107
|
+
each inner list has the same length. Each cell with a cell id can be located according to their row and column
|
|
108
|
+
spans in that scheme.
|
|
109
109
|
|
|
110
|
-
:
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
Args:
|
|
111
|
+
row_spans: A list of lists of row spans.
|
|
112
|
+
col_spans: A list of lists of column spans.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
A list of lists of the tiling of the table, indicating the precise place of each cell.
|
|
113
116
|
"""
|
|
114
117
|
number_of_cols = sum(col_spans[0])
|
|
115
118
|
number_of_rows = len(col_spans)
|
|
@@ -255,8 +258,11 @@ def row_col_cell_ids(tiling: list[list[int]]) -> list[tuple[int, int, int]]:
|
|
|
255
258
|
"""
|
|
256
259
|
Infers absolute rows and columns for every cell from the tiling of a table.
|
|
257
260
|
|
|
258
|
-
:
|
|
259
|
-
|
|
261
|
+
Args:
|
|
262
|
+
tiling: A list of lists of tiling of a table as returned from the `_tile_table`.
|
|
263
|
+
|
|
264
|
+
Returns:
|
|
265
|
+
A list of `3-tuples` with row number, column number, and cell id.
|
|
260
266
|
"""
|
|
261
267
|
indices = sorted(
|
|
262
268
|
[(i + 1, j + 1, cell_id) for i, row in enumerate(tiling) for j, cell_id in enumerate(row)], key=lambda x: x[2]
|
|
@@ -269,14 +275,15 @@ def row_col_cell_ids(tiling: list[list[int]]) -> list[tuple[int, int, int]]:
|
|
|
269
275
|
|
|
270
276
|
def embedding_in_image(dp: Image, html: list[str], categories_name_as_key: dict[ObjectTypes, int]) -> Image:
|
|
271
277
|
"""
|
|
272
|
-
Generating an image
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
:
|
|
278
|
+
Generating an image that resembles the output of an analyzer. The layout of the image is a table spanning the full
|
|
279
|
+
page, i.e. there is one table image annotation. Moreover, the table annotation has an image, with cells as image
|
|
280
|
+
annotations.
|
|
281
|
+
|
|
282
|
+
Args:
|
|
283
|
+
dp: Image html: List with html tags. categories_name_as_key: Category dictionary with all possible annotations.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
Image
|
|
280
287
|
"""
|
|
281
288
|
image = Image(file_name=dp.file_name, location=dp.location, external_id=dp.image_id + "image")
|
|
282
289
|
image.image = dp.image
|
|
@@ -313,12 +320,13 @@ def embedding_in_image(dp: Image, html: list[str], categories_name_as_key: dict[
|
|
|
313
320
|
|
|
314
321
|
def nth_index(iterable: Iterable[str], value: str, n: int) -> Optional[int]:
|
|
315
322
|
"""
|
|
316
|
-
Returns the position of the n-th string value in an iterable, e.g. a list
|
|
323
|
+
Returns the position of the n-th string value in an iterable, e.g. a list.
|
|
324
|
+
|
|
325
|
+
Args:
|
|
326
|
+
iterable: e.g. list value: Any value `n`: `n-th` value
|
|
317
327
|
|
|
318
|
-
:
|
|
319
|
-
|
|
320
|
-
:param n: n-th value
|
|
321
|
-
:return: position if n-th value exists else None
|
|
328
|
+
Returns:
|
|
329
|
+
Position if `n-th` value exists else `None`.
|
|
322
330
|
"""
|
|
323
331
|
matches = (idx for idx, val in enumerate(iterable) if val == value)
|
|
324
332
|
return next(itertools.islice(matches, n - 1, n), None)
|
|
@@ -338,19 +346,21 @@ def pub_to_image_uncur( # pylint: disable=R0914
|
|
|
338
346
|
Map a datapoint of annotation structure as given in the Pubtabnet dataset to an Image structure.
|
|
339
347
|
<https://github.com/ibm-aur-nlp/PubTabNet>
|
|
340
348
|
|
|
341
|
-
:
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
349
|
+
Args:
|
|
350
|
+
dp: A datapoint in serialized Pubtabnet format.
|
|
351
|
+
categories_name_as_key: A dict of categories, e.g. `DatasetCategories.get_categories(name_as_key=True)`
|
|
352
|
+
load_image: If `True` it will load image to `Image.image`
|
|
353
|
+
fake_score: If dp does not contain a score, a fake score with uniform random variables in (0,1)
|
|
345
354
|
will be added.
|
|
346
|
-
|
|
347
|
-
sub-category "row_col" that is equal to
|
|
348
|
-
|
|
355
|
+
rows_and_cols: If set to `True`, synthetic `ITEM` ImageAnnotations will be added. Each item has a
|
|
356
|
+
sub-category "row_col" that is equal to `ROW` or `COL`.
|
|
357
|
+
dd_pipe_like: This will generate an image identical to the output of the dd analyzer (e.g. table and words
|
|
349
358
|
annotations as well as sub annotations and relationships will be generated)
|
|
350
|
-
|
|
351
|
-
|
|
359
|
+
is_fintabnet: Set `True`, if this mapping is used for generating Fintabnet datapoints.
|
|
360
|
+
pubtables_like: Set `True`, the area covering the table will be tiled with non overlapping rows and columns
|
|
352
361
|
without leaving empty space
|
|
353
|
-
:
|
|
362
|
+
Returns:
|
|
363
|
+
Image
|
|
354
364
|
"""
|
|
355
365
|
|
|
356
366
|
if dd_pipe_like:
|
|
@@ -42,14 +42,24 @@ def image_to_tp_frcnn_training(
|
|
|
42
42
|
category_names: Optional[Union[TypeOrStr, Sequence[TypeOrStr]]] = None,
|
|
43
43
|
) -> Optional[JsonDict]:
|
|
44
44
|
"""
|
|
45
|
-
Maps an
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
:
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
Maps an `Image` to a dict to be consumed by Tensorpack Faster-RCNN bounding box detection.
|
|
46
|
+
|
|
47
|
+
Note:
|
|
48
|
+
The returned dict will not suffice for training as ground truth for RPN and anchors still need to be created.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
dp: `Image`.
|
|
52
|
+
add_mask: `True` is not implemented.
|
|
53
|
+
category_names: A list of category names for training a model. Pass nothing to train with all annotations.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
Dict with `image`, `gt_boxes`, `gt_labels` and `file_name`, provided there are some detected objects in the
|
|
57
|
+
image.
|
|
58
|
+
|
|
59
|
+
Example:
|
|
60
|
+
```python
|
|
61
|
+
image_to_tp_frcnn_training(dp)
|
|
62
|
+
```
|
|
53
63
|
"""
|
|
54
64
|
|
|
55
65
|
output: JsonDict = {}
|
|
@@ -83,15 +93,24 @@ def tf_nms_image_annotations(
|
|
|
83
93
|
anns: Sequence[ImageAnnotation], threshold: float, image_id: Optional[str] = None, prio: str = ""
|
|
84
94
|
) -> Sequence[str]:
|
|
85
95
|
"""
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
Processes given `ImageAnnotation` through `NMS`.
|
|
97
|
+
|
|
98
|
+
This is useful if you want to suppress some specific image annotation, e.g., given by name or returned through
|
|
99
|
+
different predictors. This is the TensorFlow version; for PyTorch, check `mapper.d2struct`.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
anns: A sequence of `ImageAnnotation`. All annotations will be treated as if they belong to one category.
|
|
103
|
+
threshold: NMS threshold.
|
|
104
|
+
image_id: ID in order to get the embedding bounding box.
|
|
105
|
+
prio: If an annotation has `prio`, it will overwrite its given score to 1 so that it will never be suppressed.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
A list of `annotation_id` that belong to the given input sequence and that survive the NMS process.
|
|
109
|
+
|
|
110
|
+
Example:
|
|
111
|
+
```python
|
|
112
|
+
tf_nms_image_annotations(anns, threshold)
|
|
113
|
+
```
|
|
95
114
|
"""
|
|
96
115
|
if len(anns) == 1:
|
|
97
116
|
return [anns[0].annotation_id]
|
|
@@ -122,8 +141,9 @@ def tf_nms_image_annotations(
|
|
|
122
141
|
ann_ids = np.array([ann.annotation_id for ann in anns], dtype="object")
|
|
123
142
|
|
|
124
143
|
# Get boxes for non-priority annotations
|
|
125
|
-
boxes = convert_to_tensor(
|
|
126
|
-
|
|
144
|
+
boxes = convert_to_tensor(
|
|
145
|
+
[ann.get_bounding_box(image_id).to_list(mode="xyxy") for ann in anns if ann.bounding_box is not None]
|
|
146
|
+
)
|
|
127
147
|
|
|
128
148
|
scores = convert_to_tensor([priority_to_confidence(ann, prio) for ann in anns])
|
|
129
149
|
class_mask = convert_to_tensor(len(boxes), dtype=uint8)
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
|
|
18
18
|
"""
|
|
19
|
-
Module for mapping annotations to and from
|
|
19
|
+
Module for mapping annotations to and from Xfund data structure
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
22
|
import os
|
|
@@ -50,18 +50,25 @@ def xfund_to_image(
|
|
|
50
50
|
ner_token_to_id_mapping: Mapping[ObjectTypes, Mapping[ObjectTypes, Mapping[ObjectTypes, int]]],
|
|
51
51
|
) -> Optional[Image]:
|
|
52
52
|
"""
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
Maps a datapoint of annotation structure as given from Xfund or Funsd dataset into an `Image` structure.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
dp: A datapoint in dict structure as returned from the Xfund or Funsd dataset. Each datapoint must coincide
|
|
57
|
+
with exactly one image sample.
|
|
58
|
+
load_image: If `True`, it will load image to `Image.image`.
|
|
59
|
+
fake_score: If `dp` does not contain a score, a fake score with uniform random variables in `(0,1)` will be
|
|
60
|
+
added.
|
|
61
|
+
categories_dict_name_as_key: A mapping from `ObjectTypes` to `int` for `category_id`s.
|
|
62
|
+
token_class_names_mapping: A dictionary mapping original label names to normalized category names.
|
|
63
|
+
ner_token_to_id_mapping: A dictionary mapping token classes with bio tags (i.e. token tags) into their
|
|
64
|
+
category ids.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
`Image` or `None` if the image path is not found or an error occurs during mapping.
|
|
68
|
+
|
|
69
|
+
Note:
|
|
70
|
+
This function is intended for mapping xfund or funsd dataset annotation structures to the internal `Image`
|
|
71
|
+
representation for further processing.
|
|
65
72
|
"""
|
|
66
73
|
|
|
67
74
|
img = dp.get("img")
|
deepdoctection/pipe/__init__.py
CHANGED
deepdoctection/pipe/anngen.py
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
|
|
18
18
|
"""
|
|
19
|
-
|
|
19
|
+
Datapoint manager
|
|
20
20
|
"""
|
|
21
21
|
from dataclasses import asdict
|
|
22
|
-
from typing import
|
|
22
|
+
from typing import Optional, Union
|
|
23
23
|
|
|
24
24
|
import numpy as np
|
|
25
25
|
|
|
@@ -33,8 +33,8 @@ from ..utils.settings import ObjectTypes, Relationships
|
|
|
33
33
|
|
|
34
34
|
class DatapointManager:
|
|
35
35
|
"""
|
|
36
|
-
|
|
37
|
-
annotations in the cache of the image
|
|
36
|
+
This class provides an API for manipulating image datapoints. This includes the creation and storage of
|
|
37
|
+
annotations in the cache of the image as well as in the annotations themselves.
|
|
38
38
|
|
|
39
39
|
When the image is transferred, the annotations are stored in a cache dictionary so that access via the annotation ID
|
|
40
40
|
can be performed efficiently.
|
|
@@ -46,7 +46,6 @@ class DatapointManager:
|
|
|
46
46
|
self._datapoint: Optional[Image] = None
|
|
47
47
|
self._cache_anns: dict[str, ImageAnnotation] = {}
|
|
48
48
|
self.datapoint_is_passed: bool = False
|
|
49
|
-
self.category_id_mapping: Optional[Mapping[int, int]] = None
|
|
50
49
|
self.service_id = service_id
|
|
51
50
|
self.model_id = model_id
|
|
52
51
|
self.session_id: Optional[str] = None
|
|
@@ -54,7 +53,13 @@ class DatapointManager:
|
|
|
54
53
|
@property
|
|
55
54
|
def datapoint(self) -> Image:
|
|
56
55
|
"""
|
|
57
|
-
datapoint
|
|
56
|
+
Gets the datapoint.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
The datapoint.
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
ValueError: If no datapoint is passed.
|
|
58
63
|
"""
|
|
59
64
|
if self._datapoint is not None:
|
|
60
65
|
return self._datapoint
|
|
@@ -63,7 +68,10 @@ class DatapointManager:
|
|
|
63
68
|
@datapoint.setter
|
|
64
69
|
def datapoint(self, dp: Image) -> None:
|
|
65
70
|
"""
|
|
66
|
-
datapoint
|
|
71
|
+
Sets the datapoint.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
dp: The datapoint to set.
|
|
67
75
|
"""
|
|
68
76
|
self._datapoint = dp
|
|
69
77
|
self._cache_anns = {ann.annotation_id: ann for ann in dp.get_annotation()}
|
|
@@ -71,7 +79,10 @@ class DatapointManager:
|
|
|
71
79
|
|
|
72
80
|
def assert_datapoint_passed(self) -> None:
|
|
73
81
|
"""
|
|
74
|
-
|
|
82
|
+
Asserts that a datapoint is passed.
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
AssertionError: If a datapoint has not been passed to `DatapointManager` before creating annotations.
|
|
75
86
|
"""
|
|
76
87
|
assert self.datapoint_is_passed, "Pass datapoint to DatapointManager before creating anns"
|
|
77
88
|
|
|
@@ -85,25 +96,34 @@ class DatapointManager:
|
|
|
85
96
|
detect_result_max_height: Optional[float] = None,
|
|
86
97
|
) -> Optional[str]:
|
|
87
98
|
"""
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
to
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
Creates an image annotation from a raw `DetectionResult` dataclass.
|
|
100
|
+
|
|
101
|
+
In addition to dumping the annotation to the `ImageAnnotation` cache, you can also dump the annotation to the
|
|
102
|
+
`image` of an annotation with a given `annotation_id`. This is useful if you want to send the sub image to a
|
|
103
|
+
subsequent pipeline component.
|
|
104
|
+
|
|
105
|
+
It is also possible to generate an `Image` of the given raw annotation and store it in its `image`. The
|
|
106
|
+
resulting image is given as a sub image of `self` defined by its bounding box coordinates. Use `crop_image` to
|
|
107
|
+
explicitly store the sub image as a numpy array.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
detect_result: A `DetectionResult`, generally coming from `ObjectDetector`.
|
|
111
|
+
to_annotation_id: Dumps the created image annotation to `image` of the given `annotation_id`. Requires the
|
|
112
|
+
target annotation to have a non-None image.
|
|
113
|
+
to_image: If True, will populate `image`.
|
|
114
|
+
crop_image: Only makes sense if `to_image` is True and if a numpy array is stored in the original image.
|
|
115
|
+
Will generate `Image.image`.
|
|
116
|
+
detect_result_max_width: If the detect result has a different scaling scheme from the image it refers to,
|
|
117
|
+
pass the max width possible so coordinates can be rescaled.
|
|
118
|
+
detect_result_max_height: If the detect result has a different scaling scheme from the image it refers to,
|
|
119
|
+
pass the max height possible so coordinates can be rescaled.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
The `annotation_id` of the generated image annotation, or `None` if there was a context error.
|
|
123
|
+
|
|
124
|
+
Raises:
|
|
125
|
+
TypeError: If `detect_result.box` is not of type list or `np.ndarray`.
|
|
126
|
+
ValueError: If the parent annotation's image is None or if the annotation's image is None.
|
|
107
127
|
"""
|
|
108
128
|
self.assert_datapoint_passed()
|
|
109
129
|
if not isinstance(detect_result.box, (list, np.ndarray)):
|
|
@@ -171,14 +191,17 @@ class DatapointManager:
|
|
|
171
191
|
score: Optional[float] = None,
|
|
172
192
|
) -> Optional[str]:
|
|
173
193
|
"""
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
Creates a category annotation and dumps it as a subcategory to an already created annotation.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
category_name: The category name.
|
|
198
|
+
category_id: The category id.
|
|
199
|
+
sub_cat_key: The key to dump the created annotation to.
|
|
200
|
+
annotation_id: The id of the parent annotation. Currently, this can only be an image annotation.
|
|
201
|
+
score: The score to add.
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
The `annotation_id` of the generated category annotation, or `None` if there was a context error.
|
|
182
205
|
"""
|
|
183
206
|
self.assert_datapoint_passed()
|
|
184
207
|
with MappingContextManager(
|
|
@@ -213,15 +236,18 @@ class DatapointManager:
|
|
|
213
236
|
score: Optional[float] = None,
|
|
214
237
|
) -> Optional[str]:
|
|
215
238
|
"""
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
239
|
+
Creates a container annotation and dumps it as a subcategory to an already created annotation.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
category_name: The category name.
|
|
243
|
+
category_id: The category id.
|
|
244
|
+
sub_cat_key: The key to dump the created annotation to.
|
|
245
|
+
annotation_id: The id of the parent annotation. Currently, this can only be an image annotation.
|
|
246
|
+
value: The value to store.
|
|
247
|
+
score: The score to add.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
The `annotation_id` of the generated container annotation, or None if there was a context error.
|
|
225
251
|
"""
|
|
226
252
|
self.assert_datapoint_passed()
|
|
227
253
|
with MappingContextManager(
|
|
@@ -252,13 +278,16 @@ class DatapointManager:
|
|
|
252
278
|
self, relationship_name: ObjectTypes, target_annotation_id: str, annotation_id: str
|
|
253
279
|
) -> Optional[str]:
|
|
254
280
|
"""
|
|
255
|
-
|
|
281
|
+
Creates a relationship annotation and dumps it to the target annotation.
|
|
256
282
|
|
|
257
|
-
:
|
|
258
|
-
|
|
259
|
-
|
|
283
|
+
Args:
|
|
284
|
+
relationship_name: The relationship key.
|
|
285
|
+
target_annotation_id: The `annotation_id` of the parent `ImageAnnotation`.
|
|
286
|
+
annotation_id: The `annotation_id` to dump the relationship to.
|
|
260
287
|
|
|
261
|
-
:
|
|
288
|
+
Returns:
|
|
289
|
+
The `annotation_id` of the parent `ImageAnnotation` for reference if the dump has been successful, or `None`
|
|
290
|
+
if there was a context error.
|
|
262
291
|
"""
|
|
263
292
|
self.assert_datapoint_passed()
|
|
264
293
|
with MappingContextManager(
|
|
@@ -285,16 +314,20 @@ class DatapointManager:
|
|
|
285
314
|
annotation_id: Optional[str] = None,
|
|
286
315
|
) -> Optional[str]:
|
|
287
316
|
"""
|
|
288
|
-
Creates a
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
:
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
317
|
+
Creates a subcategory of a summary annotation.
|
|
318
|
+
|
|
319
|
+
If a summary of the given `annotation_id` does not exist, it will create a new one.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
summary_key: Stores the category annotation as a subcategory.
|
|
323
|
+
summary_name: Creates the summary name as the category name.
|
|
324
|
+
summary_number: Stores the value in `category_id`.
|
|
325
|
+
summary_value: Creates a `ContainerAnnotation` and stores the corresponding value.
|
|
326
|
+
summary_score: Stores the score.
|
|
327
|
+
annotation_id: The id of the parent annotation. Note that the parent annotation must have `image` not None.
|
|
328
|
+
|
|
329
|
+
Returns:
|
|
330
|
+
The `annotation_id` of the generated category annotation, or None if there was a context error.
|
|
298
331
|
"""
|
|
299
332
|
self.assert_datapoint_passed()
|
|
300
333
|
if annotation_id is not None:
|
|
@@ -341,13 +374,22 @@ class DatapointManager:
|
|
|
341
374
|
|
|
342
375
|
def deactivate_annotation(self, annotation_id: str) -> None:
|
|
343
376
|
"""
|
|
344
|
-
|
|
377
|
+
Deactivates the annotation by the given `annotation_id`.
|
|
345
378
|
|
|
346
|
-
:
|
|
379
|
+
Args:
|
|
380
|
+
annotation_id: The `annotation_id` to deactivate.
|
|
347
381
|
"""
|
|
348
382
|
ann = self._cache_anns[annotation_id]
|
|
349
383
|
ann.deactivate()
|
|
350
384
|
|
|
351
385
|
def get_annotation(self, annotation_id: str) -> ImageAnnotation:
|
|
352
|
-
"""
|
|
386
|
+
"""
|
|
387
|
+
Gets a single `ImageAnnotation`.
|
|
388
|
+
|
|
389
|
+
Args:
|
|
390
|
+
annotation_id: The `annotation_id` of the annotation to retrieve.
|
|
391
|
+
|
|
392
|
+
Returns:
|
|
393
|
+
The `ImageAnnotation` corresponding to the given `annotation_id`.
|
|
394
|
+
"""
|
|
353
395
|
return self._cache_anns[annotation_id]
|