-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
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
Added Focal tversky loss #932
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Aditi-Mhatre, thanks for adding a new loss function and thank you for adding a test!
I left some comments below, and can you please include the loss to the docs/
? Thanks 🤗
beta: float = 0.5, | ||
gamma: float = 1.0, | ||
): | ||
assert mode in {BINARY_MODE, MULTILABEL_MODE, MULTICLASS_MODE} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the class docstring under __init__
similar to other losses
output_sum = torch.sum(output, dim=dims) | ||
target_sum = torch.sum(target, dim=dims) | ||
difference = LA.vector_norm(output - target, ord=1, dim=dims) | ||
|
||
intersection = (output_sum + target_sum - difference) / 2 # TP | ||
fp = output_sum - intersection | ||
fn = target_sum - intersection | ||
|
||
tversky_score = (intersection + smooth) / ( | ||
intersection + alpha * fp + beta * fn + smooth | ||
).clamp_min(eps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand we can just call soft_tversky_score
here?
[ | ||
[[1, 1, 1, 1], [1, 1, 1, 1], 0.0, 1e-5, 0.5, 0.5, 1.0], | ||
[[0, 1, 1, 0], [0, 1, 1, 0], 0.0, 1e-5, 0.5, 0.5, 1.0], | ||
[[1, 1, 1, 1], [0, 0, 0, 0], 1.0, 1e-5, 0.5, 0.5, 1.0], | ||
[[1, 0, 1, 0], [0, 1, 0, 0], 1.0, 1e-5, 0.5, 0.5, 1.0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test case with gamma != 1?
The focal Tversky loss has already been implemented. |
Indeed 😄 missed it, probably a documentation issue! Thanks for pointing it @zifuwanggg |
Hi,
Added:
Changed:
Maybe you can take a look at it.