Answers.Body: <p><em>&quot;But I am not sure how to do it with respect to input pixels.&quot;</em> the same way you do it for the weights... you take your input tensor, you set <code>requires_grad</code> to <code>True</code>, you do the forward pass thus having an output <span class="math-container">$y = f(x)$</span>, and you just do <code>y.mean().backward()</code>, and your input tensor will have the gradient saved in</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-25T14:52:26.213Z
Answers.LastActivityDate: 2024-06-25T14:52:26.213Z
Answers.UserDisplayName: Alberto
Body: <p>Hi for my project I'm using a somewhat simple CNN consisting of several convolution layers and pooling layers. Essentially the model is trained to perform a blur of sorts on an input image.</p>
  <p>For my project the gradients of the output pixels with respect to the input pixels is very important. I'm aware of how to get gradients for the output with respect to weights. But I am not sure how to do it with respect to input pixels.</p>
  <p>Basically it will tell me how changing an input pixel effects the output!</p>
  <p>I'm currently using pytorch but I dont mind using any package that could give me this functionality.</p>
  
Tags: <convolutional-neural-networks><pytorch><convolution><gradient>
Title: How to calculate the gradient for the output with respect to the input pixels
UserDisplayName: James Li
ThreadText: # How to calculate the gradient for the output with respect to the input pixels
  
  (Asked by: username_0 on 2024-06-25)
  
  Hi for my project I'm using a somewhat simple CNN consisting of several convolution layers and pooling layers. Essentially the model is trained to perform a blur of sorts on an input image.
  
  For my project the gradients of the output pixels with respect to the input pixels is very important. I'm aware of how to get gradients for the output with respect to weights. But I am not sure how to do it with respect to input pixels.
  
  Basically it will tell me how changing an input pixel effects the output!
  
  I'm currently using pytorch but I dont mind using any package that could give me this functionality.
  
  **Tags:** convolutional-neural-networks, pytorch, convolution, gradient
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-06-25. Score: 0
  
  *"But I am not sure how to do it with respect to input pixels."* the same way you do it for the weights... you take your input tensor, you set `requires_grad` to `True`, you do the forward pass thus having an output $y = f(x)$, and you just do `y.mean().backward()`, and your input tensor will have the gradient saved in
  
  
  ---
  
  