Skip to content

Commit e3b4d0b

Browse files
committed
keras update acc > accuracy
1 parent c9cf104 commit e3b4d0b

15 files changed

+52
-47
lines changed

ann_class2/keras_example.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
plt.show()
7676

7777
# accuracies
78-
plt.plot(r.history['acc'], label='acc')
79-
plt.plot(r.history['val_acc'], label='val_acc')
78+
plt.plot(r.history['accuracy'], label='acc')
79+
plt.plot(r.history['val_accuracy'], label='val_acc')
8080
plt.legend()
8181
plt.show()
8282

ann_class2/keras_functional.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
plt.show()
7171

7272
# accuracies
73-
plt.plot(r.history['acc'], label='acc')
74-
plt.plot(r.history['val_acc'], label='val_acc')
73+
plt.plot(r.history['accuracy'], label='acc')
74+
plt.plot(r.history['val_accuracy'], label='val_acc')
7575
plt.legend()
7676
plt.show()
7777

cnn_class/keras_example.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def rearrange(X):
113113
plt.show()
114114

115115
# accuracies
116-
plt.plot(r.history['acc'], label='acc')
117-
plt.plot(r.history['val_acc'], label='val_acc')
116+
plt.plot(r.history['accuracy'], label='acc')
117+
plt.plot(r.history['val_accuracy'], label='val_acc')
118118
plt.legend()
119119
plt.show()
120120

cnn_class2/fashion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def y2indicator(Y):
101101
plt.show()
102102

103103
# accuracies
104-
plt.plot(r.history['acc'], label='acc')
105-
plt.plot(r.history['val_acc'], label='val_acc')
104+
plt.plot(r.history['accuracy'], label='acc')
105+
plt.plot(r.history['val_accuracy'], label='val_acc')
106106
plt.legend()
107107
plt.show()
108108

cnn_class2/fashion2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def y2indicator(Y):
9696
plt.show()
9797

9898
# accuracies
99-
plt.plot(r.history['acc'], label='acc')
100-
plt.plot(r.history['val_acc'], label='val_acc')
99+
plt.plot(r.history['accuracy'], label='acc')
100+
plt.plot(r.history['val_accuracy'], label='val_acc')
101101
plt.legend()
102102
plt.show()
103103

cnn_class2/use_pretrained_weights_resnet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def get_confusion_matrix(data_path, N):
173173
plt.show()
174174

175175
# accuracies
176-
plt.plot(r.history['acc'], label='train acc')
177-
plt.plot(r.history['val_acc'], label='val acc')
176+
plt.plot(r.history['accuracy'], label='train acc')
177+
plt.plot(r.history['val_accuracy'], label='val acc')
178178
plt.legend()
179179
plt.show()
180180

cnn_class2/use_pretrained_weights_vgg.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
# valid_path = '../large_files/blood_cell_images/TEST'
3232

3333
# https://www.kaggle.com/moltean/fruits
34-
# train_path = '../large_files/fruits-360/Training'
35-
# valid_path = '../large_files/fruits-360/Validation'
36-
train_path = '../large_files/fruits-360-small/Training'
37-
valid_path = '../large_files/fruits-360-small/Validation'
34+
train_path = '../large_files/fruits-360/Training'
35+
valid_path = '../large_files/fruits-360/Validation'
36+
# train_path = '../large_files/fruits-360-small/Training'
37+
# valid_path = '../large_files/fruits-360-small/Validation'
3838

3939
# useful for getting number of files
4040
image_files = glob(train_path + '/*/*.jp*g')
@@ -45,7 +45,7 @@
4545

4646

4747
# look at an image for fun
48-
plt.imshow(image.load_img(np.random.choice(image_files)))
48+
plt.imshow(image.img_to_array(image.load_img(np.random.choice(image_files))).astype('uint8'))
4949
plt.show()
5050

5151

@@ -76,7 +76,6 @@
7676
)
7777

7878

79-
8079
# create an instance of ImageDataGenerator
8180
gen = ImageDataGenerator(
8281
rotation_range=20,
@@ -172,8 +171,8 @@ def get_confusion_matrix(data_path, N):
172171
plt.show()
173172

174173
# accuracies
175-
plt.plot(r.history['acc'], label='train acc')
176-
plt.plot(r.history['val_acc'], label='val acc')
174+
plt.plot(r.history['accuracy'], label='train acc')
175+
plt.plot(r.history['val_accuracy'], label='val acc')
177176
plt.legend()
178177
plt.show()
179178

nlp_class2/pos_ner_keras.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def get_data_ner(split_sequences=False):
217217
plt.show()
218218

219219
# accuracies
220-
plt.plot(r.history['acc'], label='acc')
221-
plt.plot(r.history['val_acc'], label='val_acc')
220+
plt.plot(r.history['accuracy'], label='acc')
221+
plt.plot(r.history['val_accuracy'], label='val_acc')
222222
plt.legend()
223223
plt.show()
224224

nlp_class3/attention.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def softmax_over_time(x):
3434

3535
# config
3636
BATCH_SIZE = 64
37-
EPOCHS = 100
38-
LATENT_DIM = 256
39-
LATENT_DIM_DECODER = 256 # idea: make it different to ensure things all fit together properly!
40-
NUM_SAMPLES = 10000
37+
EPOCHS = 30
38+
LATENT_DIM = 400
39+
LATENT_DIM_DECODER = 400 # idea: make it different to ensure things all fit together properly!
40+
NUM_SAMPLES = 20000
4141
MAX_SEQUENCE_LENGTH = 100
4242
MAX_NUM_WORDS = 20000
4343
EMBEDDING_DIM = 100
@@ -190,7 +190,8 @@ def softmax_over_time(x):
190190
# assign the values
191191
for i, d in enumerate(decoder_targets):
192192
for t, word in enumerate(d):
193-
decoder_targets_one_hot[i, t, word] = 1
193+
if word > 0:
194+
decoder_targets_one_hot[i, t, word] = 1
194195

195196

196197

@@ -367,8 +368,8 @@ def acc(y_true, y_pred):
367368
plt.show()
368369

369370
# accuracies
370-
plt.plot(r.history['acc'], label='acc')
371-
plt.plot(r.history['val_acc'], label='val_acc')
371+
plt.plot(r.history['accuracy'], label='acc')
372+
plt.plot(r.history['val_accuracy'], label='val_acc')
372373
plt.legend()
373374
plt.show()
374375

nlp_class3/bilstm_mnist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def get_mnist(limit=None):
9797
plt.show()
9898

9999
# accuracies
100-
plt.plot(r.history['acc'], label='acc')
101-
plt.plot(r.history['val_acc'], label='val_acc')
100+
plt.plot(r.history['accuracy'], label='acc')
101+
plt.plot(r.history['val_accuracy'], label='val_acc')
102102
plt.legend()
103103
plt.show()
104104

nlp_class3/cnn_toxic.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@
7070
s = sorted(len(s) for s in sequences)
7171
print("median sequence length:", s[len(s) // 2])
7272

73+
print("max word index:", max(max(seq) for seq in sequences if len(seq) > 0))
74+
7375

7476
# get word -> integer mapping
7577
word2idx = tokenizer.word_index
7678
print('Found %s unique tokens.' % len(word2idx))
7779

80+
# exit()
81+
7882

7983
# pad sequences so that we get a N x T matrix
8084
data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)
@@ -144,8 +148,8 @@
144148
plt.show()
145149

146150
# accuracies
147-
plt.plot(r.history['acc'], label='acc')
148-
plt.plot(r.history['val_acc'], label='val_acc')
151+
plt.plot(r.history['accuracy'], label='acc')
152+
plt.plot(r.history['val_accuracy'], label='val_acc')
149153
plt.legend()
150154
plt.show()
151155

nlp_class3/lstm_toxic.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from sklearn.metrics import roc_auc_score
2121

2222
import keras.backend as K
23-
if len(K.tensorflow_backend._get_available_gpus()) > 0:
24-
from keras.layers import CuDNNLSTM as LSTM
25-
from keras.layers import CuDNNGRU as GRU
23+
# if len(K.tensorflow_backend._get_available_gpus()) > 0:
24+
# from keras.layers import CuDNNLSTM as LSTM
25+
# from keras.layers import CuDNNGRU as GRU
2626

2727

2828
# Download the data:
@@ -124,7 +124,7 @@
124124
model.compile(
125125
loss='binary_crossentropy',
126126
optimizer=Adam(lr=0.01),
127-
metrics=['accuracy']
127+
metrics=['accuracy'],
128128
)
129129

130130

@@ -144,8 +144,8 @@
144144
plt.show()
145145

146146
# accuracies
147-
plt.plot(r.history['acc'], label='acc')
148-
plt.plot(r.history['val_acc'], label='val_acc')
147+
plt.plot(r.history['accuracy'], label='acc')
148+
plt.plot(r.history['val_accuracy'], label='val_acc')
149149
plt.legend()
150150
plt.show()
151151

nlp_class3/memory_network.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def hop(query, story):
425425
plt.show()
426426

427427
# accuracies
428-
plt.plot(r.history['acc'], label='acc')
429-
plt.plot(r.history['val_acc'], label='val_acc')
428+
plt.plot(r.history['accuracy'], label='acc')
429+
plt.plot(r.history['val_accuracy'], label='val_acc')
430430
plt.legend()
431431
plt.show()

nlp_class3/poetry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@
160160
plt.show()
161161

162162
# accuracies
163-
plt.plot(r.history['acc'], label='acc')
164-
plt.plot(r.history['val_acc'], label='val_acc')
163+
plt.plot(r.history['accuracy'], label='acc')
164+
plt.plot(r.history['val_accuracy'], label='val_acc')
165165
plt.legend()
166166
plt.show()
167167

nlp_class3/wseq2seq.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@
165165
# assign the values
166166
for i, d in enumerate(decoder_targets):
167167
for t, word in enumerate(d):
168-
decoder_targets_one_hot[i, t, word] = 1
168+
if word != 0:
169+
decoder_targets_one_hot[i, t, word] = 1
169170

170171

171172

@@ -190,7 +191,7 @@
190191

191192
# this word embedding will not use pre-trained vectors
192193
# although you could
193-
decoder_embedding = Embedding(num_words_output, LATENT_DIM)
194+
decoder_embedding = Embedding(num_words_output, EMBEDDING_DIM)
194195
decoder_inputs_x = decoder_embedding(decoder_inputs_placeholder)
195196

196197
# since the decoder is a "to-many" model we want to have
@@ -263,8 +264,8 @@ def acc(y_true, y_pred):
263264
plt.show()
264265

265266
# accuracies
266-
plt.plot(r.history['acc'], label='acc')
267-
plt.plot(r.history['val_acc'], label='val_acc')
267+
plt.plot(r.history['accuracy'], label='acc')
268+
plt.plot(r.history['val_accuracy'], label='val_acc')
268269
plt.legend()
269270
plt.show()
270271

0 commit comments

Comments
 (0)