Skip to content

Commit

Permalink
Make LPIPS code example use the interval [-1, 1] (#1296)
Browse files Browse the repository at this point in the history
* Make LPIPS code example use the interval [-1, 1]
* Apply suggestions from code review

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
  • Loading branch information
bryant1410 and Borda authored Oct 30, 2022
1 parent e4b3ae9 commit a42a25a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/torchmetrics/image/lpip.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ class LearnedPerceptualImagePatchSimilarity(Metric):
>>> _ = torch.manual_seed(123)
>>> from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
>>> lpips = LearnedPerceptualImagePatchSimilarity(net_type='vgg')
>>> img1 = torch.rand(10, 3, 100, 100)
>>> img2 = torch.rand(10, 3, 100, 100)
>>> # LPIPS needs the images to be in the [-1, 1] range.
>>> img1 = (torch.rand(10, 3, 100, 100) * 2) - 1
>>> img2 = (torch.rand(10, 3, 100, 100) * 2) - 1
>>> lpips(img1, img2)
tensor(0.3566, grad_fn=<SqueezeBackward0>)
tensor(0.3493, grad_fn=<SqueezeBackward0>)
"""

is_differentiable: bool = True
Expand Down

0 comments on commit a42a25a

Please sign in to comment.