n2v_factory
Convenience function to create N2V configurations.
create_n2v_configuration(experiment_name, data_type, axes, patch_size, batch_size, num_epochs=100, num_steps=None, augmentations=None, channels=None, in_memory=None, independent_channels=True, use_n2v2=False, n_channels=None, roi_size=11, masked_pixel_percentage=0.2, struct_n2v_axis='none', struct_n2v_span=5, trainer_params=None, logger='none', model_params=None, optimizer='Adam', optimizer_params=None, lr_scheduler='ReduceLROnPlateau', lr_scheduler_params=None, train_dataloader_params=None, val_dataloader_params=None, checkpoint_params=None) #
Create a configuration for training Noise2Void.
N2V uses a UNet model to denoise images in a self-supervised manner. To use its variants structN2V and N2V2, set the struct_n2v_axis and struct_n2v_span (structN2V) parameters, or set use_n2v2 to True (N2V2).
N2V2 modifies the UNet architecture by adding blur pool layers and removes the skip connections, thus removing checkboard artefacts. StructN2V is used when vertical or horizontal correlations are present in the noise; it applies an additional mask to the manipulated pixel neighbors.
If "Z" is present in axes, then patch_size must be a list of length 3, otherwise 2.
If "C" is present in axes, then you need to set n_channels to the number of channels.
By default, all channels are trained independently. To train all channels together, set independent_channels to False.
By default, the transformations applied are a random flip along X or Y, and a random 90 degrees rotation in the XY plane. Normalization is always applied, as well as the N2V manipulation.
By setting augmentations to None, the default transformations (flip in X and Y, rotations by 90 degrees in the XY plane) are applied. Rather than the default transforms, a list of transforms can be passed to the augmentations parameter. To disable the transforms, simply pass an empty list.
The roi_size parameter specifies the size of the area around each pixel that will be manipulated by N2V. The masked_pixel_percentage parameter specifies how many pixels per patch will be manipulated.
The parameters of the UNet can be specified in the model_params (passed as a parameter-value dictionary). Note that use_n2v2 and 'n_channels' override the corresponding parameters passed in model_params.
If you pass "horizontal" or "vertical" to struct_n2v_axis, then structN2V mask will be applied to each manipulated pixel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_name | str | Name of the experiment. | required |
data_type | Literal['array', 'tiff', 'czi', 'custom'] | Type of the data. | required |
axes | str | Axes of the data (e.g. SYX). | required |
patch_size | List[int] | Size of the patches along the spatial dimensions (e.g. [64, 64]). | required |
batch_size | int | Batch size. | required |
num_epochs | int | Number of epochs to train for. If provided, this will be added to trainer_params. | 100 |
num_steps | int | Number of batches in 1 epoch. If provided, this will be added to trainer_params. Translates to | None |
augmentations | list of transforms | List of transforms to apply, either both or one of XYFlipConfig and XYRandomRotate90Config. By default, it applies both XYFlip (on X and Y) and XYRandomRotate90 (in XY) to the images. | None |
channels | Sequence of int | List of channels to use. If | None |
in_memory | bool | Whether to load all data into memory. This is only supported for 'array', 'tiff' and 'custom' data types. If | None |
independent_channels | bool | Whether to train all channels together, by default True. | True |
use_n2v2 | bool | Whether to use N2V2, by default False. | False |
n_channels | int or None | Number of channels (in and out). If | None |
roi_size | int | N2V pixel manipulation area, by default 11. | 11 |
masked_pixel_percentage | float | Percentage of pixels masked in each patch, by default 0.2. | 0.2 |
struct_n2v_axis | Literal['horizontal', 'vertical', 'none'] | Axis along which to apply structN2V mask, by default "none". | 'none' |
struct_n2v_span | int | Span of the structN2V mask, by default 5. | 5 |
trainer_params | dict | Parameters for the trainer, see the relevant documentation. | None |
logger | Literal['wandb', 'tensorboard', 'none'] | Logger to use, by default "none". | 'none' |
model_params | dict | UNetModel parameters. | None |
optimizer | Literal['Adam', 'Adamax', 'SGD'] | Optimizer to use. | "Adam" |
optimizer_params | dict | Parameters for the optimizer, see PyTorch documentation for more details. | None |
lr_scheduler | Literal['ReduceLROnPlateau', 'StepLR'] | Learning rate scheduler to use. | "ReduceLROnPlateau" |
lr_scheduler_params | dict | Parameters for the learning rate scheduler, see PyTorch documentation for more details. | None |
train_dataloader_params | dict | Parameters for the training dataloader, see the PyTorch docs for | None |
val_dataloader_params | dict | Parameters for the validation dataloader, see PyTorch the docs for | None |
checkpoint_params | dict | Parameters for the checkpoint callback, see PyTorch Lightning documentation ( | None |
Returns:
| Type | Description |
|---|---|
N2VConfiguration | Configuration for training N2V. |
Source code in src/careamics/config/ng_factories/n2v_factory.py
22 23 24 25 26 27 28 29 30 31 32 33 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 225 226 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 | |