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

How to understand the gradient backward propagation of perceptual loss? #173

Open
bolimath opened this issue Jan 8, 2019 · 1 comment
Open

Comments

@bolimath
Copy link

bolimath commented Jan 8, 2019

In train.lua, Line 199, local grad_out_percep = percep_crit:backward(out, target)

this line will call for the function crit:updateGradInput(input, target) in file fast_neural_style/PerceptualCriterion.lua,

however, according to the definition of the function
function crit:updateGradInput(input, target)
self.gradInput = self.net:updateGradInput(input, self.grad_net_output)
return self.gradInput
end

and self.grad_net_output is defined as zero at Line 137,
-- Set up a tensor of zeros to pass as gradient to net in backward pass
self.grad_net_output:resizeAs(output):zero()

In my opinion, if the grad_net_output is set as zero, the return of function updateGradInput will always be zero, which implies the perceptual gradient will not be involved in the backward of the network.

Can someone be kindly to help me understand it?

@htoyryla
Copy link
Contributor

htoyryla commented Jan 8, 2019

I guess this is explained by the perceptual losses being evaluated, not at the network output, but in content and style loss layers which have been inserted inside the network at selected layers. So we pass a zero gradient from the output backwards, and the real gradients will be added by the content and style loss layers.

At least this is what happens in the original, iterative neural-style, and I have the impression that fast-neural-style uses the same approach for perceptual loss evaluation. In other words, you should look at the content and style loss layers to see what they do to the gradient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants