forked from uuembodiedsocialai/FaceDiffuser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
67 lines (56 loc) · 1.97 KB
/
utils.py
File metadata and controls
67 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
59
60
61
62
63
64
65
66
67
import matplotlib.pyplot as plt
import pickle
from diffusion import gaussian_diffusion as gd
from diffusion.respace import SpacedDiffusion, space_timesteps
with open('data/damm_rig_equal/scaler_192.pkl', 'rb') as f:
RIG_SCALER = pickle.load(f)
def plot_losses(train_losses, val_losses, save_name="losses"):
#print(train_losses)
#print(val_losses)
plt.plot(train_losses, label="Training loss",marker='o')
plt.legend()
plt.title("Training loss")
plt.savefig(f"{save_name}_train.png")
plt.close()
plt.plot(val_losses, label="Validation loss",marker='o')
plt.legend()
plt.title("Validation loss")
plt.savefig(f"{save_name}_val.png")
plt.close()
plt.plot(val_losses, label="Validation loss",marker='o')
plt.plot(train_losses, label="Training loss",marker='o')
plt.legend()
plt.title("Combined loss")
plt.savefig(f"{save_name}_val_loss.png")
plt.close()
def create_gaussian_diffusion(args):
# default params
sigma_small = True
predict_xstart = False # we always predict x_start (a.k.a. x0), that's our deal!
steps = args.diff_steps
scale_beta = 1. # no scaling
timestep_respacing = '' # can be used for ddim sampling, we don't use it.
learn_sigma = False
rescale_timesteps = False
betas = gd.get_named_beta_schedule(args.beta_type, steps, scale_beta)
loss_type = gd.LossType.MSE
if not timestep_respacing:
timestep_respacing = [steps]
return SpacedDiffusion(
use_timesteps=space_timesteps(steps, timestep_respacing),
betas=betas,
model_mean_type=(
gd.ModelMeanType.START_X
),
model_var_type=(
(
gd.ModelVarType.FIXED_LARGE
if not sigma_small
else gd.ModelVarType.FIXED_SMALL
)
if not learn_sigma
else gd.ModelVarType.LEARNED_RANGE
),
loss_type=loss_type,
rescale_timesteps=rescale_timesteps,
)