Get output from a non final keras model layer
There is a difference between layers and the outputs of those layers in Keras. You can think of layers as representing a computation and the outputs as the results of those computation. When you instantiate a Model
object, it expects the results of a computation as it's output, instead of the computation itself, hence the error. To fix it, you can pass the output of the layer to the Model
constructor:
import numpy as np
from keras.applications import vgg16, inception_v3, resnet50, mobilenet
from keras import Model
a = np.random.rand(24, 224, 224, 3)
a = mobilenet.preprocess_input(a)
mobilenet_model = mobilenet.MobileNet(weights='imagenet')
mobilenet_model.summary()
model_output = mobilenet_model.get_layer("conv_pw_13_relu").output
m = Model(inputs=mobilenet_model.input, outputs=model_output)
print(m.predict(a))
In order to acess the output of an intermediate layer in a Keras model, Keras Provides different ways.
In your case You can take output of the layer you want like this
model_out = mobilenet_model.get_layer("layer_you_want").output
m = Model(input=inputLayer, outputs=model_out)
For more details regarding this and other methods available take a look at this documentation