-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpolate.py
46 lines (30 loc) · 1.03 KB
/
interpolate.py
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
import argparse
import os
import torch
from torch import nn
from torchvision import utils
from gan import Generator
from helper import get_truncated_noise
# Just a simple script to create a video of shifting images
if __name__ == "__main__":
gen = nn.DataParallel(Generator().to('cuda'))
save = torch.load('./chk-116000.pth')
gen.load_state_dict(save["gen"])
steps = save["step"]
alpha = save["alpha"]
z = get_truncated_noise(60, 512, 0.7)
noise = []
for i in range(8):
size = 4 * 2 ** i
noise.append(torch.randn(1, 1, size, size, device='cuda'))
e = 0
for i in range(59):
start = z[i].unsqueeze(0)
end = z[i + 1].unsqueeze(0)
for psi in range(61):
interpolation = torch.lerp(start, end, float(psi / 60))
utils.save_image(
gen.forward(interpolation, noise=noise, steps=steps, alpha=alpha),
os.path.join('./output', f"image_{e + 1}.png"),
)
e += 1