Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
in0_sc = (in0 - self.shift.expand_as(in0))/self.scale.expand_as(in0)
in1_sc = (in1 - self.shift.expand_as(in0))/self.scale.expand_as(in0)
if(self.pnet_tune):
outs0 = self.net.forward(in0)
outs1 = self.net.forward(in1)
else:
outs0 = self.net[0].forward(in0)
outs1 = self.net[0].forward(in1)
feats0 = {}
feats1 = {}
diffs = {}
for (kk,out0) in enumerate(outs0):
feats0[kk] = util.normalize_tensor(outs0[kk])
feats1[kk] = util.normalize_tensor(outs1[kk])
diffs[kk] = (feats0[kk]-feats1[kk])**2
val = torch.mean(torch.mean(self.lin0.model(diffs[0]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin1.model(diffs[1]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin2.model(diffs[2]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin3.model(diffs[3]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin4.model(diffs[4]),dim=3),dim=2)
if(self.pnet_type=='squeeze'):
val = val + torch.mean(torch.mean(self.lin5.model(diffs[5]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin6.model(diffs[6]),dim=3),dim=2)
val = val.view(val.size()[0],val.size()[1],1,1)
return val
in1_sc = (in1 - self.shift.expand_as(in0))/self.scale.expand_as(in0)
if(self.pnet_tune):
outs0 = self.net.forward(in0)
outs1 = self.net.forward(in1)
else:
outs0 = self.net[0].forward(in0)
outs1 = self.net[0].forward(in1)
feats0 = {}
feats1 = {}
diffs = {}
for (kk,out0) in enumerate(outs0):
feats0[kk] = util.normalize_tensor(outs0[kk])
feats1[kk] = util.normalize_tensor(outs1[kk])
diffs[kk] = (feats0[kk]-feats1[kk])**2
val = torch.mean(torch.mean(self.lin0.model(diffs[0]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin1.model(diffs[1]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin2.model(diffs[2]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin3.model(diffs[3]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin4.model(diffs[4]),dim=3),dim=2)
if(self.pnet_type=='squeeze'):
val = val + torch.mean(torch.mean(self.lin5.model(diffs[5]),dim=3),dim=2)
val = val + torch.mean(torch.mean(self.lin6.model(diffs[6]),dim=3),dim=2)
val = val.view(val.size()[0],val.size()[1],1,1)
return val