-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_graph.py
124 lines (116 loc) · 4.35 KB
/
make_graph.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import numpy as np
import matplotlib.pyplot as plt
from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go
def generate_reconstructions(reconstructions, images=None, input=None):
reconstructions = reconstructions.view(reconstructions.shape[0], 1, 28, 28)
reconstructions = reconstructions.detach().numpy()
reconstructions = reconstructions * 255.
if images is not None:
images = images * 255.
if type(input) == int:
rows = 5
columns = 4
fig, axs = plt.subplots(rows, columns)
r_sample = 0
i_sample = 0
for i in range(0, rows):
for j in range(0, columns):
if(j % 2 == 0):
axs[i,j].imshow(images[i_sample, 0, :, :], cmap="gray")
axs[i,j].axis("off")
i_sample = i_sample + 1
else:
axs[i,j].imshow(reconstructions[r_sample, 0, :, :], cmap="gray")
axs[i,j].axis("off")
r_sample = r_sample + 1
fig.savefig("Reconstructions for Epoch "+str(input)+".png")
plt.show()
plt.close()
elif type(input) == str:
rows = 5
columns = 5
for count in range(0, 2):
fig, axs = plt.subplots(rows, columns)
r_sample = 0
i_sample = 0
for i in range(0, rows):
for j in range(0, columns):
if(count == 0):
# Ground Truth
axs[i,j].imshow(images[i_sample, 0, :, :], cmap="gray")
axs[i,j].axis("off")
i_sample = i_sample + 1
title = "Ground_Truth_Images"
else:
# Reconstructions
axs[i,j].imshow(reconstructions[r_sample, 0, :, :], cmap="gray")
axs[i,j].axis("off")
r_sample = r_sample + 1
title = "Reconstructed_Images"
fig.savefig(title + ".png")
plt.show()
plt.close()
elif input is None:
dim = 16
rows = 2
columns = 5
count = -1
for dimension in range(0, dim):
count += 1
dim_sample = count
fig, axs = plt.subplots(rows, columns)
for i in range(0, rows):
for j in range(0, columns):
axs[i,j].imshow(reconstructions[dim_sample, 0, :, :], cmap="gray")
axs[i,j].axis("off")
dim_sample = dim_sample + 11
fig.savefig("Pose_Reconstructions_for_dimension_"+str(dimension+1)+".png")
plt.show()
plt.close()
return
def plot_graph(test_accuracy):
py.sign_in('VikramShenoy','x1Un4yD3HDRT838vRkFA')
training_accuracy = []
history = np.load("history.npy", allow_pickle=True)
training_loss = history.item().get('train_loss')
train_accuracy = history.item().get('train_accuracy')
epochs = list(range(1, len(training_loss)+1))
for i in range(0, len(train_accuracy)):
training_accuracy.append(train_accuracy[i].item()/100)
testing_accuracy = 98.84#test_accuracy
trace0 = go.Scatter(
x = epochs,
y = training_accuracy,
mode = "lines",
name = "Training Accuracy"
)
trace1 = go.Scatter(
x = epochs,
y = training_loss,
mode = "lines",
name = "Training Loss"
)
data = go.Data([trace0, trace1])
layout = go.Layout()
fig = go.Figure(data=data, layout=layout)
fig['layout']['xaxis'].update(title="Number of Epochs", range = [min(epochs), max(epochs)], dtick=len(epochs)/10, showline = True, zeroline=True, mirror='ticks', linecolor='#636363', linewidth=2)
fig['layout']['yaxis'].update(title="Training Loss and Accuracy", range = [0, 1.05], dtick=0.1, showline = True, zeroline=True, mirror='ticks',linecolor='#636363',linewidth=2)
py.image.save_as(fig, filename="Training_Graph.png")
print "Training Graph Created"
x_axis = ["Training", "Testing"]
y_axis = [training_accuracy[-1]*100, testing_accuracy]
trace2 = go.Bar(
x = x_axis,
y = y_axis,
width = [0.3, 0.3]
)
data = [trace2]
layout = go.Layout()
fig = go.Figure(data=data, layout=layout)
fig['layout']['xaxis'].update(title="Mode", showline = True)
fig['layout']['yaxis'].update(title="Accuracy")
py.image.save_as(fig, filename="Accuracy_Graph.png")
print "Accuracy Graph Created"
return