val_acc and top-1 acc are different?

12 views
Skip to first unread message

ganab...@gmail.com

unread,
Oct 29, 2017, 9:56:05 PM10/29/17
to Keras-users
Hello all
After i finished training my dataset i have noticed that val_top-1 accuracy and val_acc are different.
val_acc and top-1 acc must be same as explained in concept of top-n acc.
Why would it happen?

Ex)
acc: 0.8876 - in_top1: 0.0444
val_acc: 0.8850 - val_in_top1: 0.0222

code:

def top_k_categorical_accuracy(y_true, y_pred, k=5):
    return K.mean(K.in_top_k(y_pred, K.argmax(y_true, axis=-1), k), axis=-1)

def in_top1(x, y):
    return top_k_categorical_accuracy(x, y, k=1)
def in_top5(x, y):
    return top_k_categorical_accuracy(x, y, k=5)

metrics = ['accuracy']
metrics.append(in_top1)
metrics.append(in_top5)


new_model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=metrics)

result:
ETA: 0s - loss: 1.8021 - acc: 0.8876 - in_top1: 0.0444 - in_top2: 1.0000 - in_top3: 1.0000 - in_top4: 1.0000 - in_top5: 1.0000 - in_top6: 1.0000 - in_top7: 1.0000 - in_top8: 1.0000 - in_top9: 1.0000 - in_top10: 1.0000 - val_loss: 1.8440 - val_acc: 0.8850 - val_in_top1: 0.0222 - val_in_top2: 1.0000 - val_in_top3: 1.0000 - val_in_top4: 1.0000 - val_in_top5: 1.0000 - val_in_top6: 1.0000 - val_in_top7: 1.0000 - val_in_top8: 1.0000 - val_in_top9: 1.0000 - val_in_top10: 1.0000

Reply all
Reply to author
Forward
0 new messages