fastMONAI 0.6.0__tar.gz → 0.7.0__tar.gz
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.
- {fastmonai-0.6.0/fastMONAI.egg-info → fastmonai-0.7.0}/PKG-INFO +7 -8
- fastmonai-0.7.0/fastMONAI/__init__.py +1 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/_modidx.py +32 -2
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/dataset_info.py +36 -17
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/external_data.py +15 -15
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/utils.py +297 -25
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_augmentation.py +223 -63
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_core.py +10 -10
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_data.py +15 -15
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_inference.py +12 -12
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_loss.py +4 -4
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_metrics.py +21 -21
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_patch.py +66 -12
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_plot.py +7 -7
- {fastmonai-0.6.0 → fastmonai-0.7.0/fastMONAI.egg-info}/PKG-INFO +7 -8
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI.egg-info/SOURCES.txt +1 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI.egg-info/requires.txt +6 -6
- fastmonai-0.7.0/pyproject.toml +11 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/settings.ini +3 -3
- {fastmonai-0.6.0 → fastmonai-0.7.0}/setup.py +3 -3
- fastmonai-0.6.0/fastMONAI/__init__.py +0 -1
- {fastmonai-0.6.0 → fastmonai-0.7.0}/CONTRIBUTING.md +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/LICENSE +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/MANIFEST.in +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/README.md +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/research_utils.py +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI/vision_all.py +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI.egg-info/dependency_links.txt +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI.egg-info/entry_points.txt +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI.egg-info/not-zip-safe +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/fastMONAI.egg-info/top_level.txt +0 -0
- {fastmonai-0.6.0 → fastmonai-0.7.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastMONAI
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: fastMONAI library
|
|
5
5
|
Home-page: https://github.com/MMIV-ML/fastMONAI
|
|
6
6
|
Author: Satheshkumar Kaliyugarasan
|
|
@@ -12,18 +12,17 @@ Classifier: Intended Audience :: Developers
|
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
15
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
16
|
Requires-Python: >=3.10
|
|
18
17
|
Description-Content-Type: text/markdown
|
|
19
18
|
License-File: LICENSE
|
|
20
|
-
Requires-Dist: fastai==2.8.
|
|
21
|
-
Requires-Dist: monai==1.5.
|
|
22
|
-
Requires-Dist: torchio==0.
|
|
19
|
+
Requires-Dist: fastai==2.8.6
|
|
20
|
+
Requires-Dist: monai==1.5.2
|
|
21
|
+
Requires-Dist: torchio==0.21.2
|
|
23
22
|
Requires-Dist: xlrd>=1.2.0
|
|
24
|
-
Requires-Dist: scikit-image==0.
|
|
23
|
+
Requires-Dist: scikit-image==0.26.0
|
|
25
24
|
Requires-Dist: imagedata==3.8.14
|
|
26
|
-
Requires-Dist: mlflow==3.
|
|
25
|
+
Requires-Dist: mlflow==3.9.0
|
|
27
26
|
Requires-Dist: huggingface-hub
|
|
28
27
|
Requires-Dist: gdown
|
|
29
28
|
Requires-Dist: gradio
|
|
@@ -31,7 +30,7 @@ Requires-Dist: opencv-python
|
|
|
31
30
|
Requires-Dist: plum-dispatch
|
|
32
31
|
Provides-Extra: dev
|
|
33
32
|
Requires-Dist: ipywidgets; extra == "dev"
|
|
34
|
-
Requires-Dist: nbdev; extra == "dev"
|
|
33
|
+
Requires-Dist: nbdev<3; extra == "dev"
|
|
35
34
|
Requires-Dist: tabulate; extra == "dev"
|
|
36
35
|
Requires-Dist: quarto; extra == "dev"
|
|
37
36
|
Dynamic: author
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.0"
|
|
@@ -55,10 +55,10 @@ d = { 'settings': { 'branch': 'main',
|
|
|
55
55
|
'fastMONAI/external_data.py'),
|
|
56
56
|
'fastMONAI.external_data.download_spine_test_data': ( 'external_data.html#download_spine_test_data',
|
|
57
57
|
'fastMONAI/external_data.py')},
|
|
58
|
-
'fastMONAI.research_utils': { 'fastMONAI.research_utils.pred_postprocess': ( 'research_utils.html#pred_postprocess',
|
|
59
|
-
'fastMONAI/research_utils.py')},
|
|
60
58
|
'fastMONAI.utils': { 'fastMONAI.utils.MLflowUIManager': ('utils.html#mlflowuimanager', 'fastMONAI/utils.py'),
|
|
61
59
|
'fastMONAI.utils.MLflowUIManager.__init__': ('utils.html#mlflowuimanager.__init__', 'fastMONAI/utils.py'),
|
|
60
|
+
'fastMONAI.utils.MLflowUIManager._find_running_mlflow': ( 'utils.html#mlflowuimanager._find_running_mlflow',
|
|
61
|
+
'fastMONAI/utils.py'),
|
|
62
62
|
'fastMONAI.utils.MLflowUIManager.check_mlflow_installed': ( 'utils.html#mlflowuimanager.check_mlflow_installed',
|
|
63
63
|
'fastMONAI/utils.py'),
|
|
64
64
|
'fastMONAI.utils.MLflowUIManager.find_available_port': ( 'utils.html#mlflowuimanager.find_available_port',
|
|
@@ -79,6 +79,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
79
79
|
'fastMONAI/utils.py'),
|
|
80
80
|
'fastMONAI.utils.ModelTrackingCallback._extract_training_params': ( 'utils.html#modeltrackingcallback._extract_training_params',
|
|
81
81
|
'fastMONAI/utils.py'),
|
|
82
|
+
'fastMONAI.utils.ModelTrackingCallback._log_datasets': ( 'utils.html#modeltrackingcallback._log_datasets',
|
|
83
|
+
'fastMONAI/utils.py'),
|
|
82
84
|
'fastMONAI.utils.ModelTrackingCallback._register_pytorch_model': ( 'utils.html#modeltrackingcallback._register_pytorch_model',
|
|
83
85
|
'fastMONAI/utils.py'),
|
|
84
86
|
'fastMONAI.utils.ModelTrackingCallback._save_model_artifacts': ( 'utils.html#modeltrackingcallback._save_model_artifacts',
|
|
@@ -91,13 +93,23 @@ d = { 'settings': { 'branch': 'main',
|
|
|
91
93
|
'fastMONAI/utils.py'),
|
|
92
94
|
'fastMONAI.utils.ModelTrackingCallback.extract_all_params': ( 'utils.html#modeltrackingcallback.extract_all_params',
|
|
93
95
|
'fastMONAI/utils.py'),
|
|
96
|
+
'fastMONAI.utils.ModelTrackingCallback.log_dataframe': ( 'utils.html#modeltrackingcallback.log_dataframe',
|
|
97
|
+
'fastMONAI/utils.py'),
|
|
98
|
+
'fastMONAI.utils.ModelTrackingCallback.log_metrics': ( 'utils.html#modeltrackingcallback.log_metrics',
|
|
99
|
+
'fastMONAI/utils.py'),
|
|
100
|
+
'fastMONAI.utils.ModelTrackingCallback.log_metrics_table': ( 'utils.html#modeltrackingcallback.log_metrics_table',
|
|
101
|
+
'fastMONAI/utils.py'),
|
|
94
102
|
'fastMONAI.utils._detect_patch_workflow': ('utils.html#_detect_patch_workflow', 'fastMONAI/utils.py'),
|
|
95
103
|
'fastMONAI.utils._extract_loss_name': ('utils.html#_extract_loss_name', 'fastMONAI/utils.py'),
|
|
96
104
|
'fastMONAI.utils._extract_model_name': ('utils.html#_extract_model_name', 'fastMONAI/utils.py'),
|
|
97
105
|
'fastMONAI.utils._extract_patch_config': ('utils.html#_extract_patch_config', 'fastMONAI/utils.py'),
|
|
106
|
+
'fastMONAI.utils._extract_patch_dataset_dfs': ( 'utils.html#_extract_patch_dataset_dfs',
|
|
107
|
+
'fastMONAI/utils.py'),
|
|
98
108
|
'fastMONAI.utils._extract_size_from_transforms': ( 'utils.html#_extract_size_from_transforms',
|
|
99
109
|
'fastMONAI/utils.py'),
|
|
100
110
|
'fastMONAI.utils._extract_standard_config': ('utils.html#_extract_standard_config', 'fastMONAI/utils.py'),
|
|
111
|
+
'fastMONAI.utils._extract_standard_dataset_dfs': ( 'utils.html#_extract_standard_dataset_dfs',
|
|
112
|
+
'fastMONAI/utils.py'),
|
|
101
113
|
'fastMONAI.utils.create_mlflow_callback': ('utils.html#create_mlflow_callback', 'fastMONAI/utils.py'),
|
|
102
114
|
'fastMONAI.utils.load_patch_variables': ('utils.html#load_patch_variables', 'fastMONAI/utils.py'),
|
|
103
115
|
'fastMONAI.utils.load_variables': ('utils.html#load_variables', 'fastMONAI/utils.py'),
|
|
@@ -127,6 +139,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
127
139
|
'fastMONAI/vision_augmentation.py'),
|
|
128
140
|
'fastMONAI.vision_augmentation.NormalizeIntensity.encodes': ( 'vision_augment.html#normalizeintensity.encodes',
|
|
129
141
|
'fastMONAI/vision_augmentation.py'),
|
|
142
|
+
'fastMONAI.vision_augmentation.NormalizeIntensity.tio_transform': ( 'vision_augment.html#normalizeintensity.tio_transform',
|
|
143
|
+
'fastMONAI/vision_augmentation.py'),
|
|
130
144
|
'fastMONAI.vision_augmentation.OneOf': ( 'vision_augment.html#oneof',
|
|
131
145
|
'fastMONAI/vision_augmentation.py'),
|
|
132
146
|
'fastMONAI.vision_augmentation.OneOf.__init__': ( 'vision_augment.html#oneof.__init__',
|
|
@@ -199,6 +213,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
199
213
|
'fastMONAI/vision_augmentation.py'),
|
|
200
214
|
'fastMONAI.vision_augmentation.RandomIntensityScale.encodes': ( 'vision_augment.html#randomintensityscale.encodes',
|
|
201
215
|
'fastMONAI/vision_augmentation.py'),
|
|
216
|
+
'fastMONAI.vision_augmentation.RandomIntensityScale.tio_transform': ( 'vision_augment.html#randomintensityscale.tio_transform',
|
|
217
|
+
'fastMONAI/vision_augmentation.py'),
|
|
202
218
|
'fastMONAI.vision_augmentation.RandomMotion': ( 'vision_augment.html#randommotion',
|
|
203
219
|
'fastMONAI/vision_augmentation.py'),
|
|
204
220
|
'fastMONAI.vision_augmentation.RandomMotion.__init__': ( 'vision_augment.html#randommotion.__init__',
|
|
@@ -239,6 +255,12 @@ d = { 'settings': { 'branch': 'main',
|
|
|
239
255
|
'fastMONAI/vision_augmentation.py'),
|
|
240
256
|
'fastMONAI.vision_augmentation.ZNormalization.tio_transform': ( 'vision_augment.html#znormalization.tio_transform',
|
|
241
257
|
'fastMONAI/vision_augmentation.py'),
|
|
258
|
+
'fastMONAI.vision_augmentation._TioNormalizeIntensity': ( 'vision_augment.html#_tionormalizeintensity',
|
|
259
|
+
'fastMONAI/vision_augmentation.py'),
|
|
260
|
+
'fastMONAI.vision_augmentation._TioNormalizeIntensity.__init__': ( 'vision_augment.html#_tionormalizeintensity.__init__',
|
|
261
|
+
'fastMONAI/vision_augmentation.py'),
|
|
262
|
+
'fastMONAI.vision_augmentation._TioNormalizeIntensity.apply_transform': ( 'vision_augment.html#_tionormalizeintensity.apply_transform',
|
|
263
|
+
'fastMONAI/vision_augmentation.py'),
|
|
242
264
|
'fastMONAI.vision_augmentation._TioRandomCutout': ( 'vision_augment.html#_tiorandomcutout',
|
|
243
265
|
'fastMONAI/vision_augmentation.py'),
|
|
244
266
|
'fastMONAI.vision_augmentation._TioRandomCutout.__init__': ( 'vision_augment.html#_tiorandomcutout.__init__',
|
|
@@ -247,6 +269,12 @@ d = { 'settings': { 'branch': 'main',
|
|
|
247
269
|
'fastMONAI/vision_augmentation.py'),
|
|
248
270
|
'fastMONAI.vision_augmentation._TioRandomCutout.apply_transform': ( 'vision_augment.html#_tiorandomcutout.apply_transform',
|
|
249
271
|
'fastMONAI/vision_augmentation.py'),
|
|
272
|
+
'fastMONAI.vision_augmentation._TioRandomIntensityScale': ( 'vision_augment.html#_tiorandomintensityscale',
|
|
273
|
+
'fastMONAI/vision_augmentation.py'),
|
|
274
|
+
'fastMONAI.vision_augmentation._TioRandomIntensityScale.__init__': ( 'vision_augment.html#_tiorandomintensityscale.__init__',
|
|
275
|
+
'fastMONAI/vision_augmentation.py'),
|
|
276
|
+
'fastMONAI.vision_augmentation._TioRandomIntensityScale.apply_transform': ( 'vision_augment.html#_tiorandomintensityscale.apply_transform',
|
|
277
|
+
'fastMONAI/vision_augmentation.py'),
|
|
250
278
|
'fastMONAI.vision_augmentation._create_ellipsoid_mask': ( 'vision_augment.html#_create_ellipsoid_mask',
|
|
251
279
|
'fastMONAI/vision_augmentation.py'),
|
|
252
280
|
'fastMONAI.vision_augmentation.do_pad_or_crop': ( 'vision_augment.html#do_pad_or_crop',
|
|
@@ -443,6 +471,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
443
471
|
'fastMONAI/vision_patch.py'),
|
|
444
472
|
'fastMONAI.vision_patch.MedPatchDataLoaders.patch_config': ( 'vision_patch.html#medpatchdataloaders.patch_config',
|
|
445
473
|
'fastMONAI/vision_patch.py'),
|
|
474
|
+
'fastMONAI.vision_patch.MedPatchDataLoaders.show_batch': ( 'vision_patch.html#medpatchdataloaders.show_batch',
|
|
475
|
+
'fastMONAI/vision_patch.py'),
|
|
446
476
|
'fastMONAI.vision_patch.MedPatchDataLoaders.target_spacing': ( 'vision_patch.html#medpatchdataloaders.target_spacing',
|
|
447
477
|
'fastMONAI/vision_patch.py'),
|
|
448
478
|
'fastMONAI.vision_patch.MedPatchDataLoaders.to': ( 'vision_patch.html#medpatchdataloaders.to',
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/08_dataset_info.ipynb.
|
|
2
2
|
|
|
3
|
-
# %% auto 0
|
|
3
|
+
# %% auto #0
|
|
4
4
|
__all__ = ['MedDataset', 'suggest_patch_size', 'get_class_weights']
|
|
5
5
|
|
|
6
|
-
# %% ../nbs/08_dataset_info.ipynb
|
|
6
|
+
# %% ../nbs/08_dataset_info.ipynb #027f016a-a80c-4842-b9dc-0bddb358a00c
|
|
7
7
|
from .vision_core import *
|
|
8
8
|
from .vision_plot import find_max_slice
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ import torch
|
|
|
15
15
|
import glob
|
|
16
16
|
import matplotlib.pyplot as plt
|
|
17
17
|
|
|
18
|
-
# %% ../nbs/08_dataset_info.ipynb
|
|
18
|
+
# %% ../nbs/08_dataset_info.ipynb #7401beac
|
|
19
19
|
import warnings
|
|
20
20
|
|
|
21
21
|
class MedDataset:
|
|
@@ -311,7 +311,7 @@ class MedDataset:
|
|
|
311
311
|
self._visualize_single_case(img_path, mask_path, case_id, anatomical_plane, cmap, figsize)
|
|
312
312
|
print("-" * 60)
|
|
313
313
|
|
|
314
|
-
# %% ../nbs/08_dataset_info.ipynb
|
|
314
|
+
# %% ../nbs/08_dataset_info.ipynb #wp61bidiwwd
|
|
315
315
|
def suggest_patch_size(
|
|
316
316
|
dataset: MedDataset,
|
|
317
317
|
target_spacing: list = None,
|
|
@@ -319,12 +319,17 @@ def suggest_patch_size(
|
|
|
319
319
|
max_patch_size: list = None,
|
|
320
320
|
divisor: int = 16
|
|
321
321
|
) -> list:
|
|
322
|
-
"""Suggest optimal patch size based on
|
|
322
|
+
"""Suggest optimal patch size based on dataset dimensions.
|
|
323
|
+
|
|
324
|
+
Uses median shape as the starting point but clamps to the minimum
|
|
325
|
+
volume size per axis, ensuring the suggested patch fits ALL volumes
|
|
326
|
+
without requiring padding during training.
|
|
323
327
|
|
|
324
328
|
Algorithm:
|
|
325
|
-
1. Use median
|
|
326
|
-
2. Round down to nearest multiple of divisor (16 for
|
|
327
|
-
3. Clamp to [min_patch_size, max_patch_size]
|
|
329
|
+
1. Use min(median, min_volume) per axis for safety
|
|
330
|
+
2. Round down to nearest multiple of divisor (16 for UNet compatibility)
|
|
331
|
+
3. Clamp to [min_patch_size, max_patch_size] bounds
|
|
332
|
+
4. Validate: error if min_patch_size exceeds smallest volume
|
|
328
333
|
|
|
329
334
|
Args:
|
|
330
335
|
dataset: MedDataset instance with analyzed images.
|
|
@@ -359,35 +364,49 @@ def suggest_patch_size(
|
|
|
359
364
|
# Get size statistics (resampled to target_spacing)
|
|
360
365
|
stats = dataset.get_size_statistics(target_spacing)
|
|
361
366
|
median_shape = stats['median']
|
|
367
|
+
min_shape = stats['min']
|
|
362
368
|
|
|
363
369
|
# Handle single-image edge case
|
|
364
370
|
if len(dataset.df) == 1:
|
|
365
371
|
warnings.warn("Single image dataset - using image dimensions directly")
|
|
366
372
|
|
|
367
|
-
# Step 1: Round down to nearest divisor
|
|
368
373
|
def round_to_divisor(val, div):
|
|
369
374
|
"""Round down to nearest multiple of divisor."""
|
|
370
375
|
return max(div, int(val // div) * div)
|
|
371
376
|
|
|
372
|
-
|
|
377
|
+
# Step 1: Clamp to min(median, min_volume) per axis — safety guarantee
|
|
378
|
+
effective_dims = [min(med, mn) for med, mn in zip(median_shape, min_shape)]
|
|
379
|
+
|
|
380
|
+
# Step 2: Round down to nearest divisor
|
|
381
|
+
patch_size = [round_to_divisor(dim, divisor) for dim in effective_dims]
|
|
373
382
|
|
|
374
|
-
# Step
|
|
383
|
+
# Step 3: Clamp to [min_patch_size, max_patch_size] bounds
|
|
375
384
|
patch_size = [
|
|
376
385
|
max(min_p, min(max_p, p))
|
|
377
386
|
for p, min_p, max_p in zip(patch_size, min_patch_size, max_patch_size)
|
|
378
387
|
]
|
|
379
388
|
|
|
380
|
-
#
|
|
381
|
-
for i, (p,
|
|
382
|
-
if
|
|
389
|
+
# Step 4: Final safety check — error if bounds force patch > min volume
|
|
390
|
+
for i, (p, min_dim) in enumerate(zip(patch_size, min_shape)):
|
|
391
|
+
if p > min_dim:
|
|
392
|
+
raise ValueError(
|
|
393
|
+
f"Cannot suggest safe patch_size for dimension {i}: "
|
|
394
|
+
f"smallest volume is {min_dim:.0f} but min_patch_size={min_patch_size[i]}. "
|
|
395
|
+
f"Exclude small volumes or reduce min_patch_size."
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
# Warn when suggestion was reduced to fit smallest volume
|
|
399
|
+
for i, (med, mn, p) in enumerate(zip(median_shape, min_shape, patch_size)):
|
|
400
|
+
median_based = min(max_patch_size[i], round_to_divisor(med, divisor))
|
|
401
|
+
if p < median_based:
|
|
383
402
|
warnings.warn(
|
|
384
|
-
f"
|
|
385
|
-
f"
|
|
403
|
+
f"Dim {i}: patch_size reduced from {median_based} to {p} "
|
|
404
|
+
f"to fit smallest volume (min={mn:.0f}, median={med:.0f})."
|
|
386
405
|
)
|
|
387
406
|
|
|
388
407
|
return patch_size
|
|
389
408
|
|
|
390
|
-
# %% ../nbs/08_dataset_info.ipynb
|
|
409
|
+
# %% ../nbs/08_dataset_info.ipynb #9b81f6e8-abd7-4bf6-be4c-4118986c308a
|
|
391
410
|
def get_class_weights(labels: (np.array, list), class_weight: str = 'balanced') -> torch.Tensor:
|
|
392
411
|
"""Calculates and returns the class weights.
|
|
393
412
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/09_external_data.ipynb.
|
|
2
2
|
|
|
3
|
-
# %% auto 0
|
|
3
|
+
# %% auto #0
|
|
4
4
|
__all__ = ['MURLs', 'download_ixi_data', 'download_ixi_tiny', 'download_spine_test_data', 'download_example_spine_data',
|
|
5
5
|
'download_medmnist3d_dataset', 'download_example_endometrial_cancer_data']
|
|
6
6
|
|
|
7
|
-
# %% ../nbs/09_external_data.ipynb
|
|
7
|
+
# %% ../nbs/09_external_data.ipynb #942e1644-0dac-4701-8a1e-5693f80f3ca0
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from glob import glob
|
|
10
10
|
from numpy import load
|
|
@@ -15,7 +15,7 @@ from torchio import ScalarImage
|
|
|
15
15
|
import multiprocessing as mp
|
|
16
16
|
from functools import partial
|
|
17
17
|
|
|
18
|
-
# %% ../nbs/09_external_data.ipynb
|
|
18
|
+
# %% ../nbs/09_external_data.ipynb #6d5600a3-9d70-4714-8cc2-8f4682a7e5a3
|
|
19
19
|
class MURLs():
|
|
20
20
|
"""A class with external medical dataset URLs."""
|
|
21
21
|
|
|
@@ -32,7 +32,7 @@ class MURLs():
|
|
|
32
32
|
EXAMPLE_EC_DATA = 'https://drive.google.com/uc?id=1P_J8MfzbfObTkAyWfY-LlEC_IA_NjYn-'
|
|
33
33
|
EXAMPLE_MULTI_EC_DATA = 'https://drive.google.com/uc?id=1yOmbA9-nKfzzsfysgp9OcPw8GAarXPvE'
|
|
34
34
|
|
|
35
|
-
# %% ../nbs/09_external_data.ipynb
|
|
35
|
+
# %% ../nbs/09_external_data.ipynb #cb4c061a-d7f5-4ba0-9e7b-ee0c6ec480b0
|
|
36
36
|
def _process_ixi_xls(xls_path: (str, Path), img_path: Path) -> pd.DataFrame:
|
|
37
37
|
"""Private method to process the demographic information for the IXI dataset.
|
|
38
38
|
|
|
@@ -74,7 +74,7 @@ def _process_ixi_xls(xls_path: (str, Path), img_path: Path) -> pd.DataFrame:
|
|
|
74
74
|
|
|
75
75
|
return df
|
|
76
76
|
|
|
77
|
-
# %% ../nbs/09_external_data.ipynb
|
|
77
|
+
# %% ../nbs/09_external_data.ipynb #6714a68f-1378-46b3-aeff-ef940213ac2f
|
|
78
78
|
def download_ixi_data(path: (str, Path) = '../data') -> Path:
|
|
79
79
|
"""Download T1 scans and demographic information from the IXI dataset.
|
|
80
80
|
|
|
@@ -108,7 +108,7 @@ def download_ixi_data(path: (str, Path) = '../data') -> Path:
|
|
|
108
108
|
|
|
109
109
|
return path
|
|
110
110
|
|
|
111
|
-
# %% ../nbs/09_external_data.ipynb
|
|
111
|
+
# %% ../nbs/09_external_data.ipynb #7753da8a-93e8-4bf3-8f78-bb158b4280d0
|
|
112
112
|
def download_ixi_tiny(path: (str, Path) = '../data') -> Path:
|
|
113
113
|
"""Download the tiny version of the IXI dataset provided by TorchIO.
|
|
114
114
|
|
|
@@ -132,7 +132,7 @@ def download_ixi_tiny(path: (str, Path) = '../data') -> Path:
|
|
|
132
132
|
|
|
133
133
|
return path
|
|
134
134
|
|
|
135
|
-
# %% ../nbs/09_external_data.ipynb
|
|
135
|
+
# %% ../nbs/09_external_data.ipynb #b466174a-4b49-4a8f-92c6-1e5e3ca9fc2a
|
|
136
136
|
def _create_spine_df(dir: Path) -> pd.DataFrame:
|
|
137
137
|
"""Create a pandas DataFrame containing information about spinal images.
|
|
138
138
|
|
|
@@ -159,7 +159,7 @@ def _create_spine_df(dir: Path) -> pd.DataFrame:
|
|
|
159
159
|
|
|
160
160
|
return pd.DataFrame(test_data)
|
|
161
161
|
|
|
162
|
-
# %% ../nbs/09_external_data.ipynb
|
|
162
|
+
# %% ../nbs/09_external_data.ipynb #26256dca-d9df-43f6-b8eb-f36ce2a445dc
|
|
163
163
|
def download_spine_test_data(path: (str, Path) = '../data') -> pd.DataFrame:
|
|
164
164
|
"""Downloads T2w scans from the study 'Fully Automatic Localization and
|
|
165
165
|
Segmentation of 3D Vertebral Bodies from CT/MR Images via a Learning-Based
|
|
@@ -184,7 +184,7 @@ def download_spine_test_data(path: (str, Path) = '../data') -> pd.DataFrame:
|
|
|
184
184
|
|
|
185
185
|
return _create_spine_df(Path(path) / study)
|
|
186
186
|
|
|
187
|
-
# %% ../nbs/09_external_data.ipynb
|
|
187
|
+
# %% ../nbs/09_external_data.ipynb #93b77ec9-a93a-42cc-b707-4e1e75063533
|
|
188
188
|
def download_example_spine_data(path: (str, Path) = '../data') -> Path:
|
|
189
189
|
"""Downloads example T2w scan and corresponding predicted mask.
|
|
190
190
|
|
|
@@ -207,7 +207,7 @@ def download_example_spine_data(path: (str, Path) = '../data') -> Path:
|
|
|
207
207
|
|
|
208
208
|
return Path(path) / study
|
|
209
209
|
|
|
210
|
-
# %% ../nbs/09_external_data.ipynb
|
|
210
|
+
# %% ../nbs/09_external_data.ipynb #89f60f76-5e5d-4a40-b49a-617ec2d35731
|
|
211
211
|
def _process_medmnist_img(path, idx_arr):
|
|
212
212
|
"""Save tensor as NIfTI."""
|
|
213
213
|
|
|
@@ -217,7 +217,7 @@ def _process_medmnist_img(path, idx_arr):
|
|
|
217
217
|
img.save(fn)
|
|
218
218
|
return str(fn)
|
|
219
219
|
|
|
220
|
-
# %% ../nbs/09_external_data.ipynb
|
|
220
|
+
# %% ../nbs/09_external_data.ipynb #b0199679-707b-445d-8467-3d342246322a
|
|
221
221
|
def _df_sort_and_add_columns(df, label_list, is_val):
|
|
222
222
|
"""Sort the dataframe based on img_idx and add labels and if it is validation data column."""
|
|
223
223
|
|
|
@@ -228,7 +228,7 @@ def _df_sort_and_add_columns(df, label_list, is_val):
|
|
|
228
228
|
|
|
229
229
|
return df
|
|
230
230
|
|
|
231
|
-
# %% ../nbs/09_external_data.ipynb
|
|
231
|
+
# %% ../nbs/09_external_data.ipynb #d82157b8-ab69-4a38-9323-af4b58c6b54a
|
|
232
232
|
def _create_nodule_df(pool, output_dir, imgs, labels, is_val=False):
|
|
233
233
|
"""Create dataframe for MedMNIST data."""
|
|
234
234
|
|
|
@@ -238,13 +238,13 @@ def _create_nodule_df(pool, output_dir, imgs, labels, is_val=False):
|
|
|
238
238
|
df = pd.DataFrame(list(zip(img_path_list, img_idx)), columns=['img_path','img_idx'])
|
|
239
239
|
return _df_sort_and_add_columns(df, labels, is_val)
|
|
240
240
|
|
|
241
|
-
# %% ../nbs/09_external_data.ipynb
|
|
241
|
+
# %% ../nbs/09_external_data.ipynb #04095111-a38f-4d00-a0fb-2dbfac263eb6
|
|
242
242
|
def _dataset_available_locally(path: Path):
|
|
243
243
|
"""Checks if the dataset exists in the local directory."""
|
|
244
244
|
|
|
245
245
|
return path.exists() and any(path.iterdir())
|
|
246
246
|
|
|
247
|
-
# %% ../nbs/09_external_data.ipynb
|
|
247
|
+
# %% ../nbs/09_external_data.ipynb #a1b456f0-8e14-42c6-a1cd-a332312145ff
|
|
248
248
|
def download_medmnist3d_dataset(study: str, path: (str, Path) = '../data',
|
|
249
249
|
max_workers: int = 1, skip_download: bool = True):
|
|
250
250
|
"""Downloads and processes a particular MedMNIST3D dataset.
|
|
@@ -301,7 +301,7 @@ def download_medmnist3d_dataset(study: str, path: (str, Path) = '../data',
|
|
|
301
301
|
|
|
302
302
|
return train_val_df, test_df
|
|
303
303
|
|
|
304
|
-
# %% ../nbs/09_external_data.ipynb
|
|
304
|
+
# %% ../nbs/09_external_data.ipynb #67491c4a-8491-4b10-8f03-87ffa012fee0
|
|
305
305
|
def download_example_endometrial_cancer_data(path: (str, Path) = '../data', multi_channel: bool = True):
|
|
306
306
|
"""Download example data for endometrial cancer.
|
|
307
307
|
|