perphyyoung
3/13/2019 - 8:55 AM

[keras_top_k] #keras #metrics

[keras_top_k] #keras #metrics

# https://stackoverflow.com/questions/42327006/how-to-calculate-top5-accuracy-in-keras

# top_k default to be 5
model.compile('adam', 'categorical_crossentropy', ['accuracy', 'top_k_categorical_accuracy'])

# set k to 3
top3_acc = functools.partial(keras.metrics.top_k_categorical_accuracy, k=3)
top3_acc.__name__ = 'top3_acc'
model.compile('adam', 'categorical_crossentropy', ['accuracy', top3_acc])