Created
July 16, 2020 13:19
-
-
Save TeraBytesMemory/4b4b776c87af083db66f6c7401d95cc9 to your computer and use it in GitHub Desktop.
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 manifold_mixup_loss(alpha=1.): | |
def _manifold_mixup_loss(y_true, y_pred): | |
''' | |
y_true: (batch_size, onehot_label_size) | |
y_pred: (batch_size, output_unit_size) | |
''' | |
dist = tf.compat.v1.distributions.Beta(alpha, alpha) | |
beta = dist.sample() | |
mixuped_y_true = (1. - beta) * tf.reverse(y_true, [0]) + beta * y_true | |
mixuped_y_pred = (1. - beta) * tf.reverse(y_pred, [0]) + beta * y_pred | |
mixuped_y_pred = tf.nn.softmax(mixuped_y_pred) | |
return tf.keras.losses.categorical_crossentropy(mixuped_y_true, mixuped_y_pred) | |
return _manifold_mixup_loss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment