title: K.gradients(loss, input_img)[0] return "None". (Keras CNN visualization with tensorflow backend)
body: <p>I have CNN models trained using Keras with Tensorflow backend.
  And I want to visualize my CNN filters with this tutorial: <a href="https://blog.keras.io/how-convolutional-neural-networks-see-the-world.html" rel="noreferrer">https://blog.keras.io/how-convolutional-neural-networks-see-the-world.html</a></p>
  
  <pre><code>from keras import backend as K
  from keras.models import load_model
  import numpy as np
  
  model = load_model('my_cnn_model.h5')
  input_img = np.load('my_picture.npy')
  
  # get the symbolic outputs of each "key" layer (we gave them unique names).
  layer_dict = dict([(layer.name, layer) for layer in model.layers])
  
  layer_name = 'block5_conv3'
  filter_index = 0  # can be any integer from 0 to 511, as there are 512 filters in that layer
  
  # build a loss function that maximizes the activation
  # of the nth filter of the layer considered
  layer_output = layer_dict[layer_name].output
  loss = K.mean(layer_output[:, :, :, filter_index])
  
  # compute the gradient of the input picture wrt this loss
  grads = K.gradients(loss, input_img)[0]
  
  # normalization trick: we normalize the gradient
  grads /= (K.sqrt(K.mean(K.square(grads))) + 1e-5)
  
  # this function returns the loss and grads given the input picture
  iterate = K.function([input_img], [loss, grads])
  </code></pre>
  
  <p>However, when the code execute to this line:<br>
  <code>grads = K.gradients(loss, input_img)[0]</code><br>
  I found it returns nothing but <code>None</code> object, so the program fail to progress after that.</p>
  
  <p>I search for some solution. Some people say the<code>input_img</code> should be tensorflow's Tensor type:
  <a href="https://github.com/keras-team/keras/issues/5455" rel="noreferrer">https://github.com/keras-team/keras/issues/5455</a></p>
  
  <p>But when I tried to convert the img to Tensor, the problem is still exist.<br>
  I tried the solution in the link above, but still fail.</p>
  
  <p>There is also someone say that this problem exists because your CNN model is not differentiable.
  <a href="https://github.com/keras-team/keras/issues/8478" rel="noreferrer">https://github.com/keras-team/keras/issues/8478</a></p>
  
  <p>But my model use only the activate function of ReLU and Sigmoid(at output layer).
  Is this problem really caused by nondifferentiable problem?</p>
  
  <p>Can anyone help me? Thank you very much!</p>