I want to use vgg16 pre-trained model of keras. I have notice some strange behavior when trying to change the model.
1) I have add some layers
of the per-trained model. My problem is that tensorboard is showing the layers of the model that I didn't add into the sequence model. This is strange because I have also deleted the imported model. I think this have to do with the dependency between layers so I want to remove this dependencies. How can I do this?
For example in this picture there is two layers that I didn't add but they are showing in the graph
vgg16_model = keras.applications.vgg16.VGG16()
cnnModel = keras.models.Sequential()
for layer in vgg16_model.layers[0:13]:
cnnModel.add(layer)
for layer in vgg16_model.layers[14:16]:
cnnModel.add(layer)
for layer in vgg16_model.layers[17:21]:
cnnModel.add(layer)
cnnModel.add(keras.layers.Dense(2048, name="compress_1"))
cnnModel.add(keras.layers.Dense(1024, name="compress_2"))
cnnModel.add(keras.layers.Dense(512, name="compress_3"))
for layer in cnnModel.layers[0:4]:
layer.trainable = False
del vgg16_model
2) the second problem occurs when using cnnModel.pop()
. In fact I have add all the layers but I do a pop to the layer I don't want before adding the next one this is the error I get.
Layer block4_conv2 has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `get_output_at(node_index)` instead.
And this is the code I am using:
for layer in vgg16_model.layers[0:14]:
cnnModel.add(layer)
cnnModel.pop()
for layer in vgg16_model.layers[14:17]:
cnnModel.add(layer)
cnnModel.pop()
for layer in vgg16_model.layers[17:21]:
cnnModel.add(layer)
cnnModel.pop()
is working the problem only occurs when trying to add the next layer.
Thank you for your help.
from tensorflow.keras.utils import plot_model
plot_model(model, to_file = 'model_plot.png', show_shapes = True, show_layer_names = True)
to plot the model and see. My only concern is that, I don't want the unnecessary layers increase the computational cost.