datamint 1.6.3.post1__py3-none-any.whl → 1.7.0__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 datamint might be problematic. Click here for more details.
- datamint/apihandler/annotation_api_handler.py +125 -3
- datamint/apihandler/base_api_handler.py +30 -26
- datamint/apihandler/root_api_handler.py +121 -35
- datamint/dataset/annotation.py +221 -0
- datamint/dataset/base_dataset.py +735 -483
- datamint/dataset/dataset.py +33 -16
- {datamint-1.6.3.post1.dist-info → datamint-1.7.0.dist-info}/METADATA +1 -1
- {datamint-1.6.3.post1.dist-info → datamint-1.7.0.dist-info}/RECORD +10 -9
- {datamint-1.6.3.post1.dist-info → datamint-1.7.0.dist-info}/WHEEL +0 -0
- {datamint-1.6.3.post1.dist-info → datamint-1.7.0.dist-info}/entry_points.txt +0 -0
datamint/dataset/dataset.py
CHANGED
|
@@ -7,6 +7,7 @@ import numpy as np
|
|
|
7
7
|
import logging
|
|
8
8
|
from PIL import Image
|
|
9
9
|
import albumentations
|
|
10
|
+
from datamint.dataset.annotation import Annotation
|
|
10
11
|
|
|
11
12
|
_LOGGER = logging.getLogger(__name__)
|
|
12
13
|
|
|
@@ -116,12 +117,12 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
116
117
|
if semantic_seg_merge_strategy is not None and not return_as_semantic_segmentation:
|
|
117
118
|
raise ValueError("semantic_seg_merge_strategy can only be used if return_as_semantic_segmentation is True")
|
|
118
119
|
|
|
119
|
-
def _load_segmentations(self, annotations: list[
|
|
120
|
+
def _load_segmentations(self, annotations: list[Annotation], img_shape) -> tuple[dict[str, list], dict[str, list]]:
|
|
120
121
|
"""
|
|
121
122
|
Load segmentations from annotations.
|
|
122
123
|
|
|
123
124
|
Args:
|
|
124
|
-
annotations: list of
|
|
125
|
+
annotations: list of Annotation objects
|
|
125
126
|
img_shape: shape of the image (#frames, C, H, W)
|
|
126
127
|
|
|
127
128
|
Returns:
|
|
@@ -142,14 +143,14 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
142
143
|
|
|
143
144
|
# Load segmentation annotations
|
|
144
145
|
for ann in annotations:
|
|
145
|
-
if ann
|
|
146
|
+
if ann.type != 'segmentation':
|
|
146
147
|
continue
|
|
147
|
-
if
|
|
148
|
+
if ann.file is None:
|
|
148
149
|
_LOGGER.warning(f"Segmentation annotation without file in annotations {ann}")
|
|
149
150
|
continue
|
|
150
|
-
author = ann
|
|
151
|
+
author = ann.created_by
|
|
151
152
|
|
|
152
|
-
segfilepath = ann
|
|
153
|
+
segfilepath = ann.file # png file
|
|
153
154
|
segfilepath = os.path.join(self.dataset_dir, segfilepath)
|
|
154
155
|
# FIXME: avoid enforcing resizing the mask
|
|
155
156
|
seg = (Image.open(segfilepath)
|
|
@@ -161,11 +162,11 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
161
162
|
seg = torch.from_numpy(seg)
|
|
162
163
|
seg = seg == 255 # binary mask
|
|
163
164
|
# map the segmentation label to the code
|
|
164
|
-
seg_code = self.frame_lcodes['segmentation'][ann
|
|
165
|
+
seg_code = self.frame_lcodes['segmentation'][ann.name]
|
|
165
166
|
if self.return_frame_by_frame:
|
|
166
167
|
frame_index = 0
|
|
167
168
|
else:
|
|
168
|
-
frame_index = ann
|
|
169
|
+
frame_index = ann.index
|
|
169
170
|
|
|
170
171
|
if author not in segmentations.keys():
|
|
171
172
|
segmentations[author] = [None] * nframes
|
|
@@ -308,7 +309,9 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
308
309
|
|
|
309
310
|
return augmented['image'], new_segmentations
|
|
310
311
|
|
|
311
|
-
def _seg_labels_to_names(self,
|
|
312
|
+
def _seg_labels_to_names(self,
|
|
313
|
+
seg_labels: dict | list | None
|
|
314
|
+
) -> dict | list | None:
|
|
312
315
|
"""
|
|
313
316
|
Convert segmentation label codes to label names.
|
|
314
317
|
|
|
@@ -330,10 +333,23 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
330
333
|
code_to_name = self.segmentation_labels_set
|
|
331
334
|
if isinstance(seg_labels, dict):
|
|
332
335
|
# author -> list of frame tensors
|
|
333
|
-
|
|
336
|
+
seg_names = {}
|
|
337
|
+
for author, labels in seg_labels.items():
|
|
338
|
+
if isinstance(labels, Tensor):
|
|
339
|
+
# single tensor for the author
|
|
340
|
+
seg_names[author] = [code_to_name[code.item()-1] for code in labels]
|
|
341
|
+
elif isinstance(labels, list):
|
|
342
|
+
# list of frame tensors
|
|
343
|
+
seg_names[author] = [[code_to_name[code.item()-1] for code in frame_labels]
|
|
344
|
+
for frame_labels in labels]
|
|
345
|
+
else:
|
|
346
|
+
_LOGGER.warning(
|
|
347
|
+
f"Unexpected segmentation labels format for author {author}: {type(labels)}. Returning None")
|
|
348
|
+
return None
|
|
349
|
+
return seg_names
|
|
334
350
|
elif isinstance(seg_labels, list):
|
|
335
351
|
# list of frame tensors
|
|
336
|
-
return [[code_to_name[code.item()] for code in labels] for labels in seg_labels]
|
|
352
|
+
return [[code_to_name[code.item()-1] for code in labels] for labels in seg_labels]
|
|
337
353
|
|
|
338
354
|
_LOGGER.warning(f"Unexpected segmentation labels format: {type(seg_labels)}. Returning None")
|
|
339
355
|
return None
|
|
@@ -388,6 +404,7 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
388
404
|
try:
|
|
389
405
|
if self.return_segmentations:
|
|
390
406
|
segmentations, seg_labels = self._load_segmentations(annotations, img.shape)
|
|
407
|
+
# seg_labels can be dict[str, list[Tensor]]
|
|
391
408
|
# apply mask transform
|
|
392
409
|
if self.mask_transform is not None:
|
|
393
410
|
for seglist in segmentations.values():
|
|
@@ -460,14 +477,14 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
460
477
|
return new_item
|
|
461
478
|
|
|
462
479
|
def _convert_labels_annotations(self,
|
|
463
|
-
annotations: list[
|
|
480
|
+
annotations: list[Annotation],
|
|
464
481
|
num_frames: int = None) -> dict[str, torch.Tensor]:
|
|
465
482
|
"""
|
|
466
483
|
Converts the annotations, of the same type and scope, to tensor of shape (num_frames, num_labels)
|
|
467
484
|
for each annotator.
|
|
468
485
|
|
|
469
486
|
Args:
|
|
470
|
-
annotations: list of
|
|
487
|
+
annotations: list of Annotation objects
|
|
471
488
|
num_frames: number of frames in the video
|
|
472
489
|
|
|
473
490
|
Returns:
|
|
@@ -489,14 +506,14 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
489
506
|
if len(annotations) == 0:
|
|
490
507
|
return frame_labels_byuser
|
|
491
508
|
for ann in annotations:
|
|
492
|
-
user_id = ann
|
|
509
|
+
user_id = ann.created_by
|
|
493
510
|
|
|
494
|
-
frame_idx = ann.
|
|
511
|
+
frame_idx = ann.index
|
|
495
512
|
|
|
496
513
|
if user_id not in frame_labels_byuser.keys():
|
|
497
514
|
frame_labels_byuser[user_id] = torch.zeros(size=labels_ret_size, dtype=torch.int32)
|
|
498
515
|
labels_onehot_i = frame_labels_byuser[user_id]
|
|
499
|
-
code = label2code[ann
|
|
516
|
+
code = label2code[ann.name]
|
|
500
517
|
if frame_idx is None:
|
|
501
518
|
labels_onehot_i[code] = 1
|
|
502
519
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: datamint
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: A library for interacting with the Datamint API, designed for efficient data management, processing and Deep Learning workflows.
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
datamint/__init__.py,sha256=7rKCCsaa4RBRTIfuHB708rai1xwDHLtkFNFJGKYG5D4,757
|
|
2
|
-
datamint/apihandler/annotation_api_handler.py,sha256=
|
|
2
|
+
datamint/apihandler/annotation_api_handler.py,sha256=HnWiG2ebq08mdaazTXVbkuwvh6fmKIKt8uqAOf3Y1jU,57013
|
|
3
3
|
datamint/apihandler/api_handler.py,sha256=cdVSddrFCKlF_BJ81LO1aJ0OP49rssjpNEFzJ6Q7YyY,384
|
|
4
|
-
datamint/apihandler/base_api_handler.py,sha256=
|
|
4
|
+
datamint/apihandler/base_api_handler.py,sha256=dWLiowyuP1XiGfNc-_D5oQSmJdfR0Quy0ToeJlkRA8s,11911
|
|
5
5
|
datamint/apihandler/dto/annotation_dto.py,sha256=qId1RK1VO7dXrvGJ7dqJ31jBQB7Z8yy5x0tLSiMxTB4,7105
|
|
6
6
|
datamint/apihandler/exp_api_handler.py,sha256=hFUgUgBc5rL7odK7gTW3MnrvMY1pVfJUpUdzRNobMQE,6226
|
|
7
|
-
datamint/apihandler/root_api_handler.py,sha256=
|
|
7
|
+
datamint/apihandler/root_api_handler.py,sha256=qedldmtt0oNFoaxyMAskd0A5Uy-6KsuPd7Jl1jKHpGY,55450
|
|
8
8
|
datamint/client_cmd_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
datamint/client_cmd_tools/datamint_config.py,sha256=md7dnWrbl10lPtXKbmD9yo6onLJsajeG8Vz0ZWH1v4M,8181
|
|
10
10
|
datamint/client_cmd_tools/datamint_upload.py,sha256=890USkrtaH23mNjTRYVHWce2q9jSmkUNHIP_e8fnJRM,29502
|
|
11
11
|
datamint/configs.py,sha256=Bdp6NydYwyCJ2dk19_gf_o3M2ZyQOmMHpLi8wEWNHUk,1426
|
|
12
12
|
datamint/dataset/__init__.py,sha256=4PlUKSvVhdfQvvuq8jQXrkdqnot-iTTizM3aM1vgSwg,47
|
|
13
|
-
datamint/dataset/
|
|
14
|
-
datamint/dataset/
|
|
13
|
+
datamint/dataset/annotation.py,sha256=qN1IMjdfLD2ceQ6va3l76jOXA8Vb_c-eBk1oWQu6hW0,7994
|
|
14
|
+
datamint/dataset/base_dataset.py,sha256=9aMzfrBBw8_Atro4j325OgBPXSQtcbRwXrdIpS7bM3Q,49251
|
|
15
|
+
datamint/dataset/dataset.py,sha256=fdcgxB9NKvPEdr9S6TOeAIqFW38PdhmCiYsit6u5Wxc,27314
|
|
15
16
|
datamint/examples/__init__.py,sha256=zcYnd5nLVme9GCTPYH-1JpGo8xXK2WEYvhzcy_2alZc,39
|
|
16
17
|
datamint/examples/example_projects.py,sha256=7Nb_EaIdzJTQa9zopqc-WhTBQWQJSoQZ_KjRS4PB4FI,2931
|
|
17
18
|
datamint/experiment/__init__.py,sha256=5qQOMzoG17DEd1YnTF-vS0qiM-DGdbNh42EUo91CRhQ,34
|
|
@@ -21,7 +22,7 @@ datamint/logging.yaml,sha256=a5dsATpul7QHeUHB2TjABFjWaPXBMbO--dgn8GlRqwk,483
|
|
|
21
22
|
datamint/utils/logging_utils.py,sha256=DvoA35ATYG3JTwfXEXYawDyKRfHeCrH0a9czfkmz8kM,1851
|
|
22
23
|
datamint/utils/torchmetrics.py,sha256=lwU0nOtsSWfebyp7dvjlAggaqXtj5ohSEUXOg3L0hJE,2837
|
|
23
24
|
datamint/utils/visualization.py,sha256=yaUVAOHar59VrGUjpAWv5eVvQSfztFG0eP9p5Vt3l-M,4470
|
|
24
|
-
datamint-1.
|
|
25
|
-
datamint-1.
|
|
26
|
-
datamint-1.
|
|
27
|
-
datamint-1.
|
|
25
|
+
datamint-1.7.0.dist-info/METADATA,sha256=GWsxt2qSpYc64h5DbgScsg7w-FRy1_35Gi38TJrRLOE,4090
|
|
26
|
+
datamint-1.7.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
27
|
+
datamint-1.7.0.dist-info/entry_points.txt,sha256=mn5H6jPjO-rY0W0CAZ6Z_KKWhMLvyVaSpoqk77jlTI4,145
|
|
28
|
+
datamint-1.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|