datamint 2.1.4__py3-none-any.whl → 2.2.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/dataset/base_dataset.py +0 -3
- datamint/dataset/dataset.py +16 -10
- {datamint-2.1.4.dist-info → datamint-2.2.0.dist-info}/METADATA +2 -2
- {datamint-2.1.4.dist-info → datamint-2.2.0.dist-info}/RECORD +6 -6
- {datamint-2.1.4.dist-info → datamint-2.2.0.dist-info}/WHEEL +0 -0
- {datamint-2.1.4.dist-info → datamint-2.2.0.dist-info}/entry_points.txt +0 -0
datamint/dataset/base_dataset.py
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import requests
|
|
3
|
-
from tqdm.auto import tqdm
|
|
4
3
|
from typing import Optional, Callable, Any, Literal, Sequence
|
|
5
4
|
import logging
|
|
6
5
|
import shutil
|
|
7
6
|
import json
|
|
8
|
-
import yaml
|
|
9
7
|
import pydicom
|
|
10
8
|
from pydicom.dataset import FileDataset
|
|
11
9
|
import numpy as np
|
|
12
|
-
from datamint import configs
|
|
13
10
|
from torch.utils.data import DataLoader
|
|
14
11
|
import torch
|
|
15
12
|
from torch import Tensor
|
datamint/dataset/dataset.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .base_dataset import DatamintBaseDataset
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Optional, Callable, Any, Literal, Sequence
|
|
3
3
|
import torch
|
|
4
4
|
from torch import Tensor
|
|
5
5
|
import os
|
|
@@ -120,7 +120,7 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
120
120
|
|
|
121
121
|
def _load_segmentations(self,
|
|
122
122
|
annotations: Sequence[Annotation],
|
|
123
|
-
img_shape) -> tuple[dict[str, list], dict[str, list]]:
|
|
123
|
+
img_shape) -> tuple[dict[str, list], dict[str, list], dict[str, Any]]:
|
|
124
124
|
"""
|
|
125
125
|
Load segmentations from annotations.
|
|
126
126
|
|
|
@@ -129,12 +129,13 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
129
129
|
img_shape: shape of the image (#frames, C, H, W)
|
|
130
130
|
|
|
131
131
|
Returns:
|
|
132
|
-
tuple[dict[str, list], dict[str, list]]: a tuple of two dictionaries.
|
|
132
|
+
tuple[dict[str, list], dict[str, list], dict[str, Any]]: a tuple of two dictionaries and additional metadata.
|
|
133
133
|
The first dictionary is author -> list of #frames tensors, each tensor has shape (#instances_i, H, W).
|
|
134
134
|
The second dictionary is author -> list of #frames segmentation labels (tensors).
|
|
135
135
|
"""
|
|
136
136
|
segmentations = {}
|
|
137
137
|
seg_labels = {}
|
|
138
|
+
seg_metainfos = {}
|
|
138
139
|
|
|
139
140
|
if self.return_frame_by_frame:
|
|
140
141
|
assert len(img_shape) == 3, f"img_shape must have 3 dimensions, got {img_shape}"
|
|
@@ -155,11 +156,15 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
155
156
|
|
|
156
157
|
segfilepath = ann.file # png file
|
|
157
158
|
segfilepath = os.path.join(self.dataset_dir, segfilepath)
|
|
158
|
-
seg = read_array_normalized(segfilepath) # (frames, C, H, W)
|
|
159
|
+
seg, seg_metainfo = read_array_normalized(segfilepath, return_metainfo=True) # (frames, C, H, W)
|
|
159
160
|
if seg.shape[1] != 1:
|
|
160
161
|
raise ValueError(f"Segmentation file must have 1 channel, got {seg.shape} in {segfilepath}")
|
|
161
162
|
seg = seg[:, 0, :, :] # (frames, H, W)
|
|
162
|
-
|
|
163
|
+
|
|
164
|
+
if seg_metainfo is None:
|
|
165
|
+
raise Exception
|
|
166
|
+
seg_metainfos[author] = seg_metainfo
|
|
167
|
+
|
|
163
168
|
# # FIXME: avoid enforcing resizing the mask
|
|
164
169
|
# seg = (Image.open(segfilepath)
|
|
165
170
|
# .convert('L')
|
|
@@ -217,7 +222,7 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
217
222
|
author_segs[i] = torch.zeros((0, h, w), dtype=torch.bool)
|
|
218
223
|
author_labels[i] = torch.zeros(0, dtype=torch.int32)
|
|
219
224
|
|
|
220
|
-
return segmentations, seg_labels
|
|
225
|
+
return segmentations, seg_labels, seg_metainfos
|
|
221
226
|
|
|
222
227
|
def _instanceseg2semanticseg(self,
|
|
223
228
|
segmentations: Sequence[Tensor],
|
|
@@ -273,19 +278,19 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
273
278
|
raise ValueError(f"Unknown semantic_seg_merge_strategy: {self.semantic_seg_merge_strategy}")
|
|
274
279
|
return merged_segs.to(torch.get_default_dtype())
|
|
275
280
|
|
|
276
|
-
def _apply_semantic_seg_merge_strategy_union(self, segmentations:
|
|
281
|
+
def _apply_semantic_seg_merge_strategy_union(self, segmentations: dict[str, torch.Tensor]) -> torch.Tensor:
|
|
277
282
|
new_segmentations = torch.zeros_like(list(segmentations.values())[0])
|
|
278
283
|
for seg in segmentations.values():
|
|
279
284
|
new_segmentations += seg
|
|
280
285
|
return new_segmentations.bool()
|
|
281
286
|
|
|
282
|
-
def _apply_semantic_seg_merge_strategy_intersection(self, segmentations:
|
|
287
|
+
def _apply_semantic_seg_merge_strategy_intersection(self, segmentations: dict[str, torch.Tensor]) -> torch.Tensor:
|
|
283
288
|
new_segmentations = torch.ones_like(list(segmentations.values())[0])
|
|
284
289
|
for seg in segmentations.values():
|
|
285
290
|
new_segmentations += seg
|
|
286
291
|
return new_segmentations.bool()
|
|
287
292
|
|
|
288
|
-
def _apply_semantic_seg_merge_strategy_mode(self, segmentations:
|
|
293
|
+
def _apply_semantic_seg_merge_strategy_mode(self, segmentations: dict[str, torch.Tensor]) -> torch.Tensor:
|
|
289
294
|
new_segmentations = torch.zeros_like(list(segmentations.values())[0])
|
|
290
295
|
for seg in segmentations.values():
|
|
291
296
|
new_segmentations += seg
|
|
@@ -428,7 +433,7 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
428
433
|
|
|
429
434
|
try:
|
|
430
435
|
if self.return_segmentations:
|
|
431
|
-
segmentations, seg_labels = self._load_segmentations(annotations, img.shape)
|
|
436
|
+
segmentations, seg_labels, seg_metainfos = self._load_segmentations(annotations, img.shape)
|
|
432
437
|
# seg_labels can be dict[str, list[Tensor]]
|
|
433
438
|
# apply mask transform
|
|
434
439
|
if self.mask_transform is not None:
|
|
@@ -475,6 +480,7 @@ class DatamintDataset(DatamintBaseDataset):
|
|
|
475
480
|
new_item['seg_labels'] = seg_labels
|
|
476
481
|
# process seg_labels to convert from code to label names
|
|
477
482
|
new_item['seg_labels_names'] = self._seg_labels_to_names(seg_labels)
|
|
483
|
+
new_item['seg_metainfo'] = {'file_metainfo': seg_metainfos}
|
|
478
484
|
|
|
479
485
|
except Exception:
|
|
480
486
|
_LOGGER.error(f'Error in loading/processing segmentations of {metainfo}')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datamint
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.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
|
|
@@ -21,7 +21,7 @@ Requires-Dist: humanize (>=4.0.0,<5.0.0)
|
|
|
21
21
|
Requires-Dist: lazy-loader (>=0.3.0)
|
|
22
22
|
Requires-Dist: lightning
|
|
23
23
|
Requires-Dist: matplotlib
|
|
24
|
-
Requires-Dist: medimgkit (>=0.
|
|
24
|
+
Requires-Dist: medimgkit (>=0.7.0)
|
|
25
25
|
Requires-Dist: nest-asyncio (>=1.0.0,<2.0.0)
|
|
26
26
|
Requires-Dist: nibabel (>=4.0.0)
|
|
27
27
|
Requires-Dist: numpy
|
|
@@ -24,8 +24,8 @@ datamint/client_cmd_tools/datamint_upload.py,sha256=jPzvlNeBZfOOxuG6ryswJ8OG4jXu
|
|
|
24
24
|
datamint/configs.py,sha256=Bdp6NydYwyCJ2dk19_gf_o3M2ZyQOmMHpLi8wEWNHUk,1426
|
|
25
25
|
datamint/dataset/__init__.py,sha256=4PlUKSvVhdfQvvuq8jQXrkdqnot-iTTizM3aM1vgSwg,47
|
|
26
26
|
datamint/dataset/annotation.py,sha256=qN1IMjdfLD2ceQ6va3l76jOXA8Vb_c-eBk1oWQu6hW0,7994
|
|
27
|
-
datamint/dataset/base_dataset.py,sha256=
|
|
28
|
-
datamint/dataset/dataset.py,sha256=
|
|
27
|
+
datamint/dataset/base_dataset.py,sha256=Za41Qf76nm3GmY7iA9mba_FGzzwF3gxqAwu4eY0_5b4,49479
|
|
28
|
+
datamint/dataset/dataset.py,sha256=Oj_Xr6MaCdO2Nq16fFE345qoKMWaTzKk6M1G6ajSXMo,28959
|
|
29
29
|
datamint/entities/__init__.py,sha256=tbHE7rZb0R9Hm-Dc8VWEq3PlRl7BYOzffumrV0ZdsMs,444
|
|
30
30
|
datamint/entities/annotation.py,sha256=ochAEh_JqxAe_FyYTNUfPT47KiIAG7CkBTim52bu7M8,6636
|
|
31
31
|
datamint/entities/base_entity.py,sha256=DniakCgJ-gV7Hz8VKQA_dRYTp4DU5rcjLBVOuD1aZuA,1902
|
|
@@ -44,7 +44,7 @@ datamint/logging.yaml,sha256=tOMxtc2UmwlIMTK6ljtnBwTco1PNrPeq3mx2iMuSbiw,482
|
|
|
44
44
|
datamint/utils/logging_utils.py,sha256=9pRoaPrWu2jOdDCiAoUsjEdP5ZwaealWL3hjUqFvx9g,4022
|
|
45
45
|
datamint/utils/torchmetrics.py,sha256=lwU0nOtsSWfebyp7dvjlAggaqXtj5ohSEUXOg3L0hJE,2837
|
|
46
46
|
datamint/utils/visualization.py,sha256=yaUVAOHar59VrGUjpAWv5eVvQSfztFG0eP9p5Vt3l-M,4470
|
|
47
|
-
datamint-2.
|
|
48
|
-
datamint-2.
|
|
49
|
-
datamint-2.
|
|
50
|
-
datamint-2.
|
|
47
|
+
datamint-2.2.0.dist-info/METADATA,sha256=mjsQSKJrpkEtWe_BodST4fYWWoQ49k7fUFbjt55KHAA,4203
|
|
48
|
+
datamint-2.2.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
49
|
+
datamint-2.2.0.dist-info/entry_points.txt,sha256=mn5H6jPjO-rY0W0CAZ6Z_KKWhMLvyVaSpoqk77jlTI4,145
|
|
50
|
+
datamint-2.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|