Keras remove layers after model.fit()
Asked Answered
F

1

6

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.

Filagree answered 17/11, 2016 at 10:50 Comment(1)
Can you elaborate on the second part of the question regarding layers and tensorvariable? Thanks in advance.Anticholinergic
A
2

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.

Anticholinergic answered 13/6, 2017 at 21:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.