-
Notifications
You must be signed in to change notification settings - Fork 11
/
gan_loss_vis.py
162 lines (134 loc) · 6.94 KB
/
gan_loss_vis.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.lines import Line2D
# loss_file = open('/Users/markus/workspace/master/Master/GAN/GAN_log/2017-04-26_ImgCapFalse_WordEmbedding.WORD2VEC_Vocab1000_Seq10_Batch128_EmbSize50_NoiseMode.REPEAT_Noise50_PreInitPreInit.NONE_Dataset_all_flowers_500hidden_dropout0.2/loss.txt', 'r')
# loss_fix_file = open('/Users/markus/workspace/master/Master/GAN/GAN_log/2017-04-26_ImgCapFalse_WordEmbedding.WORD2VEC_Vocab1000_Seq10_Batch128_EmbSize50_NoiseMode.REPEAT_Noise50_PreInitPreInit.NONE_Dataset_all_flowers_500hidden_dropout0.2/loss-fix.txt', 'w+')
# loss_lines = loss_file.readlines()
# loss_fix_file.writelines(loss_lines[1::2])
# loss_file.close()
# loss_fix_file.close()
log_folder = 'GAN/GAN_log/'
# model_1 = '2017-05-16_ImgCapFalse_word2vec_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers_0.75dropout'
model_1 = '2017-05-16_ImgCapFalse_word2vec_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers_0.25dropout'
# model_2 = '2017-05-13_ImgCapFalse_onehot_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers'
# model_3 = '2017-05-13_ImgCapFalse_onehot_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers'
# model_4 = '2017-05-13_ImgCapFalse_onehot_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers'
# model_2 = '2017-05-13_ImgCapFalse_onehot_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers_0.75dropout'
# model_3 = '2017-05-13_ImgCapFalse_onehot_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers_softmax'
# model_4 = '2017-05-13_ImgCapFalse_onehot_Vocab1000_Seq12_Batch64_EmbSize50_repeat_Noise50_PreInitNone_Dataset_10_all_flowers_0.75dropout-softmax'
data_1 = np.genfromtxt(
log_folder + model_1 + "/loss.txt",
delimiter=',',
skip_header=1,
skip_footer=0,
names=['epoch', 'batch', 'g_loss', 'g_acc', 'd_loss_gen', 'd_acc_gen', 'd_loss_train', 'd_acc_train'])
# data_2 = np.genfromtxt(
# log_folder + model_2 + "/loss.txt",
# delimiter=',',
# skip_header=1,
# skip_footer=20,
# names=['epoch', 'batch', 'g_loss', 'g_acc', 'd_loss_gen', 'd_acc_gen', 'd_loss_train', 'd_acc_train'])
#
# data_3 = np.genfromtxt(
# log_folder + model_3 + "/loss.txt",
# delimiter=',',
# skip_header=1,
# skip_footer=20,
# names=['epoch', 'batch', 'g_loss', 'g_acc', 'd_loss_gen', 'd_acc_gen', 'd_loss_train', 'd_acc_train'])
#
# data_4 = np.genfromtxt(
# log_folder + model_4 + "/loss.txt",
# delimiter=',',
# skip_header=1,
# skip_footer=20,
# names=['epoch', 'batch', 'g_loss', 'g_acc', 'd_loss_gen', 'd_acc_gen', 'd_loss_train', 'd_acc_train'])
fig = plt.figure()
plt.rc('font', family='Arial')
diagram = fig.add_subplot(111)
d_loss_train_1 = data_1["d_loss_train"]
d_loss_gen_1 = data_1["d_loss_gen"]
d_loss_1 = (d_loss_gen_1 + d_loss_train_1) / 2
# d_loss_train_2 = data_2["d_loss_train"]
# d_loss_gen_2 = data_2["d_loss_gen"]
# d_loss_2 = (d_loss_gen_2 + d_loss_train_2) / 2
#
# d_loss_train_3 = data_3["d_loss_train"]
# d_loss_gen_3 = data_3["d_loss_gen"]
# d_loss_3 = (d_loss_gen_3 + d_loss_train_3) / 2
#
# d_loss_train_4 = data_4["d_loss_train"]
# d_loss_gen_4 = data_4["d_loss_gen"]
# d_loss_4 = (d_loss_gen_4 + d_loss_train_4) / 2
# d_acc_train_1 = data_1["d_acc_train"]
# d_acc_gen_1 = data_1["d_acc_gen"]
# d_acc_1 = (d_acc_gen_1 + d_acc_train_1) / 2
# d_acc_train_2 = data_2["d_acc_train"]
# d_acc_gen_2 = data_2["d_acc_gen"]
# d_acc_2 = (d_acc_gen_2 + d_acc_train_2) / 2
#
# d_acc_train_3 = data_3["d_acc_train"]
# d_acc_gen_3 = data_3["d_acc_gen"]
# d_acc_3 = (d_acc_gen_3 + d_acc_train_3) / 2
#
# d_acc_train_4 = data_4["d_acc_train"]
# d_acc_gen_4 = data_4["d_acc_gen"]
# d_acc_4 = (d_acc_gen_4 + d_acc_train_4) / 2
# ax1.set_title("Accuracy - 15 seqLength - Two Flowers")
diagram.set_xlabel('Epoch')
diagram.set_ylabel('Loss')
colors = ['#F95400', '#004FA2', '#F9C000', 'y']
# markers = []
# for m in Line2D.markers:
# try:
# if len(m) == 1 and m != ' ':
# markers.append(m)
# except TypeError:
# pass
# styles = markers + [
# r'$\lambda$',
# r'$\bowtie$',
# r'$\circlearrowleft$',
# r'$\clubsuit$',
# r'$\checkmark$']
skip = 50
first = None
# plt.axvline(13, c='black', linestyle=':', label="Best sentence")
gen = [0.65, 4.9, 5.7, 5.9, 6.5, 6.4, 5.8, 6.6, 6.9, 7.1, 7.6]
disc = [0.7, 0.0, .05, 0, 0, 0, 0, 0, 0, 0, 0]
epoch = [x for x in range(11)]
diagram.plot(epoch, gen, c=colors[1], label='Generator', marker="D")
diagram.plot(epoch, disc, c=colors[0], label='Discriminator', marker="D")
# diagram.plot(data_1['epoch'][:first:skip], data_1['g_loss'][:first:skip], c=colors[0], label='Generator')
# diagram.plot(data_1['epoch'][:first:skip], d_loss_1[:first:skip], c=colors[1], label='Discriminator')
"""
4 onehot loss
"""
#
# diagram.plot(data_1['epoch'][:first:skip], data_1['g_loss'][:first:skip], c=colors[0], label='Generator')
# diagram.plot(data_1['epoch'][:first:skip], d_loss_1[:first:skip], c=colors[1], label='Discriminator')
# #
# diagram.plot(data_1['epoch'][:first:skip], data_2['g_loss'][:first:skip], c=colors[0], linestyle=':', label='Generator (Dropout)')
# diagram.plot(data_1['epoch'][:first:skip], d_loss_2[:first:skip], c=colors[1], linestyle=':', label='Discriminator (Dropout)')
#
# diagram.plot(data_1['epoch'][:first:skip], data_3['g_loss'][:first:skip], c=colors[0], linestyle='-.', label='Generator (Softmax)')
# diagram.plot(data_1['epoch'][:first:skip], d_loss_3[:first:skip], c=colors[1], linestyle='-.', label='Discriminator (Softmax)')
# #
# diagram.plot(data_1['epoch'][:first:skip], data_4['g_loss'][:first:skip], c=colors[0], linestyle='--', label='Generator (Softmax + Dropout)')
# diagram.plot(data_1['epoch'][:first:skip], d_loss_4[:first:skip], c=colors[1], linestyle='--', label='Discriminator (Softmax + Dropout)')
#
"""
4 one-hot Acc
"""
# diagram.plot(data_1['epoch'][:first:skip], data_1['g_acc'][:first:skip], c=colors[0], label='Generator')
# diagram.plot(data_1['epoch'][:first:skip], d_acc_1[:first:skip], c=colors[1], label='Discriminator')
# diagram.plot(data_1['epoch'][:first:skip], data_2['g_acc'][:first:skip], c=colors[0], linestyle=':', label='Generator (Dropout)')
# diagram.plot(data_1['epoch'][:first:skip], d_acc_2[:first:skip], c=colors[1], linestyle=':', label='Discriminator (Dropout)')
# diagram.plot(data_1['epoch'][:first:skip], data_3['g_acc'][:first:skip], c=colors[0], linestyle='-.', label='Generator (Softmax)')
# diagram.plot(data_1['epoch'][:first:skip], d_acc_3[:first:skip], c=colors[1], linestyle='-.', label='Discriminator (Softmax)')
#
# diagram.plot(data_1['epoch'][:first:skip], data_4['g_acc'][:first:skip], c=colors[0], linestyle='--', label='Generator (Softmax + Dropout)')
# diagram.plot(data_1['epoch'][:first:skip], d_acc_4[:first:skip], c=colors[1], linestyle='--', label='Discriminator (Softmax + Dropout)')
# plt.rc('font', family='Courier')
leg = diagram.legend()
# plt.show()
plt.savefig("loss.png", dpi=600)