Ludwig Zhou
Ludwig Zhou

Reputation: 1036

Keras remove layers after model.fit()

I'm using Keras to do the modelling works and I wonder is it possible to remove certain layers by index or name? Currently I only know the model.pop() could do this work but it just removes the most recently added layers. In addition, layers is the type of tensorvariable and I have no idea how to remove certain element which can be done in numpy array or list. BTW I'm using Theano backend.

Upvotes: 6

Views: 4534

Answers (1)

petezurich
petezurich

Reputation: 10184

It is correct that model.pop() just removes the last added layer and there is no other documented way to delete intermediate layers.

You can always get the output of any intermediate layer like so:

 base_model = VGG19(weights='imagenet')
 model = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_pool').output)

Example taken from here: https://keras.io/applications/

Than add your new layers on top of that.

Upvotes: 2

Related Questions