Noise#
- class vision_architectures.schedulers.noise.NoiseScheduler(betas=None, alpha_bars=None)[source]#
Bases:
Module
Base class for Gussian noise schedulers used in diffusion models
- __init__(betas=None, alpha_bars=None)[source]#
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- add_noise(x0, t, noise=None)[source]#
If noise is not provided, it is sampled from a standard normal distribution
- remove_noise(xt, t, model_output, model_output_type='noise', prev_t_offset=1, eta=1.0, x_limits=(-5.0, 5.0), eps=1e-09)[source]#
Removes noise from the input tensor xt using the predicted noise and the time step t. Equation 12 from the DDIM paper.
- Parameters:
xt (
Tensor
) – The input tensor with noise.t (
Tensor
) – The time step tensor.model_output (
Tensor
) – The predicted noise / sample / velocity tensor.model_output_type (
Literal
['noise'
,'sample'
,'velocity'
]) – The type of model output.prev_t_offset (
int
) – The offset to derive the previous time step. Use 1 for DDPM.eta (
float
) – The eta parameter for DDIM sampling. Setting it to 1.0 is equivalent to DDPM sampling, while setting it to 0.0 is equivalent to DDIM sampling. Use values in between for an interpolation between the two.x_limits (
tuple
[float
,float
]) – Clamp the x0_hat and xt_miuns_1 values to this range to avoid numerical instability.eps (
float
) – A small value to avoid division by zero.
- Returns:
The estimated clean image tensor. xt_minus_1_hat: The estimated previous noisy image tensor. Note that while this notation follows literature,
(t-1) need to actually mean the previous timestep, it is actually (t-prev_t_offset).
- Return type:
x0_hat
- get_velocity(x0, t, noise)[source]#
Computes the velocity of the diffusion process at time step t.
- Parameters:
x0 (
Tensor
) – The input tensor (clean image).t (
Tensor
) – The time step tensor.noise (
Tensor
) – The noise tensor.
- Returns:
The estimated velocity tensor.
- Return type:
velocity
- get_alpha_bars(t=None)[source]#
Returns the cumulative product of alpha values for the given timesteps t.
- get_sqrt_alpha_bars(t=None)[source]#
Returns the square root of the cumulative product of alpha values for the given timesteps t.
- get_sqrt_one_minus_alpha_bars(t=None)[source]#
Returns the square root of one minus the cumulative product of alpha values for the given timesteps t.
- class vision_architectures.schedulers.noise.LinearNoiseScheduler(T, min_beta=0.0001, max_beta=0.02)[source]#
Bases:
NoiseScheduler
- class vision_architectures.schedulers.noise.CosineNoiseScheduler(T, s=0.008, min_alpha_bars=1e-09)[source]#
Bases:
NoiseScheduler
- class vision_architectures.schedulers.noise.SigmoidNoiseScheduler(T, tau=1.0, sigmoid_start=-3, sigmoid_end=3, min_alpha_bars=1e-09)[source]#
Bases:
NoiseScheduler
- class vision_architectures.schedulers.noise.FibonacciNoiseScheduler(T, first_element=1e-06, second_element=2e-06)[source]#
Bases:
NoiseScheduler
- class vision_architectures.schedulers.noise.ExponentialNoiseScheduler(T, beta_min=0.0001, beta_max=0.02)[source]#
Bases:
NoiseScheduler
- class vision_architectures.schedulers.noise.SquareRootNoiseScheduler(T, s=0.008, min_alpha_bars=1e-09)[source]#
Bases:
NoiseScheduler