2017-02-19 4 views

Antwort

8

Wenn Sie gerade nach dem topK sind, können Sie Tensorflow immer direkt aufrufen (Sie sagen nicht, welches Backend Sie verwenden).

from keras import backend as K 
import tensorflow as tf 

top_values, top_indices = K.get_session().run(tf.nn.top_k(_pred_test, k=5)) 

Wenn Sie eine Genauigkeit Metrik wollen Sie es zu Ihrem Modell 'top_k_categorical_accuracy' hinzufügen können.

model.compile('adam', 'categorical_crossentropy', ['accuracy', 'top_k_categorical_accuracy']) 

history = model.fit(X_train, y_train, nb_epoch=3, validation_split=0.2) 

Train on 31367 samples, validate on 7842 samples 
Epoch 1/3 
31367/31367 [==============================] - 6s - loss: 0.0818 - acc: 0.9765 - top_k_categorical_accuracy: 0.9996 - 
... 

Der Standard k für diese Metrik ist 5, aber wenn Sie das ändern wollte 3 sagen, dass Sie Ihr Modell wie folgt aufgebaut würde:

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]) 
Verwandte Themen