Checks if the targets are in the top-k predictions.
tf.keras.ops.in_top_k(
targets, predictions, k
)
| Args | |
|---|---|
targets | A tensor of true labels. |
predictions | A tensor of predicted labels. |
k | An integer representing the number of predictions to consider. |
| Returns | |
|---|---|
A boolean tensor of the same shape as targets, where each element indicates whether the corresponding target is in the top-k predictions. |
targets = keras.ops.convert_to_tensor([2, 5, 3]) predictions = keras.ops.convert_to_tensor( [[0.1, 0.4, 0.6, 0.9, 0.5], [0.1, 0.7, 0.9, 0.8, 0.3], [0.1, 0.6, 0.9, 0.9, 0.5]]) in_top_k(targets, predictions, k=3) array([ True False True], shape=(3,), dtype=bool)
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/keras/ops/in_top_k