We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
def focal_loss_sigmoid(prediction_tensor, target_tensor, weights=None, alpha=0.5, gamma=0): target_tensor = tf.cast(target_tensor, tf.float32) sigmoid_p = tf.nn.sigmoid(prediction_tensor) zeros = array_ops.zeros_like(sigmoid_p, dtype=sigmoid_p.dtype) pos_p_sub = array_ops.where(target_tensor > zeros, target_tensor - sigmoid_p, zeros) neg_p_sub = array_ops.where(target_tensor > zeros, zeros, sigmoid_p) if gamma != 0: per_entry_cross_ent = - alpha * (pos_p_sub ** gamma) * tf.log(tf.clip_by_value(sigmoid_p, 1e-8, 1.0)) \ - (1 - alpha) * (neg_p_sub ** gamma) * tf.log(tf.clip_by_value(1.0 - sigmoid_p, 1e-8, 1.0)) else: # ∵0**0=1 per_entry_cross_ent = - alpha * target_tensor * tf.log(tf.clip_by_value(sigmoid_p, 1e-8, 1.0)) \ - (1 - alpha) * (1 - target_tensor) * tf.log(tf.clip_by_value(1.0 - sigmoid_p, 1e-8, 1.0)) return per_entry_cross_ent
The text was updated successfully, but these errors were encountered:
此即为sigmoid_cross_entropy
Sorry, something went wrong.
Agreed. I also found that when gamma=0, it does not correctly compute the loss.
No branches or pull requests
增加 gamma = 0 的情况的讨论
The text was updated successfully, but these errors were encountered: