-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdisplay_result.py
62 lines (45 loc) · 1.46 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
import os
import numpy as np
import torch
import torchvision.utils as vutils
import matplotlib.pyplot as plt
dir_result = './results/cyclegan/monet2photo/images'
lst_result = os.listdir(dir_result)
nx = 256
ny = 256
nch = 3
n = 8
m = 6
m_id = [0, 3, 1, 2]
n_id = np.arange(len(lst_result)//m)
np.random.shuffle(n_id)
## From domain A to domain B
img = torch.zeros((n*(m-4), ny, nx, nch))
for i in range(m-4):
for j in range(n):
p = m_id[i + 0] + m * n_id[j]
# p = m_id[i + 2] + 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-4)))
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()
## From domain B to domain A
img = torch.zeros((n*(m-4), ny, nx, nch))
for i in range(m-4):
for j in range(n):
# p = m_id[i + 0] + m * n_id[j]
p = m_id[i + 2] + 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-4)))
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()