Config
CAREamics Pydantic configurations.
CAREAlgorithm
Bases: UNetBasedAlgorithm
CARE algorithm configuration.
Attributes:
algorithm = 'care'
class-attribute
instance-attribute
CARE Algorithm name.
loss = 'mae'
class-attribute
instance-attribute
CARE-compatible loss function.
lr_scheduler = LrSchedulerConfig()
class-attribute
instance-attribute
Learning rate scheduler to use, defined in SupportedLrScheduler.
model
instance-attribute
UNet without a final activation function, without the n2v2 modifications, and
without independent channels for mismatching input/output channel numbers.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
get_algorithm_citations()
Return a list of citation entries of the current algorithm.
This is used to generate the model description for the BioImage Model Zoo.
Returns:
-
List[CiteEntry]–List of citation entries.
get_algorithm_description()
get_algorithm_friendly_name()
get_algorithm_references()
Get the algorithm references.
This is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Algorithm references.
get_num_input_channels()
is_supervised()
classmethod
uses_batch_norm()
Return whether the model uses batch normalization.
Returns:
-
bool–Whether the model uses batch normalization.
DataConfig
Bases: BaseModel
Next-Generation Dataset configuration.
DataConfig are used for both training and prediction, with the patching strategy
determining how the data is processed. Note that random is the only patching
strategy compatible with training, while tiled and whole are only used for
prediction.
All supported transforms are defined in the SupportedTransform enum.
augmentations = Field(default=(XYFlipConfig(), XYRandomRotate90Config()), validate_default=True)
class-attribute
instance-attribute
List of augmentations to apply to the data, available transforms are defined in SupportedTransform.
axes
instance-attribute
Axes of the data, as defined in SupportedAxes.
batch_size = Field(default=1, ge=1, validate_default=True)
class-attribute
instance-attribute
Batch size for training.
channels = Field(default=None)
class-attribute
instance-attribute
Channels to use from the data. If None, all channels are used. Note that it is
applied to both inputs and targets.
data_type
instance-attribute
Type of input data.
in_memory = Field(default_factory=default_in_memory, validate_default=True)
class-attribute
instance-attribute
Whether to load all data into memory. This is only supported for 'array',
'tiff' and 'custom' data types. Must be True for array. If None, defaults to
True for 'array', 'tiff' and custom, and False for 'zarr' and 'czi' data
types.
mask_filter = Field(default_factory=(lambda data: _create_mask_filter(data)))
class-attribute
instance-attribute
Mask filter configuration to apply when using a mask during training.
Coverage is automatically set to 1/(2**ndims) based on data dimensionality
where ndims is determined from axes. Only available in training mode.
mode
instance-attribute
Dataset mode, either training, validating or predicting.
n_val_patches = Field(default=8, ge=0, validate_default=True)
class-attribute
instance-attribute
The number of patches to set aside for validation during training. This parameter will be ignored if separate validation data is specified for training.
normalization = Field(...)
class-attribute
instance-attribute
Normalization configuration to use.
num_workers = Field(default_factory=get_default_num_workers, ge=0)
class-attribute
instance-attribute
Default number of workers for all dataloaders that do not explicitly set
num_workers. Automatically detected based on the current platform:
0 on Windows and macOS, min(cpu_count - 1, 4) on Linux.
patch_filter = Field(default=None, discriminator='name')
class-attribute
instance-attribute
Patch filter to apply when using random patching. Only available if
mode is training.
patching = Field(..., discriminator='name')
class-attribute
instance-attribute
Patching strategy to use. Note that random is the only supported strategy for
training, while tiled and whole are only used for prediction.
pred_dataloader_params = Field(default={})
class-attribute
instance-attribute
Dictionary of PyTorch prediction dataloader parameters.
seed = Field(default_factory=generate_random_seed, gt=0)
class-attribute
instance-attribute
Random seed for reproducibility. If not specified, a random seed is generated.
train_dataloader_params = Field(default={'shuffle': True}, validate_default=True)
class-attribute
instance-attribute
Dictionary of PyTorch training dataloader parameters. The dataloader parameters,
should include the shuffle key, which is set to True by default. We strongly
recommend to keep it as True to ensure the best training results.
val_dataloader_params = Field(default={})
class-attribute
instance-attribute
Dictionary of PyTorch validation dataloader parameters.
__str__()
axes_valid(axes, info)
classmethod
Validate axes.
Axes must: - be a combination of 'STCZYX' - not contain duplicates - contain at least 2 contiguous axes: X and Y - contain at most 4 axes - not contain both S and T axes
Parameters:
-
axes(str) –Axes to validate.
-
info(ValidationInfo) –Validation information.
Returns:
-
str–Validated axes.
Raises:
-
ValueError–If axes are not valid.
batch_size_not_in_dataloader_params(dataloader_params)
classmethod
Validate that batch_size is not set in the dataloader parameters.
batch_size must be set through batch_size field, not
through the dataloader parameters.
Parameters:
-
dataloader_params(dict of {str: Any}) –The dataloader parameters.
Returns:
-
dict of {str: Any}–The validated dataloader parameters.
Raises:
-
ValueError–If
batch_sizeis present in the dataloader parameters.
convert_mode(new_mode, new_patch_size=None, overlap_size=None, new_batch_size=None, new_data_type=None, new_axes=None, new_channels=None, new_in_memory=None, new_dataloader_params=None)
Convert a training dataset configuration to a different mode.
This method is intended to facilitate creating validation or prediction configurations from a training configuration.
To perform tile prediction when switching to predicting mode, please provide
both new_patch_size and overlap_size. Switching mode to predicting without
specifying new_patch_size and overlap_size will apply the default patching
strategy, namely whole image strategy. new_patch_size and overlap_size are
only used when switching to predicting.
channels=None will retain the same channels as in the current configuration.
To select all channels, please specify all channels explicitly or pass
channels='all'.
New dataloader parameters will be placed in the appropriate dataloader params field depending on the new mode.
To create a new training configuration, please use
careamics.config.create_ng_data_configuration.
This method compares the new parameters with the current ones and raises errors if incompatible changes are requested, such as switching between 2D and 3D axes, or changing the number of channels. Incompatibility across parameters may be delegated to Pydantic validation.
Parameters:
-
new_mode(Literal['validating', 'predicting']) –The new dataset mode, one of
validatingorpredicting. -
new_patch_size(Sequence of int, default:None) –New patch size. If None for
predicting, uses default whole image strategy. -
overlap_size(Sequence of int, default:None) –New overlap size. Necessary when switching to
predictingwith tiled patching. -
new_batch_size(int, default:None) –New batch size.
-
new_data_type(Literal['array', 'tiff', 'zarr', 'czi', 'custom'], default:None) –New data type.
-
new_axes(str, default:None) –New axes.
-
new_channels(Sequence of int or "all", default:None) –New channels.
-
new_in_memory(bool, default:None) –New in_memory value.
-
new_dataloader_params(dict of {str: Any}, default:None) –New dataloader parameters. These will be placed in the appropriate dataloader params field depending on the new mode.
Returns:
-
DataConfig–New DataConfig with the updated mode and parameters.
Raises:
-
ValueError–If conversion to training mode is requested, or if incompatible changes are requested.
is_3D()
Check if the data is 3D based on the axes.
Either "Z" is in the axes and patching patch_size has 3 dimensions, or for CZI
data, "Z" is in the axes or "T" is in the axes and patching patch_size has
3 dimensions.
This method is used during Configuration validation to cross checks dimensions with the algorithm configuration.
Returns:
-
bool–True if the data is 3D, False otherwise.
propagate_seed_to_augmentations()
Propagate the main seed to all augmentations that support seeds.
This ensures that all augmentations use the same seed for reproducibility, unless they already have a seed explicitly set.
Returns:
-
Self–Data model with propagated seeds.
propagate_seed_to_patching()
Propagate the main seed to the patching strategy if it supports seeds.
This ensures that the patching strategy uses the same seed for reproducibility, unless it already has a seed explicitly set.
Returns:
-
Self–Data model with propagated seed.
set_3D(axes, patch_size)
set_default_max_patch_filter_coverage()
Set default max patch filter coverage based on data dimensionality.
Returns:
-
Self–Data model with default max patch filter coverage updated.
set_default_pin_memory(dataloader_params)
classmethod
Set default pin_memory for dataloader parameters if not provided.
- If 'pin_memory' is not set, it defaults to True if CUDA is available.
Parameters:
-
dataloader_params(dict of {str: Any}) –The dataloader parameters.
Returns:
-
dict of {str: Any}–The dataloader parameters with pin_memory default applied.
set_default_workers_in_dataloaders()
Set num_workers and persistent_workers defaults in all dataloaders.
For each of train_dataloader_params, val_dataloader_params, and
pred_dataloader_params: sets num_workers from the num_workers
field if not already present, and sets persistent_workers=True when
num_workers > 0 and not already specified.
Returns:
-
Self–Validated data model with worker defaults applied to all dataloaders.
shuffle_train_dataloader(train_dataloader_params)
classmethod
Validate that "shuffle" is included in the training dataloader params.
A warning will be raised if shuffle=False.
Parameters:
-
train_dataloader_params(dict of {str: Any}) –The training dataloader parameters.
Returns:
-
dict of {str: Any}–The validated training dataloader parameters.
Raises:
-
ValueError–If "shuffle" is not included in the training dataloader params.
validate_channels(channels, info)
classmethod
Validate channels.
Channels must be a sequence of non-negative integers without duplicates. If
channels are not None, then C must be present in the axes.
Parameters:
-
channels(Sequence of int or None) –Channels to validate.
-
info(ValidationInfo) –Validation information.
Returns:
-
Sequence of int or None–Validated channels.
Raises:
-
ValueError–If channels are not valid.
validate_dimensions()
Validate 2D/3D dimensions between axes and patch size.
Returns:
-
Self–Validated data model.
Raises:
-
ValueError–If the patch size dimension is not compatible with the axes.
validate_filters_against_mode(filter_obj, info)
classmethod
Validate that the filters are only used during training.
Parameters:
-
filter_obj(PatchFilterConfig | MaskFilterConfig | None) –Filter to validate.
-
info(ValidationInfo) –Validation information.
Returns:
-
PatchFilterConfig | MaskFilterConfig | None–Validated filter.
Raises:
-
ValueError–If a filter is used in a mode other than training.
validate_in_memory_with_data_type(in_memory, info)
classmethod
Validate that in_memory is compatible with data_type.
in_memory can only be True for 'array', 'tiff' and 'custom' data types.
Parameters:
-
in_memory(bool) –Whether to load data into memory.
-
info(Any) –Additional information about the field being validated.
Returns:
-
bool–Validated in_memory value.
Raises:
-
ValueError–If in_memory is True for unsupported data types.
validate_patching_strategy_against_mode(patching, info)
classmethod
Validate that the patching strategy is compatible with the dataset mode.
- If mode is
training, patching strategy must berandomorstratified. - If mode is
validating, patching must befixed_random. - If mode is
predicting, patching strategy must betiledorwhole.
Parameters:
-
patching(PatchingStrategies) –Patching strategy to validate.
-
info(ValidationInfo) –Validation information.
Returns:
-
PatchingStrategies–Validated patching strategy.
Raises:
-
ValueError–If the patching strategy is not compatible with the dataset mode.
warn_inconsistent_num_workers()
Warn if num_workers conflicts with a per-dataloader value.
This validator runs before set_default_workers_in_dataloaders, so
the dataloader dicts only contain user-supplied values at this point.
Only fires when num_workers was explicitly set on the model.
Returns:
-
Self–Unchanged data model.
GaussianMixtureNMConfig
Bases: BaseModel
Gaussian mixture noise model.
max_signal = Field(default=1.0, ge=0.0)
class-attribute
instance-attribute
Maximum signal intensity expected in the image.
min_sigma = Field(default=125.0, ge=0.0)
class-attribute
instance-attribute
Minimum value of standard deviation allowed in the GMM.
All values of standard deviation below this are clamped to this value.
min_signal = Field(default=0.0, ge=0.0)
class-attribute
instance-attribute
Minimum signal intensity expected in the image.
n_coeff = Field(default=2, ge=2)
class-attribute
instance-attribute
Number of coefficients to describe the functional relationship between gaussian parameters and the signal. 2 implies a linear relationship, 3 implies a quadratic relationship and so on.
n_gaussian = Field(default=1, ge=1)
class-attribute
instance-attribute
Number of gaussians used for the GMM.
observation = Field(default=None, exclude=True)
class-attribute
instance-attribute
Path to the file containing observation or respective numpy array.
path = None
class-attribute
instance-attribute
Path to the directory where the trained noise model (*.npz) is saved in the
train method.
signal = Field(default=None, exclude=True)
class-attribute
instance-attribute
Path to the file containing signal or respective numpy array.
tol = Field(default=1e-10)
class-attribute
instance-attribute
Tolerance used in the computation of the noise model likelihood.
weight = None
class-attribute
instance-attribute
A [3*n_gaussian, n_coeff] sized array containing the values of the weights
describing the GMM noise model, with each row corresponding to one
parameter of each gaussian, namely [mean, standard deviation and weight].
Specifically, rows are organized as follows:
- first n_gaussian rows correspond to the means
- next n_gaussian rows correspond to the weights
- last n_gaussian rows correspond to the standard deviations
If weight=None, the weight array is initialized using the min_signal
and max_signal parameters.
validate_path()
Validate that the path points to a valid .npz file if provided.
Returns:
-
Self–Returns itself.
Raises:
-
ValueError–If the path is provided but does not point to a valid .npz file.
HDNAlgorithm
Bases: VAEBasedAlgorithm
HDN algorithm configuration.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
algorithm_cross_validation()
get_algorithm_citations()
Return a list of citation entries of the current algorithm.
This is used to generate the model description for the BioImage Model Zoo.
Returns:
-
List[CiteEntry]–List of citation entries.
get_algorithm_description()
get_algorithm_friendly_name()
get_algorithm_references()
Get the algorithm references.
This is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Algorithm references.
get_compatible_algorithms()
classmethod
Get the list of compatible algorithms.
Returns:
-
list of str–List of compatible algorithms.
output_channels_validation()
Validate the consistency between number of out channels and noise models.
Returns:
-
Self–The validated model.
predict_logvar_validation()
Validate the consistency of predict_logvar throughout the model.
Returns:
-
Self–The validated model.
LVAEConfig
Bases: ArchitectureConfig
LVAE model.
decoder_conv_strides = Field(default=[2, 2], validate_default=True)
class-attribute
instance-attribute
Dimensions (2D or 3D) of the convolutional layers.
input_shape = Field(default=(64, 64), validate_default=True)
class-attribute
instance-attribute
Shape of the input patch (Z, Y, X) or (Y, X) if the data is 2D.
is_3D()
model_dump(**kwargs)
set_3D(is_3D)
Set 3D model by setting the conv_dims parameters.
Parameters:
-
is_3D(bool) –Whether the algorithm is 3D or not.
validate_conv_strides()
Validate the convolutional strides.
Returns:
-
list–Validated strides.
Raises:
-
ValueError–If the number of strides is not 2.
validate_decoder_even(decoder_n_filters)
classmethod
Validate that num_channels_init is even.
Parameters:
-
decoder_n_filters(int) –Number of channels.
Returns:
-
int–Validated number of channels.
Raises:
-
ValueError–If the number of channels is odd.
validate_encoder_even(encoder_n_filters)
classmethod
Validate that num_channels_init is even.
Parameters:
-
encoder_n_filters(int) –Number of channels.
Returns:
-
int–Validated number of channels.
Raises:
-
ValueError–If the number of channels is odd.
validate_input_shape(input_shape)
classmethod
Validate the input shape.
Parameters:
-
input_shape(list) –Shape of the input patch.
Returns:
-
list–Validated input shape.
Raises:
-
ValueError–If the number of dimensions is not 3 or 4.
validate_multiscale_count()
validate_z_dims(z_dims)
Validate the z_dims.
Parameters:
-
z_dims(tuple) –Tuple of z dimensions.
Returns:
-
tuple–Validated z dimensions.
Raises:
-
ValueError–If the number of z dimensions is not 4.
LVAELossConfig
Bases: BaseModel
LVAE loss configuration.
denoisplit_weight = 0.9
class-attribute
instance-attribute
Weight for the denoiSplit loss (used in the muSplit-deonoiSplit loss).
kl_params = KLLossConfig()
class-attribute
instance-attribute
KL loss configuration.
kl_weight = 1.0
class-attribute
instance-attribute
Weight for the KL loss in the total net loss.
(i.e., net_loss = reconstruction_weight * rec_loss + kl_weight * kl_loss).
loss_type
instance-attribute
Type of loss to use for LVAE.
musplit_weight = 0.1
class-attribute
instance-attribute
Weight for the muSplit loss (used in the muSplit-denoiSplit loss).
non_stochastic = False
class-attribute
instance-attribute
Whether to sample latents and compute KL.
reconstruction_weight = 1.0
class-attribute
instance-attribute
Weight for the reconstruction loss in the total net loss
(i.e., net_loss = reconstruction_weight * rec_loss + kl_weight * kl_loss).
MaxPatchFilterConfig
Bases: PatchFilterConfig
Pydantic model for the max patch filter.
coverage = Field(default=0.25, ge=0.0, le=1.0)
class-attribute
instance-attribute
Minimum ratio of masked pixels required to keep a sampling region. The optimum value is 1/(2**ndims) where ndims is the number of spatial dimensions.
filtered_patch_prob = Field(default=0.1, ge=0.0, le=1.0)
class-attribute
instance-attribute
The probability that each patch classed as background will be selected each epoch during training.
name = 'max'
class-attribute
instance-attribute
Name of the filter.
ref_channel = 0
class-attribute
instance-attribute
The channel to use as reference for filtering.
threshold
instance-attribute
Threshold for the minimum of the max-filtered patch.
MeanStdPatchFilterConfig
Bases: PatchFilterConfig
Pydantic model for the mean std patch filter.
filtered_patch_prob = Field(default=0.1, ge=0.0, le=1.0)
class-attribute
instance-attribute
The probability that each patch classed as background will be selected each epoch during training.
mean_threshold
instance-attribute
Minimum mean intensity required to keep a patch.
name = 'mean_std'
class-attribute
instance-attribute
Name of the filter.
ref_channel = 0
class-attribute
instance-attribute
The channel to use as reference for filtering.
std_threshold = None
class-attribute
instance-attribute
Minimum standard deviation required to keep a patch.
MicroSplitAlgorithm
Bases: VAEBasedAlgorithm
MicroSplit algorithm configuration.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
algorithm_cross_validation()
get_algorithm_citations()
Return a list of citation entries of the current algorithm.
This is used to generate the model description for the BioImage Model Zoo.
Returns:
-
List[CiteEntry]–List of citation entries.
get_algorithm_description()
get_algorithm_friendly_name()
get_algorithm_references()
Get the algorithm references.
This is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Algorithm references.
get_compatible_algorithms()
classmethod
Get the list of compatible algorithms.
Returns:
-
list of str–List of compatible algorithms.
output_channels_validation()
Validate the consistency between number of out channels and noise models.
Returns:
-
Self–The validated model.
predict_logvar_validation()
Validate the consistency of predict_logvar throughout the model.
Returns:
-
Self–The validated model.
MultiChannelNMConfig
Bases: BaseModel
Noise Model config aggregating noise models for single output channels.
noise_models
instance-attribute
List of noise models, one for each target channel.
N2NAlgorithm
Bases: UNetBasedAlgorithm
Noise2Noise Algorithm configuration.
algorithm = 'n2n'
class-attribute
instance-attribute
N2N Algorithm name.
loss = 'mae'
class-attribute
instance-attribute
N2N-compatible loss function.
lr_scheduler = LrSchedulerConfig()
class-attribute
instance-attribute
Learning rate scheduler to use, defined in SupportedLrScheduler.
model
instance-attribute
UNet without a final activation function, without the n2v2 modifications, and
without independent channels for mismatching input/output channel numbers.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
get_algorithm_citations()
Return a list of citation entries of the current algorithm.
This is used to generate the model description for the BioImage Model Zoo.
Returns:
-
List[CiteEntry]–List of citation entries.
get_algorithm_description()
get_algorithm_friendly_name()
get_algorithm_references()
Get the algorithm references.
This is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Algorithm references.
get_num_input_channels()
is_supervised()
classmethod
uses_batch_norm()
Return whether the model uses batch normalization.
Returns:
-
bool–Whether the model uses batch normalization.
N2VAlgorithm
Bases: UNetBasedAlgorithm
N2V Algorithm configuration.
algorithm = 'n2v'
class-attribute
instance-attribute
N2V Algorithm name.
loss = 'n2v'
class-attribute
instance-attribute
N2V loss function.
lr_scheduler = LrSchedulerConfig()
class-attribute
instance-attribute
Learning rate scheduler to use, defined in SupportedLrScheduler.
model
instance-attribute
Model parameters.
monitor_metric = 'val_loss'
class-attribute
instance-attribute
Metric to monitor for the learning rate scheduler. Used in the returned dict of
PyTorch Lightning configure_optimizers method.
n2v_config = N2VManipulateConfig()
class-attribute
instance-attribute
Noise2Void pixel manipulation configuration.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
get_algorithm_citations()
Return a list of citation entries of the current algorithm.
This is used to generate the model description for the BioImage Model Zoo.
Returns:
-
List[CiteEntry]–List of citation entries.
get_algorithm_description()
Return a description of the algorithm.
This method is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Description of the algorithm.
get_algorithm_friendly_name()
get_algorithm_references()
Get the algorithm references.
This is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Algorithm references.
get_num_input_channels()
is_struct_n2v()
Check if the configuration is using structN2V.
Returns:
-
bool–Whether the configuration is using structN2V.
is_supervised()
classmethod
set_n2v2(use_n2v2)
Set the configuration to use N2V2 or the vanilla Noise2Void.
This method ensures that N2V2 is set correctly and remain coherent, as opposed to setting the different parameters individually.
Parameters:
-
use_n2v2(bool) –Whether to use N2V2.
uses_batch_norm()
Return whether the model uses batch normalization.
Returns:
-
bool–Whether the model uses batch normalization.
validate_n2v2()
Validate that the N2V2 strategy and models are set correctly.
Returns:
-
Self–The validateed configuration.
Raises:
-
ValueError–If N2V2 is used with the wrong pixel manipulation strategy.
PN2VAlgorithm
Bases: UNetBasedAlgorithm
PN2V Algorithm configuration.
algorithm = 'pn2v'
class-attribute
instance-attribute
PN2V Algorithm name.
loss = 'pn2v'
class-attribute
instance-attribute
PN2V loss function (uses N2V loss with noise model).
lr_scheduler = LrSchedulerConfig()
class-attribute
instance-attribute
Learning rate scheduler to use, defined in SupportedLrScheduler.
noise_model
instance-attribute
Noise model configuration for probabilistic denoising.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
get_algorithm_citations()
Return a list of citation entries of the current algorithm.
This is used to generate the model description for the BioImage Model Zoo.
Returns:
-
List[CiteEntry]–List of citation entries.
get_algorithm_description()
Return a description of the algorithm.
This method is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Description of the algorithm.
get_algorithm_friendly_name()
get_algorithm_references()
Get the algorithm references.
This is used to generate the README of the BioImage Model Zoo export.
Returns:
-
str–Algorithm references.
get_num_input_channels()
is_struct_n2v()
Check if the configuration is using structPN2V.
Returns:
-
bool–Whether the configuration is using structPN2V.
set_n2v2(use_n2v2)
Set the configuration to use PN2V2 or the vanilla Probabilistic Noise2Void.
This method ensures that PN2V2 is set correctly and remain coherent, as opposed to setting the different parameters individually.
Parameters:
-
use_n2v2(bool) –Whether to use PN2V2.
uses_batch_norm()
Return whether the model uses batch normalization.
Returns:
-
bool–Whether the model uses batch normalization.
validate_n2v2()
Validate that the N2V2 strategy and models are set correctly.
Returns:
-
Self–The validated configuration.
Raises:
-
ValueError–If N2V2 is used with the wrong pixel manipulation strategy.
ShannonPatchFilterConfig
Bases: PatchFilterConfig
Pydantic model for the Shannon entropy patch filter.
filtered_patch_prob = Field(default=0.1, ge=0.0, le=1.0)
class-attribute
instance-attribute
The probability that each patch classed as background will be selected each epoch during training.
name = 'shannon'
class-attribute
instance-attribute
Name of the filter.
ref_channel = 0
class-attribute
instance-attribute
The channel to use as reference for filtering.
threshold
instance-attribute
Minimum Shannon entropy required to keep a patch.
UNetBasedAlgorithm
Bases: BaseModel
General UNet-based algorithm configuration.
This Pydantic model validates the parameters governing the components of the training algorithm: which algorithm, loss function, model architecture, optimizer, and learning rate scheduler to use.
Currently, we only support N2V, CARE, N2N, and PN2V algorithms. In order to train
these algorithms, use the corresponding configuration child classes (e.g.
N2VAlgorithm) to ensure coherent parameters (e.g. specific losses).
Attributes:
-
algorithm({n2v, care, n2n, pn2v}) –Algorithm to use.
-
loss({n2v, mae, mse}) –Loss function to use.
-
model(UNetConfig) –Model architecture to use.
-
optimizer((OptimizerConfig, optional)) –Optimizer to use.
-
lr_scheduler((LrSchedulerConfig, optional)) –Learning rate scheduler to use.
Raises:
-
ValueError–Algorithm parameter type validation errors.
-
ValueError–If the algorithm, loss and model are not compatible.
algorithm
instance-attribute
Algorithm name, as defined in SupportedAlgorithm.
loss
instance-attribute
Loss function to use, as defined in SupportedLoss.
lr_scheduler = LrSchedulerConfig()
class-attribute
instance-attribute
Learning rate scheduler to use, defined in SupportedLrScheduler.
model
instance-attribute
UNet model configuration.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
get_num_input_channels()
uses_batch_norm()
Return whether the model uses batch normalization.
Returns:
-
bool–Whether the model uses batch normalization.
UNetConfig
Bases: ArchitectureConfig
Pydantic model for a N2V(2)-compatible UNet.
Attributes:
-
depth(int) –Depth of the model, between 1 and 10 (default 2).
-
num_channels_init(int) –Number of filters of the first level of the network, should be even and minimum 8 (default 96).
architecture
instance-attribute
Name of the architecture.
conv_dims = Field(default=2, validate_default=True)
class-attribute
instance-attribute
Dimensions (2D or 3D) of the convolutional layers.
depth = Field(default=2, ge=1, le=10, validate_default=True)
class-attribute
instance-attribute
Number of levels in the UNet.
final_activation = Field(default='None', validate_default=True)
class-attribute
instance-attribute
Final activation function.
in_channels = Field(default=1, ge=1, validate_default=True)
class-attribute
instance-attribute
Number of channels in the input to the model.
independent_channels = Field(default=True, validate_default=True)
class-attribute
instance-attribute
Whether information is processed independently in each channel, used to train channels independently.
n2v2 = Field(default=False, validate_default=True)
class-attribute
instance-attribute
Whether to use N2V2 architecture modifications, with blur pool layers and fewer skip connections.
num_channels_init = Field(default=32, ge=8, le=1024, validate_default=True)
class-attribute
instance-attribute
Number of convolutional filters in the first layer of the UNet.
num_classes = Field(default=1, ge=1, validate_default=True)
class-attribute
instance-attribute
Number of classes or channels in the model output.
residual = Field(default=False, validate_default=True)
class-attribute
instance-attribute
Whether to add a residual connection from the input to the output.
use_batch_norm = Field(default=True, validate_default=True)
class-attribute
instance-attribute
Whether to use batch normalization in the model.
get_num_input_channels()
get_num_output_channels()
is_3D()
Return whether the model is 3D or not.
This method is used in the NG configuration validation to check that the model dimensions match the data dimensions.
Returns:
-
bool–Whether the model is 3D or not.
model_dump(**kwargs)
set_3D(is_3D)
Set 3D model by setting the conv_dims parameters.
Parameters:
-
is_3D(bool) –Whether the algorithm is 3D or not.
uses_batch_norm()
Return whether the model uses batch normalization.
Returns:
-
bool–Whether the model uses batch normalization.
validate_num_channels_init(num_channels_init)
classmethod
Validate that num_channels_init is even.
Parameters:
-
num_channels_init(int) –Number of channels.
Returns:
-
int–Validated number of channels.
Raises:
-
ValueError–If the number of channels is odd.
VAEBasedAlgorithm
Bases: BaseModel
VAE-based algorithm configuration.
optimizer = OptimizerConfig()
class-attribute
instance-attribute
Optimizer to use, defined in SupportedOptimizer.
__str__()
algorithm_cross_validation()
get_compatible_algorithms()
classmethod
Get the list of compatible algorithms.
Returns:
-
list of str–List of compatible algorithms.
output_channels_validation()
Validate the consistency between number of out channels and noise models.
Returns:
-
Self–The validated model.
predict_logvar_validation()
Validate the consistency of predict_logvar throughout the model.
Returns:
-
Self–The validated model.
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.