title: How to get value of a Keras tensor in TensorFlow 2?
body: <p>TF1 had <code>sess.run()</code> and <code>.eval()</code> to get values of tensors - and Keras had <code>K.get_value()</code>; now, neither work the same (former two at all).</p>
  
  <p><code>K.eager(K.get_value)(tensor)</code> appears to work inside Keras graph by exiting it, and <code>K.get_value(tensor)</code> outside the graph - both w/ TF2's default eagerly (which is <em>off</em> in former). However, this fails if <code>tensor</code> is a <em>Keras backend operation</em>:</p>
  
  <pre class="lang-py prettyprint-override"><code>import keras.backend as K
  def tensor_info(x):
      print(x)
      print("Type: %s" % type(x))
      try:        
          x_value = K.get_value(x)
      except:
          try:    x_value = K.eager(K.get_value)(x)
          except: x_value = x.numpy()
      print("Value: %s" % x_value)  # three methods
  
  ones = K.ones(1)
  ones_sqrt = K.sqrt(ones)
  
  tensor_info(ones); print()
  tensor_info(ones_sqrt)
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code>&lt;tf.Variable 'Variable:0' shape=(1,) dtype=float32, numpy=array([1.], dtype=float32)&gt;
  Type: &lt;class 'tensorflow.python.ops.resource_variable_ops.ResourceVariable'&gt;
  Value: [1.]
  
  Tensor("Sqrt:0", shape=(1,), dtype=float32)
  Type: &lt;class 'tensorflow.python.framework.ops.Tensor'&gt;
  # third print fails w/ below
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code>AttributeError: 'Tensor' object has no attribute 'numpy' 
  </code></pre>
  
  <p><hr> 
  This is a non-issue in TF &lt; 2.0. <a href="https://github.com/keras-team/keras/issues/13396" rel="noreferrer">Github</a>'s been silent. I'm aware of ways to rewrite the code as a workaround, but it'll eliminate Keras' backend-neutrality and work akin to <code>tf.keras</code>. Is there a way to get Keras 2.3 tensor values in TensorFlow 2.0 while retaining backend-neutrality? </p>