-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Perceptual Similarity loss #20844
base: master
Are you sure you want to change the base?
Perceptual Similarity loss #20844
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #20844 +/- ##
===========================================
- Coverage 82.04% 61.15% -20.89%
===========================================
Files 559 564 +5
Lines 52367 52761 +394
Branches 8096 8154 +58
===========================================
- Hits 42964 32268 -10696
- Misses 7427 18522 +11095
+ Partials 1976 1971 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
from keras.src.models import Functional | ||
from keras.src.utils import file_utils | ||
|
||
WEIGHTS_PATH = ( |
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.
Correct weights path should still be added here. Currently I've put a placeholder. I uploaded the LPIPS weights to Hugging Face, as I'm not sure how to upload to storage.googleapis.com
.
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.
Currently added test will fail because it cannot find the weights at that location. Easy way to try out the tests locally is to change this line:
model = lpips.LPIPS() |
with
model = lpips.LPIPS(weights=<path_to_local_copy>)
@matt-gardner does it make more sense to leave LPIPS as an application and not include in the losses? That way people can always use it through a custom loss definition, without cluttering / redesigning the loss api for feature extraction losses. |
Thanks for the PR! Due to the way this method works, it does not seem to be a good fit for the I think the best way to demonstrate this loss might be one of:
The easiest way to leverage LPIPS might be to subclass a model and override the |
@fchollet Thanks for the quick look! I agree that currently it doesn't really fit in the loss api and have removed it. Do you think LPIPS is still useful as an application within Keras? In that case, how do we handle the upload of the weights here? As a follow up PR for keras.io, a code example could demonstrate it in a training loop for instance as you suggest. |
We aren't adding any new models to the |
As described in #20839.
Conversion of weights partly based on an implementation found here.
Added
keras.losses.PerceptualSimilarity
keras.applications.lpips.LPIPS
TODO
add to Metrics?I uploaded the LPIPS weights to Hugging Face, as I'm not sure how to upload to
storage.googleapis.com
.Testing code snippet
Tests both the model and loss object and compares to the torch metrics implementation.