autoden
¶
Auto-Denoise package.
Unsupervised and self-supervised CNN denoising methods.
Modules:
-
algorithms–Algorithms sub-package.
-
cli–Module that contains the command line application.
-
debug–Debugging utilities.
-
losses–Data losses definitions.
-
models–Models sub-package.
-
transforms–Transforms sub-package.
Classes:
-
DIP–Deep image prior.
-
N2N–Self-supervised denoising from pairs of images.
-
N2V–Self-supervised denoising from single images.
-
Supervised–Supervised denoising class.
DIP
¶
DIP(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = None,
device: str = "cuda" if is_available() else "cpu",
batch_size: int | None = None,
augmentation: (
str
| Augmentation
| Sequence[str | Augmentation]
| None
) = None,
save_epochs_dir: str | None = None,
verbose: bool = True,
)
Bases: Denoiser
Deep image prior.
Parameters:
-
model(str | NetworkParams | Module | Mapping | None) –Type of neural network to use or a specific network (or state) to use
-
data_scale_bias(DataScaleBias | None, default:None) –Scale and bias of the input data, by default None
-
reg_val(float | None, default:None) –Regularization value, by default 1e-5
-
device(str, default:'cuda' if is_available() else 'cpu') –Device to use, by default "cuda" if cuda is available, otherwise "cpu"
-
save_epochs_dir(str | None, default:None) –Directory where to save network states at each epoch. If None disabled, by default None
-
verbose(bool, default:True) –Whether to produce verbose output, by default True
Methods:
-
infer–Inference, given an initial stack of images.
-
prepare_data–Prepare input data.
-
train–Train the model in an unsupervised manner.
Attributes:
-
n_channels_in(int) –Returns the number of input channels of the model.
-
n_channels_out(int) –Returns the number of output channels of the model.
-
n_dims(int) –Returns the expected signal dimensions.
Source code in src/autoden/algorithms/denoiser.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
n_channels_in
property
¶
n_channels_in: int
Returns the number of input channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_in", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of input channels.
n_channels_out
property
¶
n_channels_out: int
Returns the number of output channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_out", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of output channels.
n_dims
property
¶
n_dims: int
Returns the expected signal dimensions.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_dims", this property returns its value.
Otherwise, it defaults to 2.
Returns:
-
int–The expected signal dimensions.
infer
¶
infer(
inp: NDArray, channel_axis_dst: int | None = None
) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp(NDArray) –The input stack of images
-
channel_axis_dst(int | None, default:None) –The desired channel axis for the output. If None, the output will have the same channel axis as the input.
Returns:
-
NDArray–The denoised stack of images
Source code in src/autoden/algorithms/denoiser.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
prepare_data
¶
prepare_data(
tgt: NDArray,
inp: NDArray | None = None,
*,
num_tst_ratio: float = 0.2,
average_redundant: bool = False,
channel_axis: int | None = None
) -> tuple[NDArray, NDArray, NDArray]
Prepare input data.
Parameters:
-
tgt(NDArray) –The target image array. The shape of the output noise array will match the spatial dimensions of this array.
-
inp(NDArray | None, default:None) –The input image array. If provided, it will be used as the initial input for the DIP algorithm. If None, a random noise array will be generated. Default is None.
-
num_tst_ratio(float, default:0.2) –The ratio of the test set size to the total dataset size. Default is 0.2.
-
average_redundant(bool, default:False) –If True, average redundant realizations in the target array to match the expected number of dimensions. Default is False.
-
channel_axis(int | None, default:None) –The axis of the target array that corresponds to the spectral dimension. If None, the spectral dimension is assumed to not be present. Default is None.
Returns:
-
tuple[NDArray, NDArray, NDArray]–A tuple containing: - A random noise array with the same spatial dimensions as the target image. - The target image array. - A mask array indicating the training pixels.
Notes
This function generates a random noise array with the same spatial dimensions as the target image. The noise array is used as the initial input for the DIP algorithm. It also generates a mask array indicating the training pixels based on the provided ratio.
Source code in src/autoden/algorithms/deep_image_prior.py
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 | |
train
¶
train(
inp: NDArray,
tgt: NDArray,
mask_trn: NDArray,
*,
epochs: int,
learning_rate: float = 0.001,
optimizer: str = "adam",
lower_limit: float | NDArray | None = None
) -> dict[str, NDArray]
Train the model in an unsupervised manner.
Parameters:
-
inp(NDArray) –The input image.
-
tgt(NDArray) –The target image to be denoised.
-
mask_trn(NDArray) –The mask array indicating the training pixels.
-
epochs(int) –The number of training epochs.
-
learning_rate(float, default:0.001) –The learning rate for the optimizer. Default is 1e-3.
-
optimizer(str, default:'adam') –The optimization algorithm to use. Default is "adam".
-
lower_limit(float | NDArray | None, default:None) –The lower limit for the input data. If provided, the input data will be clipped to this limit. Default is None.
Returns:
Notes
This method trains the model using the deep image prior approach in an unsupervised manner. It uses a random initialization for the input image if not provided and applies a scaling and bias transformation to the input and target images. It then trains the model using the specified optimization algorithm and the provided mask array indicating the training pixels.
Source code in src/autoden/algorithms/deep_image_prior.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
N2N
¶
N2N(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = None,
device: str = "cuda" if is_available() else "cpu",
batch_size: int | None = None,
augmentation: (
str
| Augmentation
| Sequence[str | Augmentation]
| None
) = None,
save_epochs_dir: str | None = None,
verbose: bool = True,
)
Bases: Denoiser
Self-supervised denoising from pairs of images.
Parameters:
-
model(str | NetworkParams | Module | Mapping | None) –Type of neural network to use or a specific network (or state) to use
-
data_scale_bias(DataScaleBias | None, default:None) –Scale and bias of the input data, by default None
-
reg_val(float | None, default:None) –Regularization value, by default 1e-5
-
device(str, default:'cuda' if is_available() else 'cpu') –Device to use, by default "cuda" if cuda is available, otherwise "cpu"
-
save_epochs_dir(str | None, default:None) –Directory where to save network states at each epoch. If None disabled, by default None
-
verbose(bool, default:True) –Whether to produce verbose output, by default True
Methods:
-
infer–Perform inference on the input data.
-
prepare_data–Prepare input data for training.
-
train–Train the denoiser using the Noise2Noise self-supervised approach.
Attributes:
-
n_channels_in(int) –Returns the number of input channels of the model.
-
n_channels_out(int) –Returns the number of output channels of the model.
-
n_dims(int) –Returns the expected signal dimensions.
Source code in src/autoden/algorithms/denoiser.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
n_channels_in
property
¶
n_channels_in: int
Returns the number of input channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_in", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of input channels.
n_channels_out
property
¶
n_channels_out: int
Returns the number of output channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_out", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of output channels.
n_dims
property
¶
n_dims: int
Returns the expected signal dimensions.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_dims", this property returns its value.
Otherwise, it defaults to 2.
Returns:
-
int–The expected signal dimensions.
infer
¶
Perform inference on the input data.
Parameters:
-
inp(NDArray) –The input data to perform inference on. It is expected to have an extra dimension including the different splits.
-
average_splits(bool, default:True) –If True, the splits are averaged. Default is True.
-
channel_axis_dst(int | None, default:None) –The desired channel axis for the output. If None, the output will have the same channel axis as the input.
Returns:
-
NDArray–The inferred output data. If
average_splitsis True, the splits are averaged.
Notes
If self.batch_size is set, the input data is processed in batches to avoid memory issues.
Source code in src/autoden/algorithms/noise2noise.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
prepare_data
¶
prepare_data(
inp: NDArray,
num_tst_ratio: float = 0.2,
strategy: str = "1:X",
channel_axis: int | None = None,
realizations_axis: int = 0,
) -> tuple[NDArray, NDArray, NDArray]
Prepare input data for training.
Parameters:
-
inp(NDArray) –The input data to be used for training. This should be a NumPy array of shape (N, H, W), where N is the number of samples, and H and W are the height and width of each sample, respectively.
-
num_tst_ratio(float, default:0.2) –The ratio of the input data to be used for testing. The remaining data will be used for training. Default is 0.2.
-
strategy(str, default:'1:X') –The strategy to be used for creating input-target pairs. The available strategies are: - "1:X": Use the mean of the remaining samples as the target for each sample. - "X:1": Use the mean of the remaining samples as the input for each sample. Default is "1:X".
-
channel_axis(int | None, default:None) –The axis of the input array that corresponds to the spectral dimension. If None, the spectral dimension is assumed to not be present. Default is None.
-
realizations_axis(int, default:0) –The axis of the input array that corresponds to the redundant realizations dimension. Default is 0.
Returns:
-
tuple[NDArray, NDArray, NDArray]–A tuple containing: - The input data array. - The target data array. - The mask array indicating the training pixels.
Notes
This function generates input-target pairs based on the specified strategy. It also generates a mask array indicating the training pixels based on the provided ratio.
Source code in src/autoden/algorithms/noise2noise.py
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 | |
train
¶
train(
inp: NDArray,
tgt: NDArray,
mask_trn: NDArray,
*,
epochs: int,
learning_rate: float = 0.001,
optimizer: str = "adam",
lower_limit: float | NDArray | None = None,
restarts: int | None = None,
accum_grads: bool = False
) -> dict[str, NDArray]
Train the denoiser using the Noise2Noise self-supervised approach.
Parameters:
-
inp(NDArray) –The input data to be used for training. This should be a NumPy array of shape (N, H, W), where N is the number of samples, and H and W are the height and width of each sample, respectively.
-
tgt(NDArray) –The target data to be used for training. This should be a NumPy array of shape (N, H, W), where N is the number of samples, and H and W are the height and width of each sample, respectively.
-
mask_trn(NDArray) –The mask array indicating the pixels used for training.
-
epochs(int) –The number of epochs to train the model.
-
learning_rate(float, default:0.001) –The learning rate for the optimizer. Default is 1e-3.
-
optimizer(str, default:'adam') –The optimization algorithm to be used for training. Default is "adam".
-
lower_limit(float | NDArray | None, default:None) –The lower limit for the input data. If provided, the input data will be clipped to this limit. Default is None.
-
restarts(int | None, default:None) –The number of times to restart the cosine annealing of the learning rate. If provided, the cosine annealing of the learning rate will be restarted the specified number of times. Default is None.
-
accum_grads(bool, default:False) –Whether to accumulate gradients over multiple batches. If True, gradients will be accumulated over multiple batches before updating the model parameters. Default is False.
Returns:
Notes
This method uses the Noise2Noise self-supervised approach to train the denoiser. The input data is used to generate target data based on the specified strategy. The training process involves creating pairs of input and target data and then training the model to minimize the difference between the predicted and target data.
Source code in src/autoden/algorithms/noise2noise.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
N2V
¶
N2V(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = None,
device: str = "cuda" if is_available() else "cpu",
batch_size: int | None = None,
augmentation: (
str
| Augmentation
| Sequence[str | Augmentation]
| None
) = None,
save_epochs_dir: str | None = None,
verbose: bool = True,
)
Bases: Denoiser
Self-supervised denoising from single images.
Parameters:
-
model(str | NetworkParams | Module | Mapping | None) –Type of neural network to use or a specific network (or state) to use
-
data_scale_bias(DataScaleBias | None, default:None) –Scale and bias of the input data, by default None
-
reg_val(float | None, default:None) –Regularization value, by default 1e-5
-
device(str, default:'cuda' if is_available() else 'cpu') –Device to use, by default "cuda" if cuda is available, otherwise "cpu"
-
save_epochs_dir(str | None, default:None) –Directory where to save network states at each epoch. If None disabled, by default None
-
verbose(bool, default:True) –Whether to produce verbose output, by default True
Methods:
-
infer–Inference, given an initial stack of images.
-
prepare_data–Prepare input data for training.
-
train–Self-supervised training.
Attributes:
-
n_channels_in(int) –Returns the number of input channels of the model.
-
n_channels_out(int) –Returns the number of output channels of the model.
-
n_dims(int) –Returns the expected signal dimensions.
Source code in src/autoden/algorithms/denoiser.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
n_channels_in
property
¶
n_channels_in: int
Returns the number of input channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_in", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of input channels.
n_channels_out
property
¶
n_channels_out: int
Returns the number of output channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_out", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of output channels.
n_dims
property
¶
n_dims: int
Returns the expected signal dimensions.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_dims", this property returns its value.
Otherwise, it defaults to 2.
Returns:
-
int–The expected signal dimensions.
infer
¶
infer(
inp: NDArray, channel_axis_dst: int | None = None
) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp(NDArray) –The input stack of images
-
channel_axis_dst(int | None, default:None) –The desired channel axis for the output. If None, the output will have the same channel axis as the input.
Returns:
-
NDArray–The denoised stack of images
Source code in src/autoden/algorithms/denoiser.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
prepare_data
¶
prepare_data(
inp: NDArray,
num_tst_ratio: float = 0.2,
channel_axis: int | None = None,
) -> tuple[NDArray, list[int]]
Prepare input data for training.
Parameters:
-
inp(NDArray) –The input data to be used for training. This should be a NumPy array of shape (N, H, W), where N is the number of samples, and H and W are the height and width of each sample, respectively.
-
num_tst_ratio(float, default:0.2) –The ratio of the input data to be used for testing. The remaining data will be used for training. Default is 0.2.
-
channel_axis(int | None, default:None) –The axis of the input array that corresponds to the spectral dimension. If None, the spectral dimension is assumed to not be present. Default is None.
Returns:
-
tuple[NDArray, NDArray, NDArray]–A tuple containing: - The input data array. - The mask array indicating the training pixels.
Notes
This function generates input-target pairs based on the specified strategy. It also generates a mask array indicating the training pixels based on the provided ratio.
Source code in src/autoden/algorithms/noise2void.py
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 | |
train
¶
train(
inp: NDArray,
tst_inds: Sequence[int] | NDArray,
*,
epochs: int,
mask_shape: int | Sequence[int] | NDArray = 1,
ratio_blind_spot: float = 0.015,
learning_rate: float = 0.001,
optimizer: str = "adam",
lower_limit: float | NDArray | None = None
) -> dict[str, NDArray]
Self-supervised training.
Parameters:
-
inp(NDArray) –The input images, which will also be targets
-
tst_inds(Sequence[int] | NDArray) –The validation set indices (indices if Sequence[int])
-
epochs(int) –Number of training epochs
-
mask_shape(int | Sequence[int] | NDArray, default:1) –Shape of the blind spot mask, by default 1.
-
ratio_blind_spot(float, default:0.015) –Ratio of the blind spot size to the total image size, by default 0.015.
-
learning_rate(float, default:0.001) –Learning rate for the optimizer, by default 1e-3.
-
optimizer(str, default:'adam') –Optimizer algorithm to use, by default "adam"
-
lower_limit(float | NDArray | None, default:None) –The lower limit for the input data. If provided, the input data will be clipped to this limit. Default is None.
Source code in src/autoden/algorithms/noise2void.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
Supervised
¶
Supervised(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = None,
device: str = "cuda" if is_available() else "cpu",
batch_size: int | None = None,
augmentation: (
str
| Augmentation
| Sequence[str | Augmentation]
| None
) = None,
save_epochs_dir: str | None = None,
verbose: bool = True,
)
Bases: Denoiser
Supervised denoising class.
Parameters:
-
model(str | NetworkParams | Module | Mapping | None) –Type of neural network to use or a specific network (or state) to use
-
data_scale_bias(DataScaleBias | None, default:None) –Scale and bias of the input data, by default None
-
reg_val(float | None, default:None) –Regularization value, by default 1e-5
-
device(str, default:'cuda' if is_available() else 'cpu') –Device to use, by default "cuda" if cuda is available, otherwise "cpu"
-
save_epochs_dir(str | None, default:None) –Directory where to save network states at each epoch. If None disabled, by default None
-
verbose(bool, default:True) –Whether to produce verbose output, by default True
Methods:
-
infer–Inference, given an initial stack of images.
-
prepare_data–Prepare input data for training.
-
train–Supervised training.
Attributes:
-
n_channels_in(int) –Returns the number of input channels of the model.
-
n_channels_out(int) –Returns the number of output channels of the model.
-
n_dims(int) –Returns the expected signal dimensions.
Source code in src/autoden/algorithms/denoiser.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
n_channels_in
property
¶
n_channels_in: int
Returns the number of input channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_in", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of input channels.
n_channels_out
property
¶
n_channels_out: int
Returns the number of output channels of the model.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_channels_out", this property returns its value.
Otherwise, it defaults to 1.
Returns:
-
int–The number of output channels.
n_dims
property
¶
n_dims: int
Returns the expected signal dimensions.
If the model is an instance of SerializableModel and has an init_params
attribute containing the key "n_dims", this property returns its value.
Otherwise, it defaults to 2.
Returns:
-
int–The expected signal dimensions.
infer
¶
infer(
inp: NDArray, channel_axis_dst: int | None = None
) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp(NDArray) –The input stack of images
-
channel_axis_dst(int | None, default:None) –The desired channel axis for the output. If None, the output will have the same channel axis as the input.
Returns:
-
NDArray–The denoised stack of images
Source code in src/autoden/algorithms/denoiser.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
prepare_data
¶
prepare_data(
inp: NDArray,
tgt: NDArray,
num_tst_ratio: float = 0.2,
strategy: Literal[
"pixel-mask", "self-similar"
] = "pixel-mask",
channel_axis: int | None = None,
) -> tuple[NDArray, NDArray, NDArray | list[int]]
Prepare input data for training.
Parameters:
-
inp(NDArray) –The input data to be used for training. This should be a NumPy array of shape (N, [D, H], W), where N is the number of samples, and D, H and W are the depth, height and width of each sample, respectively.
-
tgt(NDArray) –The target data to be used for training. This should be a NumPy array of shape (N, [D, H], W), where N is the number of samples, and D, H and W are the depth, height and width of each sample, respectively.
-
num_tst_ratio(float, default:0.2) –The ratio of the input data to be used for testing. The remaining data will be used for training. Default is 0.2.
-
strategy(str, default:'pixel-mask') –The strategy to be used for creating training and testing sets. The available strategies are: - "pixel-mask": Use randomly chosen pixels in the images as test set. - "self-similar": Use entire randomly chosen images as test set. Default is "pixel-mask".
-
channel_axis(int | None, default:None) –The axis of the target array that corresponds to the spectral dimension. If None, the spectral dimension is assumed to not be present. Default is None.
Returns:
-
tuple[NDArray, NDArray, NDArray]–A tuple containing: - The input data array. - The target data array. - Either the mask array indicating the testing pixels or the list of test indices.
Source code in src/autoden/algorithms/supervised.py
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 | |
train
¶
train(
inp: NDArray,
tgt: NDArray,
tst_inds: Sequence[int] | NDArray,
*,
epochs: int,
learning_rate: float = 0.001,
optimizer: str = "adam",
lower_limit: float | NDArray | None = None,
restarts: int | None = None,
accum_grads: bool = False
) -> dict[str, NDArray]
Supervised training.
Parameters:
-
inp(NDArray) –The input images
-
tgt(NDArray) –The target images
-
tst_inds(Sequence[int] | NDArray) –The validation set indices (either image indices if Sequence[int] or pixel indices if NDArray)
-
epochs(int) –Number of training epochs
-
learning_rate(float, default:0.001) –The learning rate for the optimizer. Default is 1e-3.
-
optimizer(str, default:'adam') –The optimization algorithm to be used for training. Default is "adam".
-
lower_limit(float | NDArray | None, default:None) –The lower limit for the input data. If provided, the input data will be clipped to this limit. Default is None.
-
restarts(int | None, default:None) –The number of times to restart the cosine annealing of the learning rate. If provided, the cosine annealing of the learning rate will be restarted the specified number of times. Default is None.
-
accum_grads(bool, default:False) –Whether to accumulate gradients over multiple batches. If True, gradients will be accumulated over multiple batches before updating the model parameters. Default is False.
Returns:
-
dict[str, NDArray]–A dictionary containing the training history, including the loss and validation loss over the epochs.
Source code in src/autoden/algorithms/supervised.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |