Factories
Convenience functions to create coherent configurations for CAREamics.
create_advanced_care_config(*, experiment_name, data_type, axes, patch_size, batch_size, num_epochs=30, num_steps=None, n_channels_in=None, n_channels_out=None, augmentations=None, n_val_patches=8, in_memory=None, channels=None, independent_channels=False, normalization='mean_std', normalization_params=None, patch_filter_config=None, num_workers=-1, trainer_params=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, early_stopping_params=None, logger='none', seed=None)
Create a configuration for training CARE.
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_in and
n_channels_out to the number of input and output channels, respectively.
By default, all channels are trained independently. To train all channels together,
set independent_channels to False.
By default, the augmentations applied are random flips along X or Y, and random 90 degrees rotations in the XY plane. To disable the augmentations, simply pass an empty list.
The parameters of the UNet can be specified in the model_params (passed as a
parameter-value dictionary).
Note that num_workers is applied to all dataloaders unless explicitly overridden
in the respective dataloader parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
num_epochs(int, default:30) –Number of epochs to train for. If provided, this will be added to trainer_params.
-
num_steps(int | None, default:None) –Number of batches in 1 epoch. If provided, this will be added to trainer_params. Translates to
limit_train_batchesin PyTorch Lightning Trainer. See relevant documentation for more details. -
n_channels_in(int | None, default:None) –Number of input channels. If
channelsis specified, then the number of channels is inferred from its length and this parameter is ignored. -
n_channels_out(int | None, default:None) –Number of output channels. If not specified, but n_channels_in is specified, it will default to the same number as n_channels_in.
-
augmentations(Sequence[{x_flip, y_flip, rotate_90}] | None, default:None) –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.
-
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
in_memory(bool | None, default:None) –Whether to load all data into memory. This is only supported for 'array', 'tiff' and 'custom' data types. If
None, defaults toTruefor 'array', 'tiff' andcustom, andFalsefor 'zarr' and 'czi' data types. Must beTrueforarray. -
channels(Sequence[int] | None, default:None) –List of channels to use. If
None, all channels are used. -
independent_channels(bool, default:False) –Whether to train all channels independently.
-
normalization((mean_std, min_max, quantile, none), default:"mean_std") –Normalization strategy to use.
-
normalization_params(dict[str, Any] | None, default:None) –Strategy-specific normalization parameters. If None, default values are used.
- For "mean_std": {"input_means": [...], "input_stds": [...]} (optional)
- For "min_max": {"input_mins": [...], "input_maxes": [...]} (optional)
- For "quantile": {"lower_quantiles": 0.01, "upper_quantiles": 0.99} (optional)
- For "none": No parameters needed.
-
patch_filter_config(SupportedPatchFilterConfig | None, default:None) –Specify the configuration for patch filtering. Patch filtering reduces the probability of background patches being selected during training. If
None, no patch filter is applied. -
num_workers(int, default:-1) –Number of workers for data loading. Use
-1to automatically choose based on the number of available CPUs. Unless explicitly overridden intrain_dataloader_paramsandval_dataloader_params, this will be applied to all dataloaders. -
trainer_params(dict | None, default:None) –Parameters for the trainer, see the relevant documentation.
-
model_params(dict | None, default:None) –UNetModel parameters.
-
optimizer(Literal['Adam', 'Adamax', 'SGD'], default:"Adam") –Optimizer to use.
-
optimizer_params(dict[str, Any] | None, default:None) –Parameters for the optimizer, see PyTorch documentation for more details.
-
lr_scheduler(Literal['ReduceLROnPlateau', 'StepLR'], default:"ReduceLROnPlateau") –Learning rate scheduler to use.
-
lr_scheduler_params(dict[str, Any] | None, default:None) –Parameters for the learning rate scheduler, see PyTorch documentation for more details.
-
train_dataloader_params(dict[str, Any] | None, default:None) –Parameters for the training dataloader, see the PyTorch docs for
DataLoader. If left asNone,{"shuffle": True}will be used. -
val_dataloader_params(dict[str, Any] | None, default:None) –Parameters for the validation dataloader, see PyTorch the docs for
DataLoader. -
checkpoint_params(dict[str, Any] | None, default:None) –Parameters for the checkpoint callback, see PyTorch Lightning documentation (
ModelCheckpoint) for the list of available parameters. -
early_stopping_params(dict[str, Any] | None, default:None) –Parameters for the early stopping callback, see PyTorch Lightning documentation (
EarlyStopping) for the list of available parameters. -
logger(Literal['wandb', 'tensorboard', 'none'], default:"none") –Logger to use.
-
seed(int | None, default:None) –Random seed for reproducibility.
Returns:
-
Configuration–Configuration for training CARE.
create_advanced_n2n_config(experiment_name, data_type, axes, patch_size, batch_size, num_epochs=30, num_steps=None, n_channels_in=None, n_channels_out=None, augmentations=None, n_val_patches=8, in_memory=None, channels=None, independent_channels=True, normalization='mean_std', normalization_params=None, patch_filter_config=None, num_workers=-1, trainer_params=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, logger='none', seed=None)
Create a configuration for training Noise2Noise.
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_in and
n_channels_out to the number of input and output channels, respectively.
By default, all channels are trained independently. To train all channels together,
set independent_channels to False.
By default, the augmentations applied are random flips along X or Y, and random 90 degrees rotations in the XY plane. To disable the augmentations, simply pass an empty list.
The parameters of the UNet can be specified in the model_params (passed as a
parameter-value dictionary).
Note that num_workers is applied to all dataloaders unless explicitly overridden
in the respective dataloader parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
num_epochs(int, default:30) –Number of epochs to train for. If provided, this will be added to trainer_params.
-
num_steps(int | None, default:None) –Number of batches in 1 epoch. If provided, this will be added to trainer_params. Translates to
limit_train_batchesin PyTorch Lightning Trainer. See relevant documentation for more details. -
n_channels_in(int | None, default:None) –Number of input channels. If
channelsis specified, then the number of channels is inferred from its length and this parameter is ignored. -
n_channels_out(int | None, default:None) –Number of output channels. If not specified, but n_channels_in is specified, it will default to the same number as n_channels_in.
-
augmentations(Sequence[{x_flip, y_flip, rotate_90}] | None, default:None) –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.
-
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
in_memory(bool | None, default:None) –Whether to load all data into memory. This is only supported for 'array', 'tiff' and 'custom' data types. If
None, defaults toTruefor 'array', 'tiff' andcustom, andFalsefor 'zarr' and 'czi' data types. Must beTrueforarray. -
channels(Sequence[int] | None, default:None) –List of channels to use. If
None, all channels are used. -
independent_channels(bool, default:True) –Whether to train all channels independently.
-
normalization((mean_std, min_max, quantile, none), default:"mean_std") –Normalization strategy to use.
-
normalization_params(dict[str, Any] | None, default:None) –Strategy-specific normalization parameters. If None, default values are used.
- For "mean_std": {"input_means": [...], "input_stds": [...]} (optional)
- For "min_max": {"input_mins": [...], "input_maxes": [...]} (optional)
- For "quantile": {"lower_quantiles": 0.01, "upper_quantiles": 0.99} (optional)
- For "none": No parameters needed.
-
patch_filter_config(SupportedPatchFilterConfig | None, default:None) –Specify the configuration for patch filtering. Patch filtering reduces the probability of background patches being selected during training. If
None, no patch filter is applied. -
num_workers(int, default:-1) –Number of workers for data loading. Use
-1to automatically choose based on the number of available CPUs. Unless explicitly overridden intrain_dataloader_paramsandval_dataloader_params, this will be applied to all dataloaders. -
trainer_params(dict | None, default:None) –Parameters for the trainer, see the relevant documentation.
-
model_params(dict | None, default:None) –UNetModel parameters.
-
optimizer(Literal['Adam', 'Adamax', 'SGD'], default:"Adam") –Optimizer to use.
-
optimizer_params(dict[str, Any] | None, default:None) –Parameters for the optimizer, see PyTorch documentation for more details.
-
lr_scheduler(Literal['ReduceLROnPlateau', 'StepLR'], default:"ReduceLROnPlateau") –Learning rate scheduler to use.
-
lr_scheduler_params(dict[str, Any] | None, default:None) –Parameters for the learning rate scheduler, see PyTorch documentation for more details.
-
train_dataloader_params(dict[str, Any] | None, default:None) –Parameters for the training dataloader, see the PyTorch docs for
DataLoader. If left asNone,{"shuffle": True}will be used. -
val_dataloader_params(dict[str, Any] | None, default:None) –Parameters for the validation dataloader, see PyTorch the docs for
DataLoader. -
checkpoint_params(dict[str, Any] | None, default:None) –Parameters for the checkpoint callback, see PyTorch Lightning documentation (
ModelCheckpoint) for the list of available parameters. -
logger(Literal['wandb', 'tensorboard', 'none'], default:"none") –Logger to use.
-
seed(int | None, default:None) –Random seed for reproducibility.
Returns:
-
Configuration–Configuration for training Noise2Noise.
create_advanced_n2v_config(experiment_name, data_type, axes, patch_size, batch_size, num_epochs=30, num_steps=None, n_channels=None, augmentations=None, n_val_patches=8, in_memory=None, channels=None, independent_channels=True, normalization='mean_std', normalization_params=None, patch_filter_config=None, use_n2v2=False, roi_size=11, masked_pixel_percentage=0.2, struct_n2v_axis='none', struct_n2v_span=5, num_workers=-1, trainer_params=None, model_params=None, optimizer='Adam', optimizer_params=None, lr_scheduler='ReduceLROnPlateau', lr_scheduler_params=None, monitor_metric='val_loss', train_dataloader_params=None, val_dataloader_params=None, checkpoint_params=None, logger='none', seed=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 augmentations applied are random flips along X or Y, and random 90 degrees rotations in the XY plane. To disable the augmentations, 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.
If you pass "horizontal" or "vertical" to struct_n2v_axis, then structN2V mask
will be applied to each manipulated pixel.
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.
Note that num_workers is applied to all dataloaders unless explicitly overridden
in the respective dataloader parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
num_epochs(int, default:30) –Number of epochs to train for. If provided, this will be added to trainer_params.
-
num_steps(int | None, default:None) –Number of batches in 1 epoch. If provided, this will be added to trainer_params. Translates to
limit_train_batchesin PyTorch Lightning Trainer. See relevant documentation for more details. -
n_channels(int | None, default:None) –Number of channels (in and out). If
channelsis specified, then the number of channels is inferred from its length and this parameter is ignored. -
augmentations(Sequence[{x_flip, y_flip, rotate_90}] | None, default:None) –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.
-
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
in_memory(bool | None, default:None) –Whether to load all data into memory. This is only supported for 'array', 'tiff' and 'custom' data types. If
None, defaults toTruefor 'array', 'tiff' andcustom, andFalsefor 'zarr' and 'czi' data types. Must beTrueforarray. -
channels(Sequence[int] | None, default:None) –List of channels to use. If
None, all channels are used. -
independent_channels(bool, default:True) –Whether to train all channels independently.
-
normalization((mean_std, min_max, quantile, none), default:"mean_std") –Normalization strategy to use.
-
normalization_params(dict[str, Any] | None, default:None) –Strategy-specific normalization parameters. If None, default values are used.
- For "mean_std": {"input_means": [...], "input_stds": [...]} (optional)
- For "min_max": {"input_mins": [...], "input_maxes": [...]} (optional)
- For "quantile": {"lower_quantiles": 0.01, "upper_quantiles": 0.99} (optional)
- For "none": No parameters needed.
-
patch_filter_config(SupportedPatchFilterConfig | None, default:None) –Specify the configuration for patch filtering. Patch filtering reduces the probability of background patches being selected during training. If
None, no patch filter is applied. -
use_n2v2(bool, default:False) –Whether to use N2V2.
-
roi_size(int, default:11) –N2V pixel manipulation area.
-
masked_pixel_percentage(float, default:0.2) –Percentage of pixels masked in each patch.
-
struct_n2v_axis(Literal['horizontal', 'vertical', 'none'], default:"none") –Axis along which to apply structN2V mask.
-
struct_n2v_span(int, default:5) –Span of the structN2V mask.
-
num_workers(int, default:-1) –Number of workers for data loading. Use
-1to automatically choose based on the number of available CPUs. Unless explicitly overridden intrain_dataloader_paramsandval_dataloader_params, this will be applied to all dataloaders. -
trainer_params(dict | None, default:None) –Parameters for the trainer, see the relevant documentation.
-
model_params(dict | None, default:None) –UNetModel parameters.
-
optimizer(Literal['Adam', 'Adamax', 'SGD'], default:"Adam") –Optimizer to use.
-
optimizer_params(dict[str, Any] | None, default:None) –Parameters for the optimizer, see PyTorch documentation for more details.
-
lr_scheduler(Literal['ReduceLROnPlateau', 'StepLR'], default:"ReduceLROnPlateau") –Learning rate scheduler to use.
-
lr_scheduler_params(dict[str, Any] | None, default:None) –Parameters for the learning rate scheduler, see PyTorch documentation for more details.
-
monitor_metric(Literal['train_loss', 'train_loss_epoch', 'val_loss'], default:'val_loss') –Metric to monitor for the learning rate scheduler. Default: "val_loss".
-
train_dataloader_params(dict[str, Any] | None, default:None) –Parameters for the training dataloader, see the PyTorch docs for
DataLoader. If left asNone,{"shuffle": True}will be used. -
val_dataloader_params(dict[str, Any] | None, default:None) –Parameters for the validation dataloader, see PyTorch the docs for
DataLoader. -
checkpoint_params(dict[str, Any] | None, default:None) –Parameters for the checkpoint callback, see PyTorch Lightning documentation (
ModelCheckpoint) for the list of available parameters. -
logger(Literal['wandb', 'tensorboard', 'none'], default:"none") –Logger to use.
-
seed(int | None, default:None) –Random seed for reproducibility.
Returns:
-
N2VConfiguration–Configuration for training N2V.
create_care_config(*, experiment_name, data_type, axes, patch_size, batch_size, num_epochs=30, num_steps=None, augmentations=None, n_val_patches=8, n_channels_in=None, n_channels_out=None)
Create a configuration for training CARE.
The axes parameters must reflect the actual axes and axis order from the data,
and should be the same throughout all images. The accepted axes are STCZYX. If "C"
is in axes, then you need to set n_channels_in and n_channels_out to the
number of channels expected in the input and output, respectively.
By default, CAREamics will go through the entire training data once per epoch. For
large datasets, this can lead to very long epochs. To limit the number of batches
per epoch, set the num_steps parameter to the desired number of batches.
If the content of your data is expected to always have the same orientation,
consider disabling certain augmentations. By default augmentations=None will apply
random flips along X and Y, and random 90 degrees rotations in the XY plane. To
disable augmentations, set augmentations=[].
See create_advanced_care_config for more parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
num_epochs(int, default:30) –Number of epochs to train for.
-
num_steps(int, default:None) –Number of batches in 1 epoch.
-
augmentations(Sequence of {"x_flip", "y_flip", "rotate_90"}, default:None) –List of augmentations to apply. If
None, all augmentations are applied. -
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
n_channels_in(int or None, default:None) –Number of input channels.
-
n_channels_out(int or None, default:None) –Number of output channels.
Returns:
-
Configuration–Configuration for training CARE.
create_n2n_config(*, experiment_name, data_type, axes, patch_size, batch_size, num_epochs=30, num_steps=None, augmentations=None, n_val_patches=8, n_channels_in=None, n_channels_out=None)
Create a configuration for training Noise2Noise.
The axes parameters must reflect the actual axes and axis order from the data,
and should be the same throughout all images. The accepted axes are STCZYX. If "C"
is in axes, then you need to set n_channels_in and n_channels_out to the
number of channels expected in the input and output, respectively.
By default, CAREamics will go through the entire training data once per epoch. For
large datasets, this can lead to very long epochs. To limit the number of batches
per epoch, set the num_steps parameter to the desired number of batches.
If the content of your data is expected to always have the same orientation,
consider disabling certain augmentations. By default augmentations=None will apply
random flips along X and Y, and random 90 degrees rotations in the XY plane. To
disable augmentations, set augmentations=[].
See create_advanced_care_config for more parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
num_epochs(int, default:30) –Number of epochs to train for.
-
num_steps(int, default:None) –Number of batches in 1 epoch.
-
augmentations(Sequence of {"x_flip", "y_flip", "rotate_90"}, default:None) –List of augmentations to apply. If
None, all augmentations are applied. -
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
n_channels_in(int or None, default:None) –Number of input channels.
-
n_channels_out(int or None, default:None) –Number of output channels.
Returns:
-
Configuration–Configuration for training Noise2Noise.
create_n2v_config(experiment_name, data_type, axes, patch_size, batch_size, num_epochs=30, num_steps=None, augmentations=None, n_val_patches=8, use_n2v2=False, n_channels=None)
Create a configuration for training N2V.
To activate N2V2, set use_n2v2 to True.
The axes parameters must reflect the actual axes and axis order from the data,
and should be the same throughout all images. The accepted axes are STCZYX. If "C"
is in axes, then you need to set n_channels to the number of channels.
By default, CAREamics will go through the entire training data once per epoch. For
large datasets, this can lead to very long epochs. To limit the number of batches
per epoch, set the num_steps parameter to the desired number of batches.
If the content of your data is expected to always have the same orientation,
consider disabling certain augmentations. By default augmentations=None will apply
random flips along X and Y, and random 90 degrees rotations in the XY plane. To
disable augmentations, set augmentations=[].
See create_advanced_n2v_config for more parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
num_epochs(int, default:30) –Number of epochs to train for.
-
num_steps(int, default:None) –Number of batches in 1 epoch.
-
augmentations(Sequence of {"x_flip", "y_flip", "rotate_90"}, default:None) –List of augmentations to apply. If
None, all augmentations are applied. -
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
use_n2v2(bool, default:False) –Whether to use N2V2.
-
n_channels(int or None, default:None) –Number of channels (in and out).
Returns:
-
N2VConfiguration–Configuration for training N2V.
create_ng_data_configuration(data_type, axes, patch_size, batch_size, augmentations=None, normalization=None, patch_filter_config=None, channels=None, in_memory=None, n_val_patches=8, num_workers=-1, train_dataloader_params=None, val_dataloader_params=None, pred_dataloader_params=None, seed=None)
Create a training NGDatasetConfig.
Note that num_workers is applied to all dataloaders unless explicitly overridden
in the respective dataloader parameters.
Parameters:
-
data_type((array, tiff, zarr, czi, custom), default:"array") –Type of the data.
-
axes(str) –Axes of the data.
-
patch_size(list of int) –Size of the patches along the spatial dimensions.
-
batch_size(int) –Batch size.
-
augmentations(list of transforms or None, default:None) –List of transforms to apply. If
None, default augmentations are applied (flip in X and Y, rotations by 90 degrees in the XY plane). -
normalization(dict, default:None) –Normalization configuration dictionary. If None, defaults to mean_std normalization with automatically computed statistics.
-
patch_filter_config(SupportedPatchFilterConfig | None, default:None) –Specify the configuration for patch filtering. Patch filtering reduces the probability of background patches being selected during training. If
None, no patch filter is applied. -
channels(Sequence of int, default:None) –List of channels to use. If
None, all channels are used. -
in_memory(bool, default:None) –Whether to load all data into memory. This is only supported for 'array', 'tiff' and 'custom' data types. If
None, defaults toTruefor 'array', 'tiff' andcustom, andFalsefor 'zarr' and 'czi' data types. Must beTrueforarray. -
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
num_workers(int, default:-1) –Number of workers for data loading. Use
-1to automatically choose based on the number of available CPUs (calls :func:get_default_num_workers). -
augmentations(list of transforms or None, default:None) –List of transforms to apply. If
None, default augmentations are applied (flip in X and Y, rotations by 90 degrees in the XY plane). -
train_dataloader_params(dict, default:None) –Parameters for the training dataloader, see PyTorch notes, by default None.
-
val_dataloader_params(dict, default:None) –Parameters for the validation dataloader, see PyTorch notes, by default None.
-
pred_dataloader_params(dict, default:None) –Parameters for the test dataloader, see PyTorch notes, by default None.
-
seed(int, default:None) –Random seed for reproducibility. If
None, seed is generated automatically.
Returns:
-
DataConfig–Next-Generation Data model with the specified parameters.
create_structn2v_config(experiment_name, data_type, axes, patch_size, batch_size, struct_n2v_axis, struct_n2v_span=5, num_epochs=30, num_steps=None, n_val_patches=8, use_n2v2=False, n_channels=None)
Create a configuration for training structN2V.
The structN2V mask is applied a horizontal or vertical axis, with extent defined by
struct_n2v_span (default=5, leading to a mask of size 11). For structN2V,
augmentations are disabled.
To activate N2V2, set use_n2v2 to True.
The axes parameters must reflect the actual axes and axis order from the data,
and should be the same throughout all images. The accepted axes are STCZYX. If "C"
is in axes, then you need to set n_channels to the number of channels.
patch_size is only along the spatial dimensions and should be of length 3 if "Z"
is present in axes, otherwise of length 2.
By default, CAREamics will go through the entire training data once per epoch. For
large datasets, this can lead to very long epochs. To limit the number of batches
per epoch, set the num_steps parameter to the desired number of batches.
See create_advanced_n2v_config for more parameters.
Parameters:
-
experiment_name(str) –Name of the experiment. A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.
-
data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom']) –Type of the data.
-
axes(str) –Axes of the data (e.g. SYX).
-
patch_size(Sequence[int]) –Size of the patches along the spatial dimensions (e.g. [64, 64]).
-
batch_size(int) –Batch size.
-
struct_n2v_axis(Literal['horizontal', 'vertical']) –Axis along which to apply structN2V mask.
-
struct_n2v_span(int, default:5) –Span of the structN2V mask.
-
num_epochs(int, default:30) –Number of epochs to train for.
-
num_steps(int, default:None) –Number of batches in 1 epoch.
-
n_val_patches(int, default:8,) –The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
-
use_n2v2(bool, default:False) –Whether to use N2V2.
-
n_channels(int or None, default:None) –Number of channels (in and out).
Returns:
-
N2VConfiguration–Configuration for training structN2V.