Last active
November 26, 2020 05:49
-
-
Save panchishin/35e3f224108f3e47343748d7241ddbc4 to your computer and use it in GitHub Desktop.
top k loss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def top_k_loss(k=25): | |
@tf.function | |
def loss(y_true, y_pred): | |
y_error_of_true = tf.keras.losses.categorical_crossentropy(y_true=y_true,y_pred=y_pred) | |
topk, indexs = tf.math.top_k( y_error_of_true, k=tf.minimum(k, y_true.shape[0]) ) | |
return topk | |
return loss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment