title: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute '_in_graph_mode'
body: <p>I am trying to visualize CNN filters by optimizing a random 'image' so that it produces a high mean activation on that filter which is somehow similar to the neural style transfer algorithm.</p>
  
  <p>For that purpose, I am using TensorFlow==2.2.0-rc. But during the optimization process, an error occurs saying <code>'tensorflow.python.framework.ops.EagerTensor' object has no attribute '_in_graph_mode'</code>. I tried debugging it and it somehow works when I don't use the <code>opt.apply_gradients()</code> and instead,  apply its gradient manually like <code>img = img - lr *  grads</code> but I want to use the "Adam" optimizer rather than the simple SGD.</p>
  
  <p>Here is my code for the optimization part</p>
  
  <pre><code>opt = tf.optimizers.Adam(learning_rate=lr, decay = 1e-6)
  for _ in range(epoch):
      with tf.GradientTape() as tape:
          tape.watch(img)
          y = model(img)[:, :, :, filter]
          loss = -tf.math.reduce_mean(y)
          grads = tape.gradient(loss, img)
          opt.apply_gradients(zip([grads], [img]))
  </code></pre>