Replies: 1 comment 10 replies
-
Yes, |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I have another question while looking at your code.
The ArcfaceLoss and ArcfaceLossSimple of your code are actually the same as the current learning criteria, right?
Because ArcfaceLossSimple's cos(y_pred_values+margin) = cos(y_pred_values) * cos(margin) - sin(y_pred_vals) * sin(margin), ArcfaceLoss's theta = tf.cos(tf.acos(y_pred_vals) + self.margin2)
margin==margin2==0.5
class ArcfaceLoss(tf.keras.losses.Loss):
def call(self, y_true, norm_logits):
pick_cond = tf.where(y_true != 0)
y_pred_vals = tf.gather_nd(norm_logits, pick_cond)
if self.margin1 == 1.0 and self.margin2 == 0.0 and self.margin3 == 0.0:
theta = y_pred_vals
elif self.margin1 == 1.0 and self.margin3 == 0.0:
theta = tf.cos(tf.acos(y_pred_vals) + self.margin2)
else:
theta = tf.cos(tf.acos(y_pred_vals) * self.margin1 + self.margin2) - self.margin3
class ArcfaceLossSimple(tf.keras.losses.Loss):
def call(self, y_true, norm_logits):
pick_cond = tf.where(y_true != 0)
y_pred_vals = tf.gather_nd(norm_logits, pick_cond)
theta = y_pred_vals * self.margin_cos - tf.sqrt(1 - tf.pow(y_pred_vals, 2)) * self.margin_sin
theta_valid = tf.where(y_pred_vals > self.threshold, theta, self.theta_min - theta)
arcface_logits = tf.tensor_scatter_nd_update(norm_logits, pick_cond, theta_valid) * self.scale
return tf.keras.losses.categorical_crossentropy(y_true, arcface_logits, from_logits=self.from_logits, label_smoothing=self.label_smoothing)
Beta Was this translation helpful? Give feedback.
All reactions