Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I having KeyError: 'val_acc'?

In my Keras code, I did the following:

model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
history = model.fit(border_irregularity_features,y, epochs=5, batch_size=1, validation_split=0.33)
...
...
accuracy = history.history['acc']
val_acc = history.history['val_acc']

However, I'm having the following error:

val_acc = history.history['val_acc']
KeyError: 'val_acc'

Why is that? What am I missing?

Thanks.

EDIT-1

When I did:

print history.history.keys()

I got:

['acc', 'loss', 'val_acc', 'val_loss']
like image 487
Simplicity Avatar asked Jan 26 '23 18:01

Simplicity


2 Answers

From tensorflow 2 the history keys are as follows : (['val_loss', 'val_accuracy', 'val_precision', 'val_recall', 'loss', 'accuracy', 'precision', 'recall'])

like image 115
Deepak Thirumurugan Avatar answered Jan 31 '23 09:01

Deepak Thirumurugan


There seems to be no issue with the code per-se. I have copied part of the code from another script I had. I just erased the underscores in "val_acc" and "val_loss" and typed them again, and it worked!

Maybe some special characters where embedded when copying and pasting?

like image 44
Simplicity Avatar answered Jan 31 '23 08:01

Simplicity