From a42a25a5e82094b20f4782e5789d8918fdc79cbb Mon Sep 17 00:00:00 2001 From: Santiago Castro Date: Sun, 30 Oct 2022 02:22:12 -0700 Subject: [PATCH] Make LPIPS code example use the interval [-1, 1] (#1296) * Make LPIPS code example use the interval [-1, 1] * Apply suggestions from code review Co-authored-by: Jirka Borovec --- src/torchmetrics/image/lpip.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/torchmetrics/image/lpip.py b/src/torchmetrics/image/lpip.py index 962aeadd16d..84ff4868c5a 100644 --- a/src/torchmetrics/image/lpip.py +++ b/src/torchmetrics/image/lpip.py @@ -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=) + tensor(0.3493, grad_fn=) """ is_differentiable: bool = True