predict_data_module
Prediction Lightning data modules.
PredictDataModule
#
Bases: LightningDataModule
CAREamics Lightning prediction data module.
The data module can be used with Path, str or numpy arrays. The data can be either a folder containing images or a single file.
To read custom data types, you can set data_type
to custom
in data_config
and provide a function that returns a numpy array from a path as read_source_func
parameter. The function will receive a Path object and an axies string as arguments, the axes being derived from the data_config
.
You can also provide a fnmatch
and Path.rglob
compatible expression (e.g. "*.czi") to filter the files extension using extension_filter
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pred_config | InferenceModel | Pydantic model for CAREamics prediction configuration. | required |
pred_data | Path or str or ndarray | Prediction data, can be a path to a folder, a file or a numpy array. | required |
read_source_func | Callable | Function to read custom types, by default None. | None |
extension_filter | str | Filter to filter file extensions for custom types, by default "". | '' |
dataloader_params | dict | Dataloader parameters, by default {}. | None |
Source code in src/careamics/lightning/predict_data_module.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
__init__(pred_config, pred_data, read_source_func=None, extension_filter='', dataloader_params=None)
#
Constructor.
The data module can be used with Path, str or numpy arrays. The data can be either a folder containing images or a single file.
To read custom data types, you can set data_type
to custom
in data_config
and provide a function that returns a numpy array from a path as read_source_func
parameter. The function will receive a Path object and an axies string as arguments, the axes being derived from the data_config
.
You can also provide a fnmatch
and Path.rglob
compatible expression (e.g. "*.czi") to filter the files extension using extension_filter
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pred_config | InferenceModel | Pydantic model for CAREamics prediction configuration. | required |
pred_data | Path or str or ndarray | Prediction data, can be a path to a folder, a file or a numpy array. | required |
read_source_func | Callable | Function to read custom types, by default None. | None |
extension_filter | str | Filter to filter file extensions for custom types, by default "". | '' |
dataloader_params | dict | Dataloader parameters, by default {}. | None |
Raises:
Type | Description |
---|---|
ValueError | If the data type is |
ValueError | If the data type is |
ValueError | If the data type is |
Source code in src/careamics/lightning/predict_data_module.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
predict_dataloader()
#
Create a dataloader for prediction.
Returns:
Type | Description |
---|---|
DataLoader | Prediction dataloader. |
Source code in src/careamics/lightning/predict_data_module.py
prepare_data()
#
Hook used to prepare the data before calling setup
.
Source code in src/careamics/lightning/predict_data_module.py
setup(stage=None)
#
Hook called at the beginning of predict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | Optional[str] | Stage, by default None. | None |
Source code in src/careamics/lightning/predict_data_module.py
create_predict_datamodule(pred_data, data_type, axes, image_means, image_stds, tile_size=None, tile_overlap=None, batch_size=1, tta_transforms=True, read_source_func=None, extension_filter='', dataloader_params=None)
#
Create a CAREamics prediction Lightning datamodule.
This function is used to explicitly pass the parameters usually contained in an inference_model
configuration.
Since the lightning datamodule has no access to the model, make sure that the parameters passed to the datamodule are consistent with the model's requirements and are coherent. This can be done by creating a Configuration
object beforehand and passing its parameters to the different Lightning modules.
The data module can be used with Path, str or numpy arrays. To use array data, set data_type
to array
and pass a numpy array to train_data
.
By default, CAREamics only supports types defined in careamics.config.support.SupportedData
. To read custom data types, you can set data_type
to custom
and provide a function that returns a numpy array from a path. Additionally, pass a fnmatch
and Path.rglob
compatible expression (e.g. "*.jpeg") to filter the files extension using extension_filter
.
In dataloader_params
, you can pass any parameter accepted by PyTorch dataloaders, except for batch_size
, which is set by the batch_size
parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pred_data | str or Path or ndarray | Prediction data. | required |
data_type | (array, tiff, custom) | Data type, see | "array" |
axes | str | Axes of the data, chosen among SCZYX. | required |
image_means | list of float | Mean values for normalization, only used if Normalization is defined. | required |
image_stds | list of float | Std values for normalization, only used if Normalization is defined. | required |
tile_size | tuple of int | Tile size, 2D or 3D tile size. | None |
tile_overlap | tuple of int | Tile overlap, 2D or 3D tile overlap. | None |
batch_size | int | Batch size. | 1 |
tta_transforms | bool | Use test time augmentation, by default True. | True |
read_source_func | Callable | Function to read the source data, used if | None |
extension_filter | str | Filter for file extensions, used if | '' |
dataloader_params | dict | Pytorch dataloader parameters, by default {}. | None |
Returns:
Type | Description |
---|---|
PredictDataModule | CAREamics prediction datamodule. |
Notes
If you are using a UNet model and tiling, the tile size must be divisible in every dimension by 2**d, where d is the depth of the model. This avoids artefacts arising from the broken shift invariance induced by the pooling layers of the UNet. If your image has less dimensions, as it may happen in the Z dimension, consider padding your image.
Source code in src/careamics/lightning/predict_data_module.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|