I am trying to do Image Recognition in Python with TensorFlow and Keras. Please look at my code in the link below which I provided as I was facing another issue for the same code which is fixed now.
getting error while predicting a test image - cannot reshape array of size
I followed the post Keras, How to get the output of each layer? to get output of each layer and used code below
from keras import backend as K
inp = model.input # input placeholder
outputs = [layer.output for layer in model.layers[:12]] # all layer outputs except first (input) layer
functor = K.function([inp, K.learning_phase()], outputs ) # evaluation function
# Testing
test = numpy.random.random(input_shape)[np.newaxis,...]
layer_outs = functor([test, 1.])
print (layer_outs)
However, I am getting below error:
ValueError: Input tensors to a Functional must come from `tf.keras.Input`. Received: 0 (missing previous layer metadata).
Can someone please help to get output of each layer for the image that I am doing the prediction against that is a new image and not part of the images the network was trained on?