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
21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
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. |
Source code in models/enhancer/gaussian_diffusion/utils.py
9 10 11 12 13 14 15 16 17 18 |
|
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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
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
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 |
|
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
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. |
Source code in models/enhancer/gaussian_diffusion/utils.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|