-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdisplay_result.py
76 lines (55 loc) · 1.72 KB
/
display_result.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
66
67
68
69
70
71
72
73
74
75
import os
import numpy as np
import torch
import torchvision.utils as vutils
import matplotlib.pyplot as plt
## celeba: Black_Hair | Blond_Hair | Brown_Hair | Male | Young
dir_result = './results/stargan/celeba/images'
# dir_result = './results/stargan/rafd/images'
lst_result = os.listdir(dir_result)
nx = 128
ny = 128
nch = 3
n = 8
m = 1 + 5
# m = 1 + 8
n_id = np.arange(len(lst_result)//m)
np.random.shuffle(n_id)
img = torch.zeros((n*m, ny, nx, nch))
for i in range(m):
for j in range(n):
p = i + m*n_id[j]
q = n * i + j
img[q, :, :, :] = torch.from_numpy(plt.imread(os.path.join(dir_result, lst_result[p]))[:, :, :nch])
img = img.permute((0, 3, 1, 2))
plt.figure(figsize=(n, m))
plt.axis("off")
# plt.title("Generated Images")
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
plt.imshow(np.transpose(vutils.make_grid(img, padding=2, normalize=True), (1, 2, 0)))
plt.show()
## RaFD: angry | contemptuous | disgusted | fearful | happy | neutral | sad | surprised
# dir_result = './results/stargan/celeba/images'
dir_result = './results/stargan/rafd/images'
lst_result = os.listdir(dir_result)
nx = 128
ny = 128
nch = 3
n = 8
# m = 1 + 5
m = 1 + 8
n_id = np.arange(len(lst_result)//m)
np.random.shuffle(n_id)
img = torch.zeros((n*m, ny, nx, nch))
for i in range(m):
for j in range(n):
p = i + m*n_id[j]
q = n * i + j
img[q, :, :, :] = torch.from_numpy(plt.imread(os.path.join(dir_result, lst_result[p]))[:, :, :nch])
img = img.permute((0, 3, 1, 2))
plt.figure(figsize=(n, m))
plt.axis("off")
# plt.title("Generated Images")
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
plt.imshow(np.transpose(vutils.make_grid(img, padding=2, normalize=True), (1, 2, 0)))
plt.show()