careamics 0.1.0rc7__py3-none-any.whl → 0.1.0rc8__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 careamics might be problematic. Click here for more details.
- careamics/__init__.py +1 -14
- careamics/careamist.py +83 -62
- careamics/config/__init__.py +0 -3
- careamics/config/algorithm_model.py +8 -0
- careamics/config/architectures/architecture_model.py +1 -0
- careamics/config/architectures/custom_model.py +2 -0
- careamics/config/architectures/unet_model.py +19 -0
- careamics/config/architectures/vae_model.py +1 -0
- careamics/config/callback_model.py +76 -34
- careamics/config/configuration_factory.py +1 -79
- careamics/config/configuration_model.py +12 -7
- careamics/config/data_model.py +29 -10
- careamics/config/inference_model.py +12 -2
- careamics/config/optimizer_models.py +6 -0
- careamics/config/support/supported_data.py +29 -4
- careamics/config/tile_information.py +10 -0
- careamics/config/training_model.py +5 -1
- careamics/dataset/dataset_utils/__init__.py +0 -6
- careamics/dataset/dataset_utils/file_utils.py +1 -1
- careamics/dataset/dataset_utils/iterate_over_files.py +1 -1
- careamics/dataset/in_memory_dataset.py +37 -21
- careamics/dataset/iterable_dataset.py +38 -34
- careamics/dataset/iterable_pred_dataset.py +2 -1
- careamics/dataset/iterable_tiled_pred_dataset.py +2 -1
- careamics/dataset/patching/patching.py +53 -37
- careamics/file_io/__init__.py +7 -0
- careamics/file_io/read/__init__.py +11 -0
- careamics/file_io/read/get_func.py +56 -0
- careamics/{dataset/dataset_utils/read_tiff.py → file_io/read/tiff.py} +3 -1
- careamics/file_io/write/__init__.py +9 -0
- careamics/file_io/write/get_func.py +59 -0
- careamics/file_io/write/tiff.py +39 -0
- careamics/lightning/__init__.py +17 -0
- careamics/{lightning_module.py → lightning/lightning_module.py} +58 -85
- careamics/{lightning_prediction_datamodule.py → lightning/predict_data_module.py} +78 -116
- careamics/{lightning_datamodule.py → lightning/train_data_module.py} +134 -214
- careamics/model_io/bmz_io.py +1 -1
- careamics/model_io/model_io_utils.py +1 -1
- careamics/prediction_utils/__init__.py +0 -2
- careamics/prediction_utils/prediction_outputs.py +18 -46
- careamics/prediction_utils/stitch_prediction.py +17 -14
- careamics/utils/__init__.py +2 -0
- careamics/utils/autocorrelation.py +40 -0
- {careamics-0.1.0rc7.dist-info → careamics-0.1.0rc8.dist-info}/METADATA +1 -1
- {careamics-0.1.0rc7.dist-info → careamics-0.1.0rc8.dist-info}/RECORD +51 -46
- careamics/config/configuration_example.py +0 -86
- careamics/dataset/dataset_utils/read_utils.py +0 -27
- careamics/prediction_utils/create_pred_datamodule.py +0 -185
- /careamics/{dataset/dataset_utils/read_zarr.py → file_io/read/zarr.py} +0 -0
- /careamics/{callbacks → lightning/callbacks}/__init__.py +0 -0
- /careamics/{callbacks → lightning/callbacks}/hyperparameters_callback.py +0 -0
- /careamics/{callbacks → lightning/callbacks}/progress_bar_callback.py +0 -0
- {careamics-0.1.0rc7.dist-info → careamics-0.1.0rc8.dist-info}/WHEEL +0 -0
- {careamics-0.1.0rc7.dist-info → careamics-0.1.0rc8.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"""Module containing functions to create `CAREamicsPredictData`."""
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Callable, Dict, Literal, Optional, Tuple, Union
|
|
5
|
-
|
|
6
|
-
import numpy as np
|
|
7
|
-
from numpy.typing import NDArray
|
|
8
|
-
|
|
9
|
-
from careamics.config import Configuration, create_inference_configuration
|
|
10
|
-
from careamics.utils import check_path_exists
|
|
11
|
-
|
|
12
|
-
from ..lightning_prediction_datamodule import CAREamicsPredictData
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def create_pred_datamodule(
|
|
16
|
-
source: Union[CAREamicsPredictData, Path, str, NDArray],
|
|
17
|
-
config: Configuration,
|
|
18
|
-
batch_size: Optional[int] = None,
|
|
19
|
-
tile_size: Optional[Tuple[int, ...]] = None,
|
|
20
|
-
tile_overlap: Tuple[int, ...] = (48, 48),
|
|
21
|
-
axes: Optional[str] = None,
|
|
22
|
-
data_type: Optional[Literal["array", "tiff", "custom"]] = None,
|
|
23
|
-
tta_transforms: bool = True,
|
|
24
|
-
dataloader_params: Optional[Dict] = None,
|
|
25
|
-
read_source_func: Optional[Callable] = None,
|
|
26
|
-
extension_filter: str = "",
|
|
27
|
-
) -> CAREamicsPredictData:
|
|
28
|
-
"""
|
|
29
|
-
Create a `CAREamicsPredictData` module.
|
|
30
|
-
|
|
31
|
-
Parameters
|
|
32
|
-
----------
|
|
33
|
-
source : CAREamicsPredData, pathlib.Path, str or numpy.ndarray
|
|
34
|
-
Data to predict on.
|
|
35
|
-
config : Configuration
|
|
36
|
-
Global configuration.
|
|
37
|
-
batch_size : int, default=1
|
|
38
|
-
Batch size for prediction.
|
|
39
|
-
tile_size : tuple of int, optional
|
|
40
|
-
Size of the tiles to use for prediction.
|
|
41
|
-
tile_overlap : tuple of int, default=(48, 48)
|
|
42
|
-
Overlap between tiles.
|
|
43
|
-
axes : str, optional
|
|
44
|
-
Axes of the input data, by default None.
|
|
45
|
-
data_type : {"array", "tiff", "custom"}, optional
|
|
46
|
-
Type of the input data.
|
|
47
|
-
tta_transforms : bool, default=True
|
|
48
|
-
Whether to apply test-time augmentation.
|
|
49
|
-
dataloader_params : dict, optional
|
|
50
|
-
Parameters to pass to the dataloader.
|
|
51
|
-
read_source_func : Callable, optional
|
|
52
|
-
Function to read the source data.
|
|
53
|
-
extension_filter : str, default=""
|
|
54
|
-
Filter for the file extension.
|
|
55
|
-
|
|
56
|
-
Returns
|
|
57
|
-
-------
|
|
58
|
-
prediction datamodule: CAREamicsPredictData
|
|
59
|
-
Subclass of `pytorch_lightning.LightningDataModule` for creating predictions.
|
|
60
|
-
|
|
61
|
-
Raises
|
|
62
|
-
------
|
|
63
|
-
ValueError
|
|
64
|
-
If the input is not a CAREamicsPredData instance, a path or a numpy array.
|
|
65
|
-
"""
|
|
66
|
-
# Reuse batch size if not provided explicitly
|
|
67
|
-
if batch_size is None:
|
|
68
|
-
batch_size = config.data_config.batch_size
|
|
69
|
-
|
|
70
|
-
# create predict config, reuse training config if parameters missing
|
|
71
|
-
prediction_config = create_inference_configuration(
|
|
72
|
-
configuration=config,
|
|
73
|
-
tile_size=tile_size,
|
|
74
|
-
tile_overlap=tile_overlap,
|
|
75
|
-
data_type=data_type,
|
|
76
|
-
axes=axes,
|
|
77
|
-
tta_transforms=tta_transforms,
|
|
78
|
-
batch_size=batch_size,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
# remove batch from dataloader parameters (priority given to config)
|
|
82
|
-
if dataloader_params is None:
|
|
83
|
-
dataloader_params = {}
|
|
84
|
-
if "batch_size" in dataloader_params:
|
|
85
|
-
del dataloader_params["batch_size"]
|
|
86
|
-
|
|
87
|
-
if isinstance(source, CAREamicsPredictData):
|
|
88
|
-
pred_datamodule = source
|
|
89
|
-
elif isinstance(source, Path) or isinstance(source, str):
|
|
90
|
-
pred_datamodule = _create_from_path(
|
|
91
|
-
source=source,
|
|
92
|
-
pred_config=prediction_config,
|
|
93
|
-
read_source_func=read_source_func,
|
|
94
|
-
extension_filter=extension_filter,
|
|
95
|
-
dataloader_params=dataloader_params,
|
|
96
|
-
)
|
|
97
|
-
elif isinstance(source, np.ndarray):
|
|
98
|
-
pred_datamodule = _create_from_array(
|
|
99
|
-
source=source,
|
|
100
|
-
pred_config=prediction_config,
|
|
101
|
-
dataloader_params=dataloader_params,
|
|
102
|
-
)
|
|
103
|
-
else:
|
|
104
|
-
raise ValueError(
|
|
105
|
-
f"Invalid input. Expected a CAREamicsPredData instance, paths or "
|
|
106
|
-
f"NDArray (got {type(source)})."
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
return pred_datamodule
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def _create_from_path(
|
|
113
|
-
source: Union[Path, str],
|
|
114
|
-
pred_config: Configuration,
|
|
115
|
-
read_source_func: Optional[Callable] = None,
|
|
116
|
-
extension_filter: str = "",
|
|
117
|
-
dataloader_params: Optional[Dict] = None,
|
|
118
|
-
**kwargs,
|
|
119
|
-
) -> CAREamicsPredictData:
|
|
120
|
-
"""
|
|
121
|
-
Create `CAREamicsPredictData` from path.
|
|
122
|
-
|
|
123
|
-
Parameters
|
|
124
|
-
----------
|
|
125
|
-
source : Path or str
|
|
126
|
-
_Data to predict on.
|
|
127
|
-
pred_config : Configuration
|
|
128
|
-
Prediction configuration.
|
|
129
|
-
read_source_func : Callable, optional
|
|
130
|
-
Function to read the source data.
|
|
131
|
-
extension_filter : str, default=""
|
|
132
|
-
Function to read the source data.
|
|
133
|
-
dataloader_params : Optional[Dict], optional
|
|
134
|
-
Parameters to pass to the dataloader.
|
|
135
|
-
**kwargs
|
|
136
|
-
Unused.
|
|
137
|
-
|
|
138
|
-
Returns
|
|
139
|
-
-------
|
|
140
|
-
prediction datamodule: CAREamicsPredictData
|
|
141
|
-
Subclass of `pytorch_lightning.LightningDataModule` for creating predictions.
|
|
142
|
-
"""
|
|
143
|
-
source_path = check_path_exists(source)
|
|
144
|
-
|
|
145
|
-
datamodule = CAREamicsPredictData(
|
|
146
|
-
pred_config=pred_config,
|
|
147
|
-
pred_data=source_path,
|
|
148
|
-
read_source_func=read_source_func,
|
|
149
|
-
extension_filter=extension_filter,
|
|
150
|
-
dataloader_params=dataloader_params,
|
|
151
|
-
)
|
|
152
|
-
return datamodule
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def _create_from_array(
|
|
156
|
-
source: NDArray,
|
|
157
|
-
pred_config: Configuration,
|
|
158
|
-
dataloader_params: Optional[Dict] = None,
|
|
159
|
-
**kwargs,
|
|
160
|
-
) -> CAREamicsPredictData:
|
|
161
|
-
"""
|
|
162
|
-
Create `CAREamicsPredictData` from array.
|
|
163
|
-
|
|
164
|
-
Parameters
|
|
165
|
-
----------
|
|
166
|
-
source : Path or str
|
|
167
|
-
_Data to predict on.
|
|
168
|
-
pred_config : Configuration
|
|
169
|
-
Prediction configuration.
|
|
170
|
-
dataloader_params : Optional[Dict], optional
|
|
171
|
-
Parameters to pass to the dataloader.
|
|
172
|
-
**kwargs
|
|
173
|
-
Unused. Added for compatible function signature with `_create_from_path`.
|
|
174
|
-
|
|
175
|
-
Returns
|
|
176
|
-
-------
|
|
177
|
-
prediction datamodule: CAREamicsPredictData
|
|
178
|
-
Subclass of `pytorch_lightning.LightningDataModule` for creating predictions.
|
|
179
|
-
"""
|
|
180
|
-
datamodule = CAREamicsPredictData(
|
|
181
|
-
pred_config=pred_config,
|
|
182
|
-
pred_data=source,
|
|
183
|
-
dataloader_params=dataloader_params,
|
|
184
|
-
)
|
|
185
|
-
return datamodule
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|