Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 382
Ludwig Zhou Avatar asked Nov 17 '16 10:11

Ludwig Zhou


1 Answers

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.

like image 81
petezurich Avatar answered Oct 04 '22 04:10

petezurich