algorithms
¶
Implementation of various unsupervised and self-supervised denoising methods.
Classes:
-
DIP
–Deep image prior.
-
DataScaleBias
–Data scale and bias.
-
Denoiser
–Denoising images.
-
N2N
–Self-supervised denoising from pairs of images.
-
N2V
–Self-supervised denoising from single images.
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.
DIP
¶
DIP(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = 1e-05,
device: str = "cuda" if is_available() else "cpu",
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:1e-05
) –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_supervised
–Supervised training.
-
train_unsupervised
–Train the model in an unsupervised manner.
Source code in src/autoden/algorithms.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
infer
¶
infer(inp: NDArray) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp
(NDArray
) –The input stack of images
Returns:
-
NDArray
–The denoised stack of images
Source code in src/autoden/algorithms.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
train_supervised
¶
train_supervised(
inp: NDArray,
tgt: NDArray,
epochs: int,
tst_inds: Sequence[int] | NDArray,
algo: str = "adam",
)
Supervised training.
Parameters:
-
inp
(NDArray
) –The input images
-
tgt
(NDArray
) –The target images
-
epochs
(int
) –Number of training epochs
-
tst_inds
(Sequence[int] | NDArray
) –The validation set indices
-
algo
(str
, default:'adam'
) –Learning algorithm to use, by default "adam"
Source code in src/autoden/algorithms.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
train_unsupervised
¶
train_unsupervised(
tgt: NDArray,
epochs: int,
inp: NDArray | None = None,
num_tst_ratio: float = 0.2,
algo: str = "adam",
) -> NDArray
Train the model in an unsupervised manner.
Parameters:
-
tgt
(NDArray
) –The target image to be denoised.
-
epochs
(int
) –The number of training epochs.
-
inp
(NDArray | None
, default:None
) –The input image. If None, a random image 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.
-
algo
(str
, default:'adam'
) –The optimization algorithm to use. Default is "adam".
Returns:
-
NDArray
–The denoised input image.
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 splits the data into training and test sets based on the provided ratio and trains the model using the specified optimization algorithm.
Source code in src/autoden/algorithms.py
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
|
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 = 1e-05,
device: str = "cuda" if is_available() else "cpu",
save_epochs_dir: str | None = None,
verbose: bool = True,
)
Denoising 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:1e-05
) –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_supervised
–Supervised training.
Source code in src/autoden/algorithms.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
infer
¶
infer(inp: NDArray) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp
(NDArray
) –The input stack of images
Returns:
-
NDArray
–The denoised stack of images
Source code in src/autoden/algorithms.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
train_supervised
¶
train_supervised(
inp: NDArray,
tgt: NDArray,
epochs: int,
tst_inds: Sequence[int] | NDArray,
algo: str = "adam",
)
Supervised training.
Parameters:
-
inp
(NDArray
) –The input images
-
tgt
(NDArray
) –The target images
-
epochs
(int
) –Number of training epochs
-
tst_inds
(Sequence[int] | NDArray
) –The validation set indices
-
algo
(str
, default:'adam'
) –Learning algorithm to use, by default "adam"
Source code in src/autoden/algorithms.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
N2N
¶
N2N(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = 1e-05,
device: str = "cuda" if is_available() else "cpu",
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:1e-05
) –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_selfsupervised
–Train the denoiser using the Noise2Noise self-supervised approach.
-
train_supervised
–Supervised training.
Source code in src/autoden/algorithms.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
infer
¶
infer(inp: NDArray) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp
(NDArray
) –The input stack of images
Returns:
-
NDArray
–The denoised stack of images
Source code in src/autoden/algorithms.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
train_selfsupervised
¶
train_selfsupervised(
inp: NDArray,
epochs: int,
num_tst_ratio: float = 0.2,
strategy: str = "1:X",
algo: str = "adam",
lower_limit: float | NDArray | None = None,
) -> None
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.
-
epochs
(int
) –The number of epochs to train the model.
-
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".
-
algo
(str
, default:'adam'
) –The optimization algorithm to be used for training. The available algorithms are: - "adam": Adam optimizer. 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.
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.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
train_supervised
¶
train_supervised(
inp: NDArray,
tgt: NDArray,
epochs: int,
tst_inds: Sequence[int] | NDArray,
algo: str = "adam",
)
Supervised training.
Parameters:
-
inp
(NDArray
) –The input images
-
tgt
(NDArray
) –The target images
-
epochs
(int
) –Number of training epochs
-
tst_inds
(Sequence[int] | NDArray
) –The validation set indices
-
algo
(str
, default:'adam'
) –Learning algorithm to use, by default "adam"
Source code in src/autoden/algorithms.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
N2V
¶
N2V(
model: int | str | NetworkParams | Module | Mapping,
data_scale_bias: DataScaleBias | None = None,
reg_val: float | LossRegularizer | None = 1e-05,
device: str = "cuda" if is_available() else "cpu",
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:1e-05
) –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_selfsupervised
–Self-supervised training.
-
train_supervised
–Supervised training.
Source code in src/autoden/algorithms.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
infer
¶
infer(inp: NDArray) -> NDArray
Inference, given an initial stack of images.
Parameters:
-
inp
(NDArray
) –The input stack of images
Returns:
-
NDArray
–The denoised stack of images
Source code in src/autoden/algorithms.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
train_selfsupervised
¶
train_selfsupervised(
inp: NDArray,
epochs: int,
tst_inds: Sequence[int] | NDArray,
mask_shape: int | Sequence[int] | NDArray = 1,
ratio_blind_spot: float = 0.015,
algo: str = "adam",
)
Self-supervised training.
Parameters:
-
inp
(NDArray
) –The input images, which will also be targets
-
epochs
(int
) –Number of training epochs
-
tst_inds
(Sequence[int] | NDArray
) –The validation set indices
-
mask_shape
(int | Sequence[int] | NDArray
, default:1
) –Shape of the blind spot mask, by default 1.
-
algo
(str
, default:'adam'
) –Learning algorithm to use, by default "adam"
Source code in src/autoden/algorithms.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
|
train_supervised
¶
train_supervised(
inp: NDArray,
tgt: NDArray,
epochs: int,
tst_inds: Sequence[int] | NDArray,
algo: str = "adam",
)
Supervised training.
Parameters:
-
inp
(NDArray
) –The input images
-
tgt
(NDArray
) –The target images
-
epochs
(int
) –Number of training epochs
-
tst_inds
(Sequence[int] | NDArray
) –The validation set indices
-
algo
(str
, default:'adam'
) –Learning algorithm to use, by default "adam"
Source code in src/autoden/algorithms.py
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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
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.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 |
|
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.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 |
|