Utils
default(val, d)
Return the input value if it exists, otherwise return a default value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Any
|
Input value. |
required |
d |
Any
|
Default value or function to generate the default value. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
Input value if it exists, otherwise the default value. |
Source code in models/enhancer/gaussian_diffusion/utils.py
exists(x)
Check if the input variable is not None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Any
|
Input variable. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the input variable is not None, False otherwise. |
extract(a, t, x_shape)
Extract elements from tensor 'a' using indices 't'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
Tensor
|
Input tensor. |
required |
t |
Tensor
|
Indices tensor. |
required |
x_shape |
Size
|
Shape of the input tensor 'a'. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor: Extracted elements tensor. |
Source code in models/enhancer/gaussian_diffusion/utils.py
get_noise_schedule_list(schedule_mode, timesteps, min_beta=0.0, max_beta=0.01, s=0.008)
Generate a noise schedule list based on the specified mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schedule_mode |
str
|
Mode for generating the noise schedule. Can be one of ["linear", "cosine", "vpsde"]. |
required |
timesteps |
int
|
Total number of time steps. |
required |
min_beta |
float
|
Minimum value of beta for VPSDE mode. Defaults to 0.0. |
0.0
|
max_beta |
float
|
Maximum value of beta for VPSDE mode. Defaults to 0.01. |
0.01
|
s |
float
|
Parameter for cosine schedule mode. Defaults to 0.008. |
0.008
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: List or array of beta coefficients for each time step. |
Source code in models/enhancer/gaussian_diffusion/utils.py
noise_like(shape, device, repeat=False)
Generate random noise tensor with the given shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape |
Size
|
Shape of the noise tensor. |
required |
device |
device
|
Device for the tensor. |
required |
repeat |
bool
|
If True, repeat the noise tensor to match the given shape. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
torch.Tensor: Random noise tensor. |
Source code in models/enhancer/gaussian_diffusion/utils.py
vpsde_beta_t(t, T, min_beta, max_beta)
Calculate beta coefficient for VPSDE noise schedule at time step t.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
int
|
Current time step. |
required |
T |
int
|
Total number of time steps. |
required |
min_beta |
float
|
Minimum value of beta. |
required |
max_beta |
float
|
Maximum value of beta. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Beta coefficient at time step t. |