deepdoctection 0.42.1__py3-none-any.whl → 0.43__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 (124) hide show
  1. deepdoctection/__init__.py +2 -1
  2. deepdoctection/analyzer/__init__.py +2 -1
  3. deepdoctection/analyzer/config.py +904 -0
  4. deepdoctection/analyzer/dd.py +36 -62
  5. deepdoctection/analyzer/factory.py +311 -141
  6. deepdoctection/configs/conf_dd_one.yaml +100 -44
  7. deepdoctection/configs/profiles.jsonl +32 -0
  8. deepdoctection/dataflow/__init__.py +9 -6
  9. deepdoctection/dataflow/base.py +33 -15
  10. deepdoctection/dataflow/common.py +96 -75
  11. deepdoctection/dataflow/custom.py +36 -29
  12. deepdoctection/dataflow/custom_serialize.py +135 -91
  13. deepdoctection/dataflow/parallel_map.py +33 -31
  14. deepdoctection/dataflow/serialize.py +15 -10
  15. deepdoctection/dataflow/stats.py +41 -28
  16. deepdoctection/datapoint/__init__.py +4 -6
  17. deepdoctection/datapoint/annotation.py +104 -66
  18. deepdoctection/datapoint/box.py +190 -130
  19. deepdoctection/datapoint/convert.py +66 -39
  20. deepdoctection/datapoint/image.py +151 -95
  21. deepdoctection/datapoint/view.py +383 -236
  22. deepdoctection/datasets/__init__.py +2 -6
  23. deepdoctection/datasets/adapter.py +11 -11
  24. deepdoctection/datasets/base.py +118 -81
  25. deepdoctection/datasets/dataflow_builder.py +18 -12
  26. deepdoctection/datasets/info.py +76 -57
  27. deepdoctection/datasets/instances/__init__.py +6 -2
  28. deepdoctection/datasets/instances/doclaynet.py +17 -14
  29. deepdoctection/datasets/instances/fintabnet.py +16 -22
  30. deepdoctection/datasets/instances/funsd.py +11 -6
  31. deepdoctection/datasets/instances/iiitar13k.py +9 -9
  32. deepdoctection/datasets/instances/layouttest.py +9 -9
  33. deepdoctection/datasets/instances/publaynet.py +9 -9
  34. deepdoctection/datasets/instances/pubtables1m.py +13 -13
  35. deepdoctection/datasets/instances/pubtabnet.py +13 -15
  36. deepdoctection/datasets/instances/rvlcdip.py +8 -8
  37. deepdoctection/datasets/instances/xfund.py +11 -9
  38. deepdoctection/datasets/registry.py +18 -11
  39. deepdoctection/datasets/save.py +12 -11
  40. deepdoctection/eval/__init__.py +3 -2
  41. deepdoctection/eval/accmetric.py +72 -52
  42. deepdoctection/eval/base.py +29 -10
  43. deepdoctection/eval/cocometric.py +14 -12
  44. deepdoctection/eval/eval.py +56 -41
  45. deepdoctection/eval/registry.py +6 -3
  46. deepdoctection/eval/tedsmetric.py +24 -9
  47. deepdoctection/eval/tp_eval_callback.py +13 -12
  48. deepdoctection/extern/__init__.py +1 -1
  49. deepdoctection/extern/base.py +176 -97
  50. deepdoctection/extern/d2detect.py +127 -92
  51. deepdoctection/extern/deskew.py +19 -10
  52. deepdoctection/extern/doctrocr.py +157 -106
  53. deepdoctection/extern/fastlang.py +25 -17
  54. deepdoctection/extern/hfdetr.py +137 -60
  55. deepdoctection/extern/hflayoutlm.py +329 -248
  56. deepdoctection/extern/hflm.py +67 -33
  57. deepdoctection/extern/model.py +108 -762
  58. deepdoctection/extern/pdftext.py +37 -12
  59. deepdoctection/extern/pt/nms.py +15 -1
  60. deepdoctection/extern/pt/ptutils.py +13 -9
  61. deepdoctection/extern/tessocr.py +87 -54
  62. deepdoctection/extern/texocr.py +29 -14
  63. deepdoctection/extern/tp/tfutils.py +36 -8
  64. deepdoctection/extern/tp/tpcompat.py +54 -16
  65. deepdoctection/extern/tp/tpfrcnn/config/config.py +20 -4
  66. deepdoctection/extern/tpdetect.py +4 -2
  67. deepdoctection/mapper/__init__.py +1 -1
  68. deepdoctection/mapper/cats.py +117 -76
  69. deepdoctection/mapper/cocostruct.py +35 -17
  70. deepdoctection/mapper/d2struct.py +56 -29
  71. deepdoctection/mapper/hfstruct.py +32 -19
  72. deepdoctection/mapper/laylmstruct.py +221 -185
  73. deepdoctection/mapper/maputils.py +71 -35
  74. deepdoctection/mapper/match.py +76 -62
  75. deepdoctection/mapper/misc.py +68 -44
  76. deepdoctection/mapper/pascalstruct.py +13 -12
  77. deepdoctection/mapper/prodigystruct.py +33 -19
  78. deepdoctection/mapper/pubstruct.py +42 -32
  79. deepdoctection/mapper/tpstruct.py +39 -19
  80. deepdoctection/mapper/xfundstruct.py +20 -13
  81. deepdoctection/pipe/__init__.py +1 -2
  82. deepdoctection/pipe/anngen.py +104 -62
  83. deepdoctection/pipe/base.py +226 -107
  84. deepdoctection/pipe/common.py +206 -123
  85. deepdoctection/pipe/concurrency.py +74 -47
  86. deepdoctection/pipe/doctectionpipe.py +108 -47
  87. deepdoctection/pipe/language.py +41 -24
  88. deepdoctection/pipe/layout.py +45 -18
  89. deepdoctection/pipe/lm.py +146 -78
  90. deepdoctection/pipe/order.py +196 -113
  91. deepdoctection/pipe/refine.py +111 -63
  92. deepdoctection/pipe/registry.py +1 -1
  93. deepdoctection/pipe/segment.py +213 -142
  94. deepdoctection/pipe/sub_layout.py +76 -46
  95. deepdoctection/pipe/text.py +52 -33
  96. deepdoctection/pipe/transform.py +8 -6
  97. deepdoctection/train/d2_frcnn_train.py +87 -69
  98. deepdoctection/train/hf_detr_train.py +72 -40
  99. deepdoctection/train/hf_layoutlm_train.py +85 -46
  100. deepdoctection/train/tp_frcnn_train.py +56 -28
  101. deepdoctection/utils/concurrency.py +59 -16
  102. deepdoctection/utils/context.py +40 -19
  103. deepdoctection/utils/develop.py +25 -17
  104. deepdoctection/utils/env_info.py +85 -36
  105. deepdoctection/utils/error.py +16 -10
  106. deepdoctection/utils/file_utils.py +246 -62
  107. deepdoctection/utils/fs.py +162 -43
  108. deepdoctection/utils/identifier.py +29 -16
  109. deepdoctection/utils/logger.py +49 -32
  110. deepdoctection/utils/metacfg.py +83 -21
  111. deepdoctection/utils/pdf_utils.py +119 -62
  112. deepdoctection/utils/settings.py +24 -10
  113. deepdoctection/utils/tqdm.py +10 -5
  114. deepdoctection/utils/transform.py +182 -46
  115. deepdoctection/utils/utils.py +61 -28
  116. deepdoctection/utils/viz.py +150 -104
  117. deepdoctection-0.43.dist-info/METADATA +376 -0
  118. deepdoctection-0.43.dist-info/RECORD +149 -0
  119. deepdoctection/analyzer/_config.py +0 -146
  120. deepdoctection-0.42.1.dist-info/METADATA +0 -431
  121. deepdoctection-0.42.1.dist-info/RECORD +0 -148
  122. {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.dist-info}/WHEEL +0 -0
  123. {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.dist-info}/licenses/LICENSE +0 -0
  124. {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.dist-info}/top_level.txt +0 -0
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
 
