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

LPIPS loss can produce negative values #24

Open
jklimmek opened this issue Aug 29, 2024 · 0 comments
Open

LPIPS loss can produce negative values #24

jklimmek opened this issue Aug 29, 2024 · 0 comments

Comments

@jklimmek
Copy link

When calculating LPIPS you first square distances and then multiply by a 1x1Conv. Since 1x1Conv is frozen and randomly initialized it can produce negative results, which is not desired. So instead:

for i in range(len(self.channels)):
    diffs[i] = (norm_tensor(features_real[i]) - norm_tensor(features_fake[i])) ** 2

return sum([spatial_average(self.lins[i].model(diffs[i])) for i in range(len(self.channels))])

you should move **2 term after diffs are passed through 1x1Conv as so:

for i in range(len(self.channels)):
    diffs[i] = (norm_tensor(features_real[i]) - norm_tensor(features_fake[i]))

return sum([spatial_average(self.lins[i].model(diffs[i]) ** 2) for i in range(len(self.channels))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant