fcn_algorithm_model
Module containing FCNAlgorithmConfig
class.
FCNAlgorithmConfig
#
Bases: BaseModel
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 custom models. The n2v
algorithm is only compatible with n2v
loss and UNet
architecture. The custom
algorithm allows you to register your own architecture and select it using its name as name
in the custom pydantic model.
Attributes:
Name | Type | Description |
---|---|---|
algorithm | {n2v, care, n2n, custom} | Algorithm to use. |
loss | {n2v, mae, mse} | Loss function to use. |
model | UNetModel or CustomModel | Model architecture to use. |
optimizer | (OptimizerModel, optional) | Optimizer to use. |
lr_scheduler | (LrSchedulerModel, optional) | Learning rate scheduler to use. |
Raises:
Type | Description |
---|---|
ValueError | Algorithm parameter type validation errors. |
ValueError | If the algorithm, loss and model are not compatible. |
Examples:
Minimum example:
>>> from careamics.config import FCNAlgorithmConfig
>>> config_dict = {
... "algorithm": "n2v",
... "loss": "n2v",
... "model": {
... "architecture": "UNet",
... }
... }
>>> config = FCNAlgorithmConfig(**config_dict)
Source code in src/careamics/config/fcn_algorithm_model.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
algorithm: Literal['n2v', 'care', 'n2n', 'custom']
instance-attribute
#
Name of the algorithm, as defined in SupportedAlgorithm. Use custom
for custom model architecture.
loss: Literal['n2v', 'mae', 'mse']
instance-attribute
#
Loss function to use, as defined in SupportedLoss.
lr_scheduler: LrSchedulerModel = LrSchedulerModel()
class-attribute
instance-attribute
#
Learning rate scheduler to use, defined in SupportedLrScheduler.
model: Union[UNetModel, CustomModel] = Field(discriminator='architecture')
class-attribute
instance-attribute
#
Model architecture to use, along with its parameters. Compatible architectures are defined in SupportedArchitecture, and their Pydantic models in careamics.config.architectures
.
optimizer: OptimizerModel = OptimizerModel()
class-attribute
instance-attribute
#
Optimizer to use, defined in SupportedOptimizer.
__str__()
#
Pretty string representing the configuration.
Returns:
Type | Description |
---|---|
str | Pretty string. |
algorithm_cross_validation()
#
Validate the algorithm model based on algorithm
.
N2V: - loss must be n2v - model must be a UNetModel
Returns:
Type | Description |
---|---|
Self | The validated model. |
Source code in src/careamics/config/fcn_algorithm_model.py
get_compatible_algorithms()
classmethod
#
Get the list of compatible algorithms.
Returns:
Type | Description |
---|---|
list of str | List of compatible algorithms. |