-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_utils.py
85 lines (81 loc) · 2.55 KB
/
plot_utils.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
76
77
78
79
80
81
82
83
84
85
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torchvision
width = 64 #output[0][0].shape[0]
height = 64 #output[0][0].shape[1]
def save_frame(output, filename):
x1 = output[0][0].view(1, width, height)
x1 = x1.permute(1, 2, 0)
x1 = x1.cpu()
x1 = x1.detach().numpy()
plt.figure(1)
plt.axis("off")
plt.clf()
plt.title('output')
plt.imshow(x1, cmap="gray")
#plt.pause(1)
#plt.draw()
plt.savefig(filename)
plt.close()
def save_sequences(data, video, output, filename):
figure = plt.figure(figsize=(7, 7))
figure.add_subplot(2, 4, 1)
frame0 = data[0][[video]].view(1, width, height)
frame0 = frame0.permute(1, 2, 0)
frame0 = frame0.cpu()
frame0 = frame0.detach().numpy()
plt.axis("off")
plt.imshow(frame0, cmap="gray")
figure.add_subplot(2, 4, 2)
frame1 = data[5][video].view(1,width,height)
frame1 = frame1.permute(1, 2, 0)
frame1 = frame1.cpu()
frame1 = frame1.detach().numpy()
plt.axis("off")
plt.imshow(frame1, cmap="gray")
figure.add_subplot(2, 4, 3)
frame2 = data[10][video].view(1,width,height)
frame2 = frame2.permute(1, 2, 0)
frame2 = frame2.cpu()
frame2 = frame2.detach().numpy()
plt.axis("off")
plt.imshow(frame2, cmap="gray")
figure.add_subplot(2, 4, 4)
frame3 = data[19][video].view(1,width,height)
frame3 = frame3.permute(1, 2, 0)
frame3 = frame3.cpu()
frame3 = frame3.detach().numpy()
plt.axis("off")
plt.imshow(frame3, cmap="gray")
#first row with original samples done, now output
figure.add_subplot(2, 4, 5)
frame4 = output[0][video].view(1, width, height)
frame4 = frame4.permute(1, 2, 0)
frame4 = frame4.cpu()
frame4 = frame4.detach().numpy()
plt.axis("off")
plt.imshow(frame4, cmap="gray")
figure.add_subplot(2, 4, 6)
frame5 = output[5][video].view(1, width, height)
frame5 = frame5.permute(1, 2, 0)
frame5 = frame5.cpu()
frame5 = frame5.detach().numpy()
plt.axis("off")
plt.imshow(frame5, cmap="gray")
figure.add_subplot(2, 4, 7)
frame6 = output[10][video].view(1, width, height)
frame6 = frame6.permute(1, 2, 0)
frame6 = frame6.cpu()
frame6 = frame6.detach().numpy()
plt.axis("off")
plt.imshow(frame6, cmap="gray")
figure.add_subplot(2, 4, 8)
frame7 = output[19][video].view(1, width, height)
frame7 = frame7.permute(1, 2, 0)
frame7 = frame7.cpu()
frame7 = frame7.detach().numpy()
plt.axis("off")
plt.imshow(frame7, cmap="gray")
plt.savefig(filename)
plt.close()