denoiser
¶
Base class and functions for all denoising algorithms.
@author: Nicola VIGANÒ, CEA-MEM, Grenoble, France
Classes:
-
DataScaleBias–Data scale and bias.
-
Denoiser–Base denoising class.
Functions:
-
compute_scaling_selfsupervised–Compute input data scaling and bias for self-supervised learning.
-
compute_scaling_supervised–Compute input and target data scaling and bias for supervised learning.
-
get_normalization_range–Calculate the normalization range for a given volume.
-
get_random_image_indices–Return a list of random indices from 0 to num_imgs - 1.
-
get_random_pixel_mask–Generate a random pixel mask for a given data shape.
DataScaleBias
dataclass
¶
DataScaleBias(
scale_inp: float | NDArray = 1.0,
scale_out: float | NDArray = 1.0,
scale_tgt: float | NDArray = 1.0,
bias_inp: float | NDArray = 0.0,
bias_out: float | NDArray = 0.0,
bias_tgt: float | NDArray = 0.0,
)
Data scale and bias.
Denoiser
¶
Denoiser(
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: ABC
Base 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.
-
train–Training of the model, given the required input.
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 | |
train
abstractmethod
¶
Training of the model, given the required input.
Source code in src/autoden/algorithms/denoiser.py
435 436 437 | |
compute_scaling_selfsupervised
¶
compute_scaling_selfsupervised(
inp: NDArray,
) -> DataScaleBias
Compute input data scaling and bias for self-supervised learning.
Parameters:
-
inp(NDArray) –Input data.
Returns:
-
DataScaleBias–An instance of DataScaleBias containing the computed scaling and bias values.
Source code in src/autoden/algorithms/denoiser.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
compute_scaling_supervised
¶
compute_scaling_supervised(
inp: NDArray, tgt: NDArray
) -> DataScaleBias
Compute input and target data scaling and bias for supervised learning.
Parameters:
-
inp(NDArray) –Input data.
-
tgt(NDArray) –Target data.
Returns:
-
DataScaleBias–An instance of DataScaleBias containing the computed scaling and bias values.
Source code in src/autoden/algorithms/denoiser.py
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 | |
get_normalization_range
¶
get_normalization_range(
vol: NDArray, percentile: float | None = None
) -> tuple[float, float, float]
Calculate the normalization range for a given volume.
Parameters:
-
vol(NDArray) –The input volume as a NumPy array.
-
percentile(float, default:None) –The percentile to use for calculating the normalization range. If None, the minimum, maximum, and mean of the entire volume are used. Default is None.
Returns:
-
tuple[float, float, float]–A tuple containing the minimum, maximum, and mean values of the volume within the specified percentile range. If
percentileis None, the minimum, maximum, and mean of the entire volume are returned.
Notes
If percentile is provided, the function calculates the indices for the minimum
and maximum values based on the specified percentile. The mean value is then
calculated from the range between these indices.
Source code in src/autoden/algorithms/denoiser.py
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 | |
get_random_image_indices
¶
Return a list of random indices from 0 to num_imgs - 1.
Parameters:
Returns:
-
list–List of random indices.
Source code in src/autoden/algorithms/denoiser.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_random_pixel_mask
¶
Generate a random pixel mask for a given data shape.
This function creates a mask where a specified ratio of pixels are set to True, effectively masking those pixels. The remaining pixels are set to True.
Parameters:
-
data_shape(Sequence[int] | NDArray) –The shape of the data array for which the mask is to be generated.
-
mask_pixel_ratio(float) –The ratio of pixels to be masked (set to True). Must be between 0 and 1.
Returns:
-
NDArray–A boolean array of the same shape as
data_shapewith the specified ratio of pixels set to True.
Examples:
>>> data_shape = (10, 10)
>>> mask_pixel_ratio = 0.1
>>> mask = get_random_pixel_mask(data_shape, mask_pixel_ratio)
>>> print(mask)
Source code in src/autoden/algorithms/denoiser.py
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 | |