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

Add CategoricalFocalCrossentropy to Losses API #17651

Merged

Conversation

Frightera
Copy link
Contributor

@Frightera Frightera commented Mar 9, 2023

Implements the CategoricalFocalCrossentropy() loss based on the paper Focal Loss for Dense Object Detection (Lin et al., 2018).

Feature request was made in keras-team/tf-keras#259.

@gbaned gbaned requested a review from haifeng-jin March 9, 2023 17:12
@google-ml-butler google-ml-butler bot added the keras-team-review-pending Pending review by a Keras team member. label Mar 9, 2023
Copy link
Contributor

@haifeng-jin haifeng-jin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I had a quick review of the docstring styles. Will look into the logics later.

keras/backend.py Outdated Show resolved Hide resolved
keras/backend.py Outdated Show resolved Hide resolved
keras/backend.py Outdated Show resolved Hide resolved
keras/backend.py Show resolved Hide resolved
keras/losses.py Outdated Show resolved Hide resolved
@qlzh727 qlzh727 removed the keras-team-review-pending Pending review by a Keras team member. label Mar 9, 2023
@Frightera
Copy link
Contributor Author

Frightera commented Mar 10, 2023

@haifeng-jin Thanks for the feedback! I ran the format.sh but I guess it does not indentation into account.

Copy link
Contributor

@haifeng-jin haifeng-jin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!
I have provided some more comments on the docstrings format.

The rest of the code LGTM.
Prefer to have @qlzh727 approval before merging.

keras/losses.py Outdated Show resolved Hide resolved
keras/losses.py Outdated Show resolved Hide resolved
keras/losses.py Outdated Show resolved Hide resolved
keras/losses.py Outdated Show resolved Hide resolved
keras/backend.py Outdated Show resolved Hide resolved
keras/losses.py Outdated Show resolved Hide resolved
@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Mar 21, 2023
@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Mar 21, 2023
@Frightera Frightera removed the request for review from sampathweb March 21, 2023 11:53
@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Mar 26, 2023
@Frightera Frightera requested review from qlzh727 and removed request for fchollet March 26, 2023 20:45
@Frightera
Copy link
Contributor Author

@qlzh727 Re-requesting a review removed Francois, can you add him again? Also fixed the docstrings in terms of clarity.

Can you check once more? Thanks.

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you.

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Mar 27, 2023
@haifeng-jin
Copy link
Contributor

@Frightera Here is what would happen next.

After @qlzh727 approval, I will start to help you migrate it. It would take some work to adapt to our internal system for anything that changes the APIs.

One more thing we need your help is to update the (tensorflow/tensorflow RELEASE.md)[https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md] to include your changes in the release notes. You may start this after this PR is completely merged.

Thanks!

copybara-service bot pushed a commit that referenced this pull request 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 pushed a commit that referenced this pull request 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 pushed a commit that referenced this pull request 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
@haifeng-jin
Copy link
Contributor

haifeng-jin commented Mar 29, 2023

@Frightera I have added the release notes altogether.
So you do not need to submit a separate PR for it.
Everything will be done with this single PR.

@Frightera
Copy link
Contributor Author

@haifeng-jin Thanks, appreciate it 👍🏼

@copybara-service copybara-service bot merged commit 0f8e81f into keras-team:master Mar 30, 2023
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Mar 30, 2023
Imported from GitHub PR keras-team/keras#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:

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

Add pure logic of CFCE

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

Add support for ragged tensors

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

Make sure output sum equals 1

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

Raise shape mismatch / update tests

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

Add categorical_focal_loss tests

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

Add documentation / minor fix.

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

Reformatting after focal loss implementation

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

Fix linting.

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

Fix docstring style.

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

Update the docstrings.

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

Fix linting issues

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

Address comments from code-review.

Merging this change closes #17651

PiperOrigin-RevId: 520482950
@Frightera Frightera deleted the frightera_categorical_focal_loss_v2 branch March 30, 2023 23:26
copybara-service bot pushed a commit that referenced this pull request Apr 5, 2023
Imported from GitHub PR #17746

Small changes in backend.py, some of were discussed in the PR #17651
Copybara import of the project:

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

Small fixes on focal losses and cat.crossentropy

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

Fix linting and sigmoid func

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

Revert the redirection of the internal function

Merging this change closes #17746

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17746 from Frightera:frightera_small_loss_fixes b87b656
PiperOrigin-RevId: 522179031
copybara-service bot pushed a commit that referenced this pull request Apr 6, 2023
Imported from GitHub PR #17746

Small changes in backend.py, some of were discussed in the PR #17651
Copybara import of the project:

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

Small fixes on focal losses and cat.crossentropy

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

Fix linting and sigmoid func

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

Revert the redirection of the internal function

Merging this change closes #17746

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17746 from Frightera:frightera_small_loss_fixes b87b656
PiperOrigin-RevId: 522179031
copybara-service bot pushed a commit that referenced this pull request Apr 6, 2023
Imported from GitHub PR #17746

Small changes in backend.py, some of were discussed in the PR #17651
Copybara import of the project:

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

Small fixes on focal losses and cat.crossentropy

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

Fix linting and sigmoid func

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

Revert the redirection of the internal function

Merging this change closes #17746

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17746 from Frightera:frightera_small_loss_fixes b87b656
PiperOrigin-RevId: 522179031
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keras-team-review-pending Pending review by a Keras team member. ready to pull Ready to be merged into the codebase size:L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants