Returns whether the <code>targets</code> are in the top <code>k</code> <code>predictions</code>.

Returns whether the targets are in the top k predictions.

k_in_top_k(predictions, targets, k)



A tensor of shape (batch_size, classes) and type float32.


A 1D tensor of length batch_size and type int32 or int64.


An int, number of top elements to consider.


A 1D tensor of length batch_size and type bool. output[[i]] is TRUE if predictions[i, targets[[i]] is within top-k values of predictions[[i]].

Keras Backend

This function is part of a set of Keras backend functions that enable lower level access to the core operations of the backend tensor engine (e.g. TensorFlow, CNTK, Theano, etc.).

You can see a list of all available backend functions here: