-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
65 lines (58 loc) · 2.01 KB
/
test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import matplotlib
import matplotlib.pyplot as plt
from torchsummaryX import summary
import pylab
from stylegan2 import utils
import numpy as np
import torch
import stylegan2
import pickle
import os
# matplotlib.use('TkAgg')
if __name__ == "__main__":
# path to model code and weight
plt.ion()
path_model = './Gs.pth'
device = torch.device('cpu')
latens = torch.randn([3, 512])
G = stylegan2.models.load(path_model)
assert isinstance(G, stylegan2.models.Generator), 'Model type has to be ' + \
'stylegan2.models.Generator. Found {}.'.format(type(G))
G.to(device)
latent_size, label_size = G.latent_size, G.label_size
summary(G, torch.zeros(1, 13, 512))
# for parameters in G.parameters():
# print(parameters)
# for name, parameters in G.named_parameters():
# print(name, ':', parameters.size())
# a = G.G_mapping(latens)
##
# # Generate random latent variables
# latents_ = []
# rnd = np.random.RandomState(seed=6600)
# latents_.append(torch.from_numpy(rnd.randn(latent_size)))
# #latents = torch.from_numpy(np.random.randn(1, latent_size)).to(device=device, dtype=torch.float32)
# # Generate dummy labels
# latents = torch.stack(latents_, dim=0).to(device=device, dtype=torch.float32)
# labels = None
#
#
# def gen_image(latents):
# """
# tool funciton to generate image from latent variables
# :param latents: latent variables
# :return:
# """
# with torch.no_grad():
# images = G(latents, labels=labels)
# return np.clip((images[0].permute(1,2,0).numpy() + 1.0)/2.0, a_min=0.0, a_max=1.0)
#
#
# img_cur = gen_image(latents)
# # """ plot figure with GUI """
# h_fig = plt.figure(figsize=[30, 30])
# h_ax = plt.axes([0.0, 0.0, 0.5, 1.0])
# h_ax.axis('off')
# h_img = plt.imshow(img_cur)
# plt.show()
print()