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

Fixed where the square() to preserve distance properties #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed where the square() to preserve distance properties
  • Loading branch information
GuillaumeRochette authored Jul 10, 2021
commit 779e2982d0e963c66349ba88a09467a66aa67867
10 changes: 5 additions & 5 deletions lpips/lpips.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ def forward(self, in0, in1, retPerLayer=False, normalize=False):

for kk in range(self.L):
feats0[kk], feats1[kk] = lpips.normalize_tensor(outs0[kk]), lpips.normalize_tensor(outs1[kk])
diffs[kk] = (feats0[kk]-feats1[kk])**2
diffs[kk] = feats0[kk]-feats1[kk]

if(self.lpips):
if(self.spatial):
res = [upsample(self.lins[kk](diffs[kk]), out_HW=in0.shape[2:]) for kk in range(self.L)]
res = [upsample(self.lins[kk](diffs[kk]).square(), out_HW=in0.shape[2:]) for kk in range(self.L)]
else:
res = [spatial_average(self.lins[kk](diffs[kk]), keepdim=True) for kk in range(self.L)]
res = [spatial_average(self.lins[kk](diffs[kk]).square(), keepdim=True) for kk in range(self.L)]
else:
if(self.spatial):
res = [upsample(diffs[kk].sum(dim=1,keepdim=True), out_HW=in0.shape[2:]) for kk in range(self.L)]
res = [upsample(diffs[kk].square().sum(dim=1,keepdim=True), out_HW=in0.shape[2:]) for kk in range(self.L)]
else:
res = [spatial_average(diffs[kk].sum(dim=1,keepdim=True), keepdim=True) for kk in range(self.L)]
res = [spatial_average(diffs[kk].square().sum(dim=1,keepdim=True), keepdim=True) for kk in range(self.L)]

val = res[0]
for l in range(1,self.L):
Expand Down