18
18
  """
19
- Module for mapping annotations in pubtabnet style structure
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 list, where each
107
- inner list has the same length. Each cell with a cell id can be located according to their row and column spans in
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
- :param row_spans: A list of list of row spans
111
- :param col_spans: A list of list of column spans
112
- :return: A list of list of the tiling of the table, indicating the precise place of each cell.
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
- :param tiling: A list of list of tiling of a table as returned from the `_tile_table`
259
- :return: A list of 3-tuples with row number, column number and cell id.
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, that resembles the output of an analyzer. The layout of the image is table spanning
273
- the full page, i.e. there is one table image annotation. Moreover, the table annotation has an image, with cells
274
- as image annotations.
275
-
276
- :param dp: Image
277
- :param html: list with html tags
278
- :param categories_name_as_key: category dictionary with all possible annotations
279
- :return: Image
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
- :param iterable: e.g. list
319
- :param value: any value
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
- :param dp: A datapoint in serialized Pubtabnet format.
342
- :param categories_name_as_key: A dict of categories, e.g. DatasetCategories.get_categories(name_as_key=True)
343
- :param load_image: If `True` it will load image to `Image.image`
344
- :param fake_score: If dp does not contain a score, a fake score with uniform random variables in (0,1)
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
- :param rows_and_cols: If set to `True`, synthetic "ITEM" ImageAnnotations will be added. Each item has a
347
- sub-category "row_col" that is equal to "ROW" or "COL".
348
- :param dd_pipe_like: This will generate an image identical to the output of the dd analyzer (e.g. table and words
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
- :param is_fintabnet: Set `True`, if this mapping is used for generating fintabnet datapoints.
351
- :param pubtables_like: Set `True`, the area covering the table will be tiled with non overlapping rows and columns
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
- :return: Image
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 image to a dict to be consumed by Tensorpack Faster-RCNN bounding box detection. Note, that the returned
46
- dict will not suffice for training as gt for RPN and anchors still need to be created.
47
-
48
- :param dp: Image
49
- :param add_mask: True is not implemented (yet).
50
- :param category_names: A list of category names for training a model. Pass nothing to train with all annotations
51
- :return: Dict with `image`, `gt_boxes`, `gt_labels` and `file_name`, provided there are some detected objects in the
52
- image
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
- Processing given image annotations through NMS. This is useful, if you want to supress some specific image
87
- annotation, e.g. given by name or returned through different predictors. This is the tf version, for pt check
88
- `mapper.d2struct`
89
-
90
- :param anns: A sequence of ImageAnnotations. All annotations will be treated as if they belong to one category
91
- :param threshold: NMS threshold
92
- :param image_id: id in order to get the embedding bounding box
93
- :param prio: If an annotation has prio, it will overwrite its given score to 1 so that it will never be suppressed
94
- :return: A list of annotation_ids that belong to the given input sequence and that survive the NMS process
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([ann.get_bounding_box(image_id).to_list(mode="xyxy") for ann in anns if ann.bounding_box
126
- is not None])
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 xfund data structure
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
- Map a datapoint of annotation structure as given as from xfund or funsd dataset in to an Image structure
54
-
55
- :param dp: A datapoint in dict structure as returned from the xfund or funsd dataset. Each datapoint must coincide
56
- with exactly one image sample.
57
- :param load_image: If 'True' it will load image to attr:`Image.image`
58
- :param fake_score: If dp does not contain a score, a fake score with uniform random variables in (0,1)
59
- will be added.
60
- :param categories_dict_name_as_key:
61
- :param token_class_names_mapping: A dictionary, mapping original label names to normalized category names
62
- :param ner_token_to_id_mapping: A dictionary, mapping token classes with bio tags (i.e. token tags) into their
63
- category ids.
64
- :return: Image
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")
@@ -16,8 +16,7 @@
16
16
  # limitations under the License.
17
17
 
18
18
  """
