I have trained ResNet50
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 NumPy array
format. I tried to convert the tensor to NumPy array but getting errors, I have followed this post, but it wasn't helpful
Can anyone share some thoughts, any advice will be very helpful
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))
#<class 'numpy.ndarray'>
result = model.get_layer('avg_pool').output
print(type(result))
#<class 'tensorflow.python.framework.ops.Tensor'>
Things I tried
Option 1
result = result.numpy()
AttributeError: 'Tensor' object has no attribute 'numpy'
Option 2
result = result.eval(session=tf.compat.v1.Session())
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:
Dependency Installed:
tensorflow-gpu==1.15.0