tf.keras.ops.in_top_k
Stay organized with collections
Save and categorize content based on your preferences.
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.
|
Example:
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[]]