19
- Contains pipeline components that can be plugged into each other and predictors that are invoked by their
20
- respective component.
19
+ # Pipeline components and pipelines
21
20
  """
22
21
 
23
22
  from .anngen import *
@@ -16,10 +16,10 @@
16
16
  # limitations under the License.
17
17
 
18
18
  """
19
- Module for datapoint populating helpers
19
+ Datapoint manager
20
20
  """
21
21
  from dataclasses import asdict
22
- from typing import Mapping, Optional, Union
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
- Class whose methods provide an API for manipulating image datapoints. This includes the creation and storage of
37
- annotations in the cache of the image but also in the annotations themselves.
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
- assert that datapoint is passed
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
- Creating an image annotation from a raw `DetectionResult` dataclass. Beside dumping the annotation to the
89
- `ImageAnnotation` cache you can also dump the annotation to the `image` of an annotation with given
90
- `annotation_id`. This is handy if, you know, you want to send the sub image to a subsequent pipeline component.
91
-
92
- Moreover, it is possible to generate an Image of the given raw annotation and store it in its `image`. The
93
- resulting image is given as a sub image of `self` defined by it bounding box coordinates. Use `crop_image`
94
- to explicitly store the sub image as numpy array.
95
-
96
- :param detect_result: A `DetectionResult` in general coming from ObjectDetector
97
- :param to_annotation_id: Will dump the created image annotation to `image` of the given annotation_id.
98
- Requires the to_annotation to have a not `None` image.
99
- :param to_image: If True will populate `image`.
100
- :param crop_image: Makes only sense if to_image=True and if a numpy array is stored in the original image.
101
- Will generate `Image.image`.
102
- :param detect_result_max_width: If detect result has a different scaling scheme from the image it refers to,
103
- pass the max width possible so coords can be rescaled.
104
- :param detect_result_max_height: If detect result has a different scaling scheme from the image it refers to,
105
- pass the max height possible so coords can be rescaled.
106
- :return: the annotation_id of the generated image annotation
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
- Create a category annotation and dump it as sub category to an already created annotation.
175
-
176
- :param category_name: category name
177
- :param category_id: category id
178
- :param sub_cat_key: the key to dump the created annotation to.
179
- :param annotation_id: id, of the parent annotation. Currently, this can only be an image annotation.
180
- :param score: Add a score.
181
- :return: the annotation_id of the generated category annotation
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
- Create a container annotation and dump it as sub category to an already created annotation.
217
-
218
- :param category_name: category name
219
- :param category_id: category id
220
- :param sub_cat_key: the key to dump the created annotation to.
221
- :param annotation_id: id, of the parent annotation. Currently, this can only be an image annotation.
222
- :param value: A value to store
223
- :param score: Add a score.
224
- :return: annotation_id of the generated container annotation
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
- Create a relationship annotation and dump it to the target annotation.
281
+ Creates a relationship annotation and dumps it to the target annotation.
256
282
 
257
- :param relationship_name: The relationship key
258
- :param target_annotation_id: Annotation_id of the parent `ImageAnnotation`
259
- :param annotation_id: The annotation_id to dump the relationship to
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
- :return: Annotation_id of the parent `ImageAnnotation` for references if the dumpy has been successful
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 sub category of a summary annotation. If a summary of the given `annotation_id` does not exist, it
289
- will create a new one.
290
- :param summary_key: will store the category annotation as sub category
291
- :param summary_name: will create the summary name as category name
292
- :param summary_number: will store the value in category_id.
293
- :param summary_value: will create a ContainerAnnotation and store the corresponding value
294
- :param summary_score: will store the score
295
- :param annotation_id: id of the parent annotation. Note, that the parent annotation must have `image` to
296
- be not None.
297
- :return: `annotation_id` of the generated category annotation
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
- Deactivate annotation by given annotation_id
377
+ Deactivates the annotation by the given `annotation_id`.
345
378
 
346
- :param annotation_id: annotation_id
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
- """get single `ImageAnnotation`"""
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]