Architectures
Deep-learning model configurations.
ArchitectureConfig
Bases: BaseModel
Base Pydantic model for all model architectures.
The model_dump method allows removing the architecture key from the model.
architecture
instance-attribute
Name of the architecture.
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()
Return whether the model is 3D or not.
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
is_3D
|
bool
|
Whether the algorithm is 3D or not. |
required |
validate_conv_strides()
Validate the convolutional strides.
Returns:
| Type | Description |
|---|---|
list
|
Validated strides. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of strides is not 2. |
validate_decoder_even(decoder_n_filters)
classmethod
Validate that num_channels_init is even.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decoder_n_filters
|
int
|
Number of channels. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Validated number of channels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of channels is odd. |
validate_encoder_even(encoder_n_filters)
classmethod
Validate that num_channels_init is even.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_n_filters
|
int
|
Number of channels. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Validated number of channels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of channels is odd. |
validate_input_shape(input_shape)
classmethod
Validate the input shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_shape
|
list
|
Shape of the input patch. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Validated input shape. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of dimensions is not 3 or 4. |
validate_multiscale_count()
validate_z_dims(z_dims)
Validate the z_dims.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_dims
|
tuple
|
Tuple of z dimensions. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Validated z dimensions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of z dimensions is not 4. |
UNetConfig
Bases: ArchitectureConfig
Pydantic model for a N2V(2)-compatible UNet.
Attributes:
| Name | Type | Description |
|---|---|---|
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.
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:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
is_3D
|
bool
|
Whether the algorithm is 3D or not. |
required |
validate_num_channels_init(num_channels_init)
classmethod
Validate that num_channels_init is even.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_channels_init
|
int
|
Number of channels. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Validated number of channels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of channels is odd. |