Skip to content

Instantly share code, notes, and snippets.

@rejunity
Created April 16, 2017 07:19
Show Gist options
  • Save rejunity/a0c2b874668aed725df1adb262648ffd to your computer and use it in GitHub Desktop.
Save rejunity/a0c2b874668aed725df1adb262648ffd to your computer and use it in GitHub Desktop.
Histrogram style loss based on "Stable and Controllable Neural Texture Synthesis and Style Transfer Using Histogram Losses" (4.3)
# output -- per layer feature-map of the image we optimize
# style -- per layer feature-map of the style image we want to copy
# histogram_matching() -- see reference numpy implementation http://stackoverflow.com/a/33047048/7873678
output_remapped = histogram_matching(output, style, nbins=1024) # non-differentiable
sum((output_image - output_remapped)**2) # gradients assume that output_remapped ~~ const
@fsalmasri
Copy link

where is the histogram calculation function ?

@mkolodny
Copy link

Hi there, I see you wrote 'non-differentiable' as a comment there, so could this be used in back-propagation?

The line with that comment isn't differentiable, but the line below it is. So histogram loss (the two lines in combination) can be used in back propagation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment