Skip to content Skip to sidebar Skip to footer

Getting Vector Obtained In The Last Layer Of Cnn Before Softmax Layer

I am trying to implement a system by encoding inputs using CNN. After CNN, I need to get a vector and use it in another deep learning method. def get_input_representation(self):

Solution 1:

For that you can define a backend function to get the output of arbitrary layer(s):

from keras import backend as K

func = K.function([model.input], [model.layers[index_of_layer].output])

You can find the index of your desired layer using model.summary() where the layers are listed starting from index zero. If you need the layer before the last layer you can use -2 as the index (i.e. .layers attribute is actually a list so you can index it like a list in python). Then you can use the function you have defined by passing a list of input array(s):

outputs = func(inputs)

Alternatively, you can also define a model for this purpose. This has been covered in Keras documentation more thoroughly so I advise you to read that.

Post a Comment for "Getting Vector Obtained In The Last Layer Of Cnn Before Softmax Layer"