title: How to convert Tensor into NumPy array
body: <p>I have trained <code>ResNet50</code> model on my data. I want to get the output of a custom layer while making the prediction. I tried using the below code to get the output of a custom layer, it gives data in a tensor format, but I need the data in a <code>NumPy array</code> format. I tried to convert the tensor to NumPy array but getting errors, I have followed this <a href="https://stackoverflow.com/questions/34097281/how-can-i-convert-a-tensor-into-a-numpy-array-in-tensorflow">post</a>, but it wasn't helpful</p>
  <p>Can anyone share some thoughts, any advice will be very helpful</p>
  <pre><code>from keras.models import load_model
  import tensorflow as tf
  import numpy as np
  
  config = tf.ConfigProto()
  config.gpu_options.allow_growth = True
  tf.Session(config=config)
  
  model = load_model(model_path) # load trained model
  
  data = load_data(data_path) # load data for predictions
  result = model.predict(data)
  print(type(result_dev))
  #&lt;class 'numpy.ndarray'&gt; 
  
  result = model.get_layer('avg_pool').output
  print(type(result))
  #&lt;class 'tensorflow.python.framework.ops.Tensor'&gt;
  </code></pre>
  <p>Things I tried</p>
  <h3>Option 1</h3>
  <pre><code>result = result.numpy()
  </code></pre>
  <blockquote>
  <p>AttributeError: 'Tensor' object has no attribute 'numpy'</p>
  </blockquote>
  <h3>Option 2</h3>
  <pre><code>result = result.eval(session=tf.compat.v1.Session())
  </code></pre>
  <blockquote>
  <p>2020-09-22 11:21:59.522138: I
  tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful
  NUMA node read from SysFS had negative value (-1), but there must be
  at least one NUMA node, so returning NUMA node zero 2020-09-22
  11:21:59.522343: I
  tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0
  with properties:</p>
  </blockquote>
  <p>Dependency Installed:</p>
  <pre><code>tensorflow-gpu==1.15.0
  </code></pre>