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.
- deepdoctection/__init__.py +2 -1
- deepdoctection/analyzer/__init__.py +2 -1
- deepdoctection/analyzer/config.py +904 -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 +157 -106
- 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 +196 -113
- 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 +25 -17
- deepdoctection/utils/env_info.py +85 -36
- deepdoctection/utils/error.py +16 -10
- deepdoctection/utils/file_utils.py +246 -62
- 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.dist-info/METADATA +376 -0
- deepdoctection-0.43.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.dist-info}/WHEEL +0 -0
- {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.dist-info}/licenses/LICENSE +0 -0
- {deepdoctection-0.42.1.dist-info → deepdoctection-0.43.dist-info}/top_level.txt +0 -0
deepdoctection/dataflow/stats.py
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"""
|
|
19
19
|
Dataflows for calculating statistical values of the underlying dataset
|
|
20
20
|
"""
|
|
21
|
+
|
|
21
22
|
from typing import Any, Optional, Union
|
|
22
23
|
|
|
23
24
|
import numpy as np
|
|
@@ -32,14 +33,20 @@ class MeanFromDataFlow(ProxyDataFlow):
|
|
|
32
33
|
"""
|
|
33
34
|
Get the mean of some dataflow. Takes a component from a dataflow and calculates iteratively the mean.
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
Example:
|
|
37
|
+
```python
|
|
38
|
+
df: some dataflow
|
|
39
|
+
MeanFromDataFlow(df).start() # If you want to put MeanFromDataFlow at the end of a dataflow
|
|
40
|
+
|
|
41
|
+
or
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
df: some dataflow
|
|
40
|
-
df = MeanFromDataFlow(df)
|
|
43
|
+
df: some dataflow
|
|
44
|
+
df = MeanFromDataFlow(df)
|
|
41
45
|
|
|
42
46
|
is also possible. Testing with the progress bar will stop once the requested size has been reached.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
43
50
|
"""
|
|
44
51
|
|
|
45
52
|
def __init__(
|
|
@@ -50,16 +57,18 @@ class MeanFromDataFlow(ProxyDataFlow):
|
|
|
50
57
|
max_datapoints: Optional[int] = None,
|
|
51
58
|
):
|
|
52
59
|
"""
|
|
53
|
-
:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
Args:
|
|
61
|
+
df: the dataflow to test
|
|
62
|
+
axis: The axis along which to calculate the mean. It will always calculate the mean along
|
|
63
|
+
the dataflow length axis, which is the 0th axis. E.g. for calculating the mean of an image dataset
|
|
64
|
+
use
|
|
65
|
+
```python
|
|
66
|
+
MeanFromDataFlow(df,key="image",axis=(0,1,2)).start()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
key: The datapoint key giving the values to evaluate the mean. If None it tries to use
|
|
70
|
+
the whole datapoint.
|
|
71
|
+
max_datapoints: Will stop considering datapoints with index>max_datapoints.
|
|
63
72
|
"""
|
|
64
73
|
|
|
65
74
|
super().__init__(df)
|
|
@@ -149,17 +158,19 @@ class StdFromDataFlow(ProxyDataFlow):
|
|
|
149
158
|
Gets the standard deviation of some dataflow. Takes a component from a dataflow and calculates iteratively
|
|
150
159
|
the standard deviation.
|
|
151
160
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
Example:
|
|
162
|
+
```python
|
|
163
|
+
df= ...
|
|
164
|
+
StdFromDataFlow(df).start()
|
|
156
165
|
|
|
157
166
|
if you want to put StdFromDataFlow at the end of a dataflow
|
|
158
167
|
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
df: some dataflow
|
|
169
|
+
df = StdFromDataFlow(df)
|
|
161
170
|
|
|
162
171
|
is also possible. The testing with the progress bar will stop once the requested size has been reached.
|
|
172
|
+
```
|
|
173
|
+
|
|
163
174
|
"""
|
|
164
175
|
|
|
165
176
|
def __init__(
|
|
@@ -170,16 +181,18 @@ class StdFromDataFlow(ProxyDataFlow):
|
|
|
170
181
|
max_datapoints: Optional[int] = None,
|
|
171
182
|
):
|
|
172
183
|
"""
|
|
173
|
-
:
|
|
174
|
-
|
|
184
|
+
Args:
|
|
185
|
+
df: the dataflow to test
|
|
186
|
+
axis: The axis along which to calculate the mean. It will always calculate the std along
|
|
175
187
|
the dataflow length axis, which is the 0th axis. E.g. for calculating the mean of an image dataset
|
|
176
188
|
use
|
|
177
|
-
|
|
189
|
+
```python
|
|
178
190
|
StdFromDataFlow(df,key="image",axis=(0,1,2)).start()
|
|
191
|
+
```
|
|
179
192
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
193
|
+
key: The datapoint key giving the values to evaluate the std. If None it tries to use
|
|
194
|
+
the whole datapoint.
|
|
195
|
+
max_datapoints: Will stop considering datapoints with index>max_datapoints.
|
|
183
196
|
"""
|
|
184
197
|
|
|
185
198
|
super().__init__(df)
|
|
@@ -266,6 +279,6 @@ class StdFromDataFlow(ProxyDataFlow):
|
|
|
266
279
|
var = (ex2 - (ex * ex) / n) / (n - 1)
|
|
267
280
|
self.std = np.sqrt(var)
|
|
268
281
|
|
|
269
|
-
logger.info(LoggingRecord(f"Standard deviation from
|
|
282
|
+
logger.info(LoggingRecord(f"Standard deviation from {n} datapoints along axis {self.axis}: {self.std}"))
|
|
270
283
|
|
|
271
284
|
return self.std
|
|
@@ -16,17 +16,15 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
|
|
18
18
|
"""
|
|
19
|
-
|
|
19
|
+
# Core data model for single pages
|
|
20
20
|
|
|
21
|
-
A
|
|
22
|
-
datasets or the predictions from the pipelines, into a
|
|
21
|
+
A fundamental architectural decision in the **deep**doctection framework is to convert all data, be it those from
|
|
22
|
+
datasets or the predictions from the pipelines, into a standardized format. This procedure leads to the following
|
|
23
23
|
simplifications:
|
|
24
24
|
|
|
25
|
-
- Data of the training environment can be transported in the production environment (i.e. through
|
|
25
|
+
- Data of the training environment can be transported in the production environment (i.e. through pipelines)
|
|
26
26
|
without further adjustments.
|
|
27
|
-
|
|
28
27
|
- Datasets of different origins can be merged quickly, so that training data with greater variability arise.
|
|
29
|
-
|
|
30
28
|
- Pipeline environment components can be executed one after the other without conversion measures.
|
|
31
29
|
|
|
32
30
|
The disadvantage of carrying out any redundant transformations and thus experiencing a loss of performance is accepted.
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
|
|
18
18
|
"""
|
|
19
|
-
Dataclass for
|
|
19
|
+
Dataclass for `Annotation`s and their sub-classes.
|
|
20
20
|
"""
|
|
21
|
+
|
|
21
22
|
from __future__ import annotations
|
|
22
23
|
|
|
23
24
|
from abc import ABC, abstractmethod
|
|
@@ -88,20 +89,23 @@ class Annotation(ABC):
|
|
|
88
89
|
value is to set an external id, which in turn creates an annotation id as a function of this.
|
|
89
90
|
An annotation id can only be explicitly set, provided the value is a md5 hash.
|
|
90
91
|
|
|
91
|
-
Note
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
Note:
|
|
93
|
+
Ids will be generated automatically if the annotation object is dumped in a parent container,
|
|
94
|
+
either an image or an annotation (e.g. sub-category). If no id is supplied, the `annotation_id` is created
|
|
95
|
+
depending on the defining attributes (key and value pairs) as specified in the return value of
|
|
96
|
+
`get_defining_attributes`.
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
Attributes:
|
|
99
|
+
active: Always set to `True`. You can change the value using `deactivate` .
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
external_id: A string or integer value for generating an annotation id. Note, that the resulting annotation
|
|
102
|
+
id will not depend on the defining attributes.
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
_annotation_id: Unique id for annotations. Will always be given as string representation of a md5-hash.
|
|
105
|
+
service_id: Service that generated the annotation. This will be the name of a pipeline component
|
|
106
|
+
model_id: Model that generated the annotation. This will be the name of a model in a component
|
|
107
|
+
session_id: Session id for the annotation. This will be the id of the session in which the annotation was
|
|
108
|
+
created.
|
|
105
109
|
"""
|
|
106
110
|
|
|
107
111
|
active: bool = field(default=True, init=False, repr=True)
|
|
@@ -114,7 +118,7 @@ class Annotation(ABC):
|
|
|
114
118
|
def __post_init__(self) -> None:
|
|
115
119
|
"""
|
|
116
120
|
Will check, if the external id provided is an uuid. If not will use the external id as seed for defining an
|
|
117
|
-
uuid
|
|
121
|
+
`uuid`.
|
|
118
122
|
"""
|
|
119
123
|
|
|
120
124
|
if self.external_id is not None:
|
|
@@ -128,7 +132,7 @@ class Annotation(ABC):
|
|
|
128
132
|
@property
|
|
129
133
|
def annotation_id(self) -> str:
|
|
130
134
|
"""
|
|
131
|
-
annotation_id
|
|
135
|
+
`annotation_id`
|
|
132
136
|
"""
|
|
133
137
|
if self._annotation_id:
|
|
134
138
|
return self._annotation_id
|
|
@@ -137,7 +141,7 @@ class Annotation(ABC):
|
|
|
137
141
|
@annotation_id.setter
|
|
138
142
|
def annotation_id(self, input_id: str) -> None:
|
|
139
143
|
"""
|
|
140
|
-
annotation_id setter
|
|
144
|
+
`annotation_id` setter
|
|
141
145
|
"""
|
|
142
146
|
if self._annotation_id is not None:
|
|
143
147
|
raise AnnotationError("Annotation_id already defined and cannot be reset")
|
|
@@ -155,7 +159,8 @@ class Annotation(ABC):
|
|
|
155
159
|
describe the annotation object. If you do not provide an external id, only the defining attributes will be used
|
|
156
160
|
for generating the annotation id.
|
|
157
161
|
|
|
158
|
-
:
|
|
162
|
+
Returns:
|
|
163
|
+
A list of attributes.
|
|
159
164
|
"""
|
|
160
165
|
raise NotImplementedError()
|
|
161
166
|
|
|
@@ -171,9 +176,12 @@ class Annotation(ABC):
|
|
|
171
176
|
Defines the `annotation_id` by attributes of the annotation class as well as by external parameters given by a
|
|
172
177
|
tuple or list of container id contexts.
|
|
173
178
|
|
|
174
|
-
:
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
Args:
|
|
180
|
+
annotation: The annotation instance for which the id should be generated.
|
|
181
|
+
container_id_context: A tuple/list of strings on which you want the resulting annotation id to depend on.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
A uuid that uniquely characterizes the annotation.
|
|
177
185
|
"""
|
|
178
186
|
for container_id in container_id_context:
|
|
179
187
|
if container_id is not None:
|
|
@@ -187,7 +195,8 @@ class Annotation(ABC):
|
|
|
187
195
|
Returning the full dataclass as dict. Uses the custom `convert.as_dict` to disregard attributes defined by
|
|
188
196
|
`remove_keys`.
|
|
189
197
|
|
|
190
|
-
:
|
|
198
|
+
Returns:
|
|
199
|
+
A custom dict.
|
|
191
200
|
"""
|
|
192
201
|
|
|
193
202
|
img_dict = as_dict(self, dict_factory=dict)
|
|
@@ -206,9 +215,11 @@ class Annotation(ABC):
|
|
|
206
215
|
"""
|
|
207
216
|
Method to initialize a derived class from dict.
|
|
208
217
|
|
|
209
|
-
:
|
|
218
|
+
Args:
|
|
219
|
+
kwargs: dict with `Annotation` attributes
|
|
210
220
|
|
|
211
|
-
:
|
|
221
|
+
Returns:
|
|
222
|
+
Annotation instance
|
|
212
223
|
"""
|
|
213
224
|
raise NotImplementedError()
|
|
214
225
|
|
|
@@ -218,7 +229,8 @@ class Annotation(ABC):
|
|
|
218
229
|
"""
|
|
219
230
|
Similar to `get_defining_attributes` but for `state_id`
|
|
220
231
|
|
|
221
|
-
:
|
|
232
|
+
Returns:
|
|
233
|
+
A list of attributes.
|
|
222
234
|
"""
|
|
223
235
|
raise NotImplementedError()
|
|
224
236
|
|
|
@@ -228,7 +240,8 @@ class Annotation(ABC):
|
|
|
228
240
|
Different to `annotation_id` this id does depend on every defined state attributes and might therefore change
|
|
229
241
|
over time.
|
|
230
242
|
|
|
231
|
-
:
|
|
243
|
+
Returns:
|
|
244
|
+
Annotation state instance
|
|
232
245
|
"""
|
|
233
246
|
container_ids = []
|
|
234
247
|
attributes = self.get_state_attributes()
|
|
@@ -270,20 +283,18 @@ class CategoryAnnotation(Annotation):
|
|
|
270
283
|
`dump_relationship`. If a key is already available as a sub-category, it must be explicitly removed using the
|
|
271
284
|
`remove_sub_category` before replacing the sub-category.
|
|
272
285
|
|
|
273
|
-
Note
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
`relationships`: Do not access the dict directly either. Use `get_relationship` or
|
|
286
|
-
`dump_relationship` instead.
|
|
286
|
+
Note:
|
|
287
|
+
Sub categories are only accepted as category annotations. Relationships, on the other hand, are only
|
|
288
|
+
managed by passing the `annotation_id`.
|
|
289
|
+
|
|
290
|
+
Attributes:
|
|
291
|
+
category_name: String will be used for selecting specific annotations. Use upper case strings.
|
|
292
|
+
category_id: When setting a value will accept strings and ints. Will be stored as string.
|
|
293
|
+
score: Score of a prediction.
|
|
294
|
+
sub_categories: Do not access the dict directly. Rather use the access `get_sub_category` resp.
|
|
295
|
+
`dump_sub_category`.
|
|
296
|
+
relationships: Do not access the dict directly either. Use `get_relationship` or
|
|
297
|
+
`dump_relationship` instead.
|
|
287
298
|
"""
|
|
288
299
|
|
|
289
300
|
category_name: TypeOrStr = field(default=DefaultType.DEFAULT_TYPE)
|
|
@@ -295,7 +306,7 @@ class CategoryAnnotation(Annotation):
|
|
|
295
306
|
|
|
296
307
|
@property # type: ignore
|
|
297
308
|
def category_name(self) -> ObjectTypes:
|
|
298
|
-
"""
|
|
309
|
+
"""`category_name`"""
|
|
299
310
|
return self._category_name
|
|
300
311
|
|
|
301
312
|
@category_name.setter
|
|
@@ -312,13 +323,14 @@ class CategoryAnnotation(Annotation):
|
|
|
312
323
|
self, sub_category_name: TypeOrStr, annotation: CategoryAnnotation, *container_id_context: Optional[str]
|
|
313
324
|
) -> None:
|
|
314
325
|
"""
|
|
315
|
-
Storage of sub
|
|
326
|
+
Storage of sub categories. As sub categories usually only depend on very few attributes and the parent
|
|
316
327
|
category cannot yet be stored in a comprehensive container, it is possible to include a context of the
|
|
317
328
|
annotation id in order to ensure that the sub-category annotation id is unambiguously created.
|
|
318
329
|
|
|
319
|
-
:
|
|
320
|
-
|
|
321
|
-
|
|
330
|
+
Args:
|
|
331
|
+
sub_category_name: key for defining the sub category.
|
|
332
|
+
annotation: Annotation instance to dump
|
|
333
|
+
container_id_context: Tuple/list of context ids.
|
|
322
334
|
"""
|
|
323
335
|
|
|
324
336
|
if sub_category_name in self.sub_categories:
|
|
@@ -344,9 +356,11 @@ class CategoryAnnotation(Annotation):
|
|
|
344
356
|
"""
|
|
345
357
|
Return a sub category by its key.
|
|
346
358
|
|
|
347
|
-
:
|
|
359
|
+
Args:
|
|
360
|
+
sub_category_name: The key of the sub-category.
|
|
348
361
|
|
|
349
|
-
:
|
|
362
|
+
Returns:
|
|
363
|
+
sub category as `CategoryAnnotation`
|
|
350
364
|
"""
|
|
351
365
|
return self.sub_categories[sub_category_name]
|
|
352
366
|
|
|
@@ -355,7 +369,8 @@ class CategoryAnnotation(Annotation):
|
|
|
355
369
|
Removes a sub category with a given key. Necessary to call, when you want to replace an already dumped sub
|
|
356
370
|
category.
|
|
357
371
|
|
|
358
|
-
:
|
|
372
|
+
Args:
|
|
373
|
+
key: A key to a sub category.
|
|
359
374
|
"""
|
|
360
375
|
|
|
361
376
|
if key in self.sub_categories:
|
|
@@ -363,11 +378,14 @@ class CategoryAnnotation(Annotation):
|
|
|
363
378
|
|
|
364
379
|
def dump_relationship(self, key: TypeOrStr, annotation_id: str) -> None:
|
|
365
380
|
"""
|
|
366
|
-
Dumps an `annotation_id` to a given key, in order to store relations between annotations.
|
|
367
|
-
referenced annotation must be stored elsewhere.
|
|
381
|
+
Dumps an `annotation_id` to a given key, in order to store relations between annotations.
|
|
368
382
|
|
|
369
|
-
:
|
|
370
|
-
|
|
383
|
+
Note:
|
|
384
|
+
The referenced annotation must be stored elsewhere.
|
|
385
|
+
|
|
386
|
+
Args:
|
|
387
|
+
key: The key, where to place the `annotation_id`.
|
|
388
|
+
annotation_id: The `annotation_id` to dump
|
|
371
389
|
"""
|
|
372
390
|
if not is_uuid_like(annotation_id):
|
|
373
391
|
raise UUIDError("Annotation_id must be uuid")
|
|
@@ -382,8 +400,11 @@ class CategoryAnnotation(Annotation):
|
|
|
382
400
|
"""
|
|
383
401
|
Returns a list of annotation ids stored with a given relationship key.
|
|
384
402
|
|
|
385
|
-
:
|
|
386
|
-
|
|
403
|
+
Args:
|
|
404
|
+
key: The key for the required relationship.
|
|
405
|
+
|
|
406
|
+
Returns:
|
|
407
|
+
A (possibly) empty list of `annotation_id`s.
|
|
387
408
|
"""
|
|
388
409
|
if key in self.relationships:
|
|
389
410
|
return self.relationships[key]
|
|
@@ -394,9 +415,10 @@ class CategoryAnnotation(Annotation):
|
|
|
394
415
|
Remove relationship by some given keys and ids. If no annotation ids are provided all relationship according
|
|
395
416
|
to the key will be removed.
|
|
396
417
|
|
|
397
|
-
:
|
|
398
|
-
|
|
399
|
-
|
|
418
|
+
Args:
|
|
419
|
+
key: A relationship key.
|
|
420
|
+
annotation_ids: A single annotation_id or a list. Will remove only the relation with given
|
|
421
|
+
`annotation_ids`, provided not None is passed as argument.
|
|
400
422
|
"""
|
|
401
423
|
|
|
402
424
|
if annotation_ids is not None:
|
|
@@ -419,7 +441,8 @@ class CategoryAnnotation(Annotation):
|
|
|
419
441
|
"""
|
|
420
442
|
A list of attributes to suspend from as_dict creation.
|
|
421
443
|
|
|
422
|
-
:
|
|
444
|
+
Returns:
|
|
445
|
+
list of attributes.
|
|
423
446
|
"""
|
|
424
447
|
return ["_category_name"]
|
|
425
448
|
|
|
@@ -441,11 +464,12 @@ class ImageAnnotation(CategoryAnnotation):
|
|
|
441
464
|
generating an image from the annotation and then saving it there. Compare with the method `image.Image.
|
|
442
465
|
image_ann_to_image`, which naturally populates this attribute.
|
|
443
466
|
|
|
444
|
-
|
|
445
|
-
|
|
467
|
+
Attributes:
|
|
468
|
+
bounding_box: Regarding the coordinate system, if you have to define a prediction, use the system of the
|
|
469
|
+
image where the object has been detected.
|
|
446
470
|
|
|
447
|
-
|
|
448
|
-
|
|
471
|
+
image: Image, defined by the bounding box and cropped from its parent image. Populate this attribute with
|
|
472
|
+
`Image.image_ann_to_image`.
|
|
449
473
|
"""
|
|
450
474
|
|
|
451
475
|
bounding_box: Optional[BoundingBox] = field(default=None)
|
|
@@ -467,7 +491,13 @@ class ImageAnnotation(CategoryAnnotation):
|
|
|
467
491
|
|
|
468
492
|
def get_bounding_box(self, image_id: Optional[str] = None) -> BoundingBox:
|
|
469
493
|
"""Get bounding from image embeddings or, if not available or if `image_id` is not provided,
|
|
470
|
-
from `bounding_box`.
|
|
494
|
+
from `bounding_box`.
|
|
495
|
+
|
|
496
|
+
Returns:
|
|
497
|
+
BoundingBox: A bounding box of the annotation.
|
|
498
|
+
|
|
499
|
+
Raises:
|
|
500
|
+
ValueError: If no bounding box is available."""
|
|
471
501
|
if self.image and image_id:
|
|
472
502
|
box = self.image.get_embedding(image_id)
|
|
473
503
|
else:
|
|
@@ -477,16 +507,23 @@ class ImageAnnotation(CategoryAnnotation):
|
|
|
477
507
|
raise AnnotationError(f"bounding_box has not been initialized for {self.annotation_id}")
|
|
478
508
|
|
|
479
509
|
def get_summary(self, key: ObjectTypes) -> CategoryAnnotation:
|
|
480
|
-
"""Get summary sub categories from `image`.
|
|
510
|
+
"""Get summary sub categories from `image`.
|
|
511
|
+
|
|
512
|
+
Returns:
|
|
513
|
+
CategoryAnnotation: A summary sub category of the image.
|
|
514
|
+
|
|
515
|
+
Raises:
|
|
516
|
+
ValueError: If `key` is not available"""
|
|
517
|
+
|
|
481
518
|
if self.image:
|
|
482
519
|
return self.image.summary.get_sub_category(key)
|
|
483
520
|
raise AnnotationError(f"Summary does not exist for {self.annotation_id} and key: {key}")
|
|
484
521
|
|
|
485
522
|
def get_annotation_map(self) -> defaultdict[str, list[AnnotationMap]]:
|
|
486
523
|
"""
|
|
487
|
-
Returns
|
|
488
|
-
|
|
489
|
-
|
|
524
|
+
Returns:
|
|
525
|
+
A `defaultdict` with `annotation_id`s as keys and a list of `AnnotationMap` instances as values for all
|
|
526
|
+
sub categories, relationships and image summaries.
|
|
490
527
|
"""
|
|
491
528
|
annotation_id_dict = defaultdict(list)
|
|
492
529
|
annotation_id_dict[self.annotation_id].append(AnnotationMap(image_annotation_id=self.annotation_id))
|
|
@@ -515,7 +552,8 @@ class ContainerAnnotation(CategoryAnnotation):
|
|
|
515
552
|
A dataclass for transporting values along with categorical attributes. Use these types of annotations as special
|
|
516
553
|
types of sub categories.
|
|
517
554
|
|
|
518
|
-
|
|
555
|
+
Attributes:
|
|
556
|
+
value: Attribute to store the value. Use strings.
|
|
519
557
|
"""
|
|
520
558
|
|
|
521
559
|
value: Optional[Union[list[str], str]] = field(default=None)
|