Skip to content
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

[Feature Request]: Adding Categorical Focal Loss #259

Closed
Frightera opened this issue Feb 18, 2023 · 3 comments
Closed

[Feature Request]: Adding Categorical Focal Loss #259

Frightera opened this issue Feb 18, 2023 · 3 comments
Assignees

Comments

@Frightera
Copy link
Contributor

System information.

TensorFlow version (you are using): 2.11
Are you willing to contribute it (Yes/No) : Yes

Describe the feature and the current behavior/state.

Currently, Keras provides built-in implementation of Binary Focal Crossentropy. However, it does not provide a built-in implementation of the Categorical Focal Loss.

Related SO questions:
https://stackoverflow.com/questions/56293964/categorical-focal-loss-on-keras
https://stackoverflow.com/questions/65875860/how-to-use-categorial-focal-loss-for-one-hot-encoding-with-keras
https://stackoverflow.com/questions/57807175/use-of-1-a-weight-in-categorical-focal-loss
https://stackoverflow.com/questions/70459884/can-sigmoidfocalcrossentropy-in-tensorflow-tf-addons-be-used-in-multiclass-cla

Some repositories:
https://github.com/umbertogriffo/focal-loss-keras
https://github.com/artemmavrin/focal-loss

Will this change the current api? How?
Yes, this will change the current API by adding a new built-in loss function to Keras.

Contributing

  • Do you want to contribute a PR? (yes/no): Yes
@sampathweb
Copy link
Collaborator

Thanks for raising this issue. This would be a useful feature. Would you be able to contribute with a PR. Please also look at reference implementation in tesorflow-addons package.

@Frightera
Copy link
Contributor Author

Frightera commented Feb 23, 2023

@sampathweb Yes I can contribute with a PR, I'll start working on it.

Edit: This is in progress.

copybara-service bot referenced this issue in keras-team/keras Mar 23, 2023
Imported from GitHub PR #17651

Implements the `CategoricalFocalCrossentropy()` loss based on the paper [Focal Loss for Dense Object Detection](https://arxiv.org/pdf/1708.02002.pdf) (Lin et al., 2018).

Feature request was made in #17583.
Copybara import of the project:

--
5696b5a by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add pure logic of CFCE

--
40e547f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add support for ragged tensors

--
d3dd32f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Make sure output sum equals 1

--
16adf85 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Raise shape mismatch / update tests

--
bc38e33 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add categorical_focal_loss tests

--
363baaf by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add documentation / minor fix.

--
c267fa0 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Reformatting after focal loss implementation

--
3c33117 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting.

--
3538622 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix docstring style.

--
6b4fa6b by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Update the docstrings.

--
49c03a2 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting issues

Merging this change closes #17651

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17651 from Frightera:frightera_categorical_focal_loss_v2 49c03a2
PiperOrigin-RevId: 518880861
copybara-service bot referenced this issue in keras-team/keras Mar 27, 2023
Imported from GitHub PR #17651

Implements the `CategoricalFocalCrossentropy()` loss based on the paper [Focal Loss for Dense Object Detection](https://arxiv.org/pdf/1708.02002.pdf) (Lin et al., 2018).

Feature request was made in #17583.
Copybara import of the project:

--
5696b5a by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add pure logic of CFCE

--
40e547f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add support for ragged tensors

--
d3dd32f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Make sure output sum equals 1

--
16adf85 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Raise shape mismatch / update tests

--
bc38e33 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add categorical_focal_loss tests

--
363baaf by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add documentation / minor fix.

--
c267fa0 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Reformatting after focal loss implementation

--
3c33117 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting.

--
3538622 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix docstring style.

--
6b4fa6b by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Update the docstrings.

--
49c03a2 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting issues

--
f560336 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Address comments from code-review.

Merging this change closes #17651

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17651 from Frightera:frightera_categorical_focal_loss_v2 f560336
PiperOrigin-RevId: 518880861
copybara-service bot referenced this issue in keras-team/keras Mar 27, 2023
Imported from GitHub PR #17651

Implements the `CategoricalFocalCrossentropy()` loss based on the paper [Focal Loss for Dense Object Detection](https://arxiv.org/pdf/1708.02002.pdf) (Lin et al., 2018).

Feature request was made in #17583.
Copybara import of the project:

--
5696b5a by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add pure logic of CFCE

--
40e547f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add support for ragged tensors

--
d3dd32f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Make sure output sum equals 1

--
16adf85 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Raise shape mismatch / update tests

--
bc38e33 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add categorical_focal_loss tests

--
363baaf by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add documentation / minor fix.

--
c267fa0 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Reformatting after focal loss implementation

--
3c33117 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting.

--
3538622 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix docstring style.

--
6b4fa6b by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Update the docstrings.

--
49c03a2 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting issues

--
f560336 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Address comments from code-review.

Merging this change closes #17651

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17651 from Frightera:frightera_categorical_focal_loss_v2 f560336
PiperOrigin-RevId: 519824695
copybara-service bot referenced this issue in keras-team/keras Mar 28, 2023
Imported from GitHub PR #17651

Implements the `CategoricalFocalCrossentropy()` loss based on the paper [Focal Loss for Dense Object Detection](https://arxiv.org/pdf/1708.02002.pdf) (Lin et al., 2018).

Feature request was made in #17583.
Copybara import of the project:

--
5696b5a by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add pure logic of CFCE

--
40e547f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add support for ragged tensors

--
d3dd32f by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Make sure output sum equals 1

--
16adf85 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Raise shape mismatch / update tests

--
bc38e33 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add categorical_focal_loss tests

--
363baaf by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Add documentation / minor fix.

--
c267fa0 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Reformatting after focal loss implementation

--
3c33117 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting.

--
3538622 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix docstring style.

--
6b4fa6b by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Update the docstrings.

--
49c03a2 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Fix linting issues

--
f560336 by Kaan Bıçakcı <kaan.dvlpr@gmail.com>:

Address comments from code-review.

Merging this change closes #17651

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17651 from Frightera:frightera_categorical_focal_loss_v2 f560336
PiperOrigin-RevId: 519824695
@Frightera
Copy link
Contributor Author

Closing as PR is merged now.

@fchollet fchollet transferred this issue from keras-team/keras Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants