Skip to content

Instantly share code, notes, and snippets.

@Blaizzy
Last active May 5, 2020 17:23
Show Gist options
  • Select an option

  • Save Blaizzy/862aabff5083ce6b2e8e40198f6efd37 to your computer and use it in GitHub Desktop.

Select an option

Save Blaizzy/862aabff5083ce6b2e8e40198f6efd37 to your computer and use it in GitHub Desktop.
def forward(self, input, target):
res = [F.l1_loss(input, target) / 100] # pixel loss
in_fts = self.make_fts(input, True) # extracting activations for predicted image
out_fts = self.make_fts(target) # extracting activations for ground-truth image
res+= [F.l1_loss(inp, targ.features) * w
for inp, targ, w in zip(in_fts, out_fts, self.wgts)] # Perceptual loss
return sum(res)
def close(self):
for o in self.sfs: o.remove() # This removes the activations from your memory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment