<p dir="auto">I am replacing the last softmax layer (with 1000 output units) of the original model (VGG16) with a new softmax layer (with 10 output units):<br>
model.add(Dense(4096, activation='relu'))<br>
model.add(Dropout(0.5))<br>
model.add(Dense(1000, activation='softmax'))<br>
model.load_weights('./vgg16_weights.h5')<br>
model.layers.pop()<br>
model.layers.pop()<br>
model.add(Dropout(0.5))<br>
model.add(Dense(10, activation='softmax'))<br>
sgd = SGD(lr=1e-3, decay=1e-6, momentum=0.9, nesterov=True)<br>
model.compile(optimizer=sgd, loss='categorical_crossentropy')</p>
<p dir="auto">However, when I check input_shape and output_shape of the last three layers I find:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">model.layers[-1].output_shape<br>
(None, 10)<br>
model.layers[-1].input_shape<br>
(None, 1000)<br>
model.layers[-2].input_shape<br>
(None, 1000)<br>
model.layers[-2].output_shape<br>
(None, 1000)<br>
model.layers[-3].output_shape<br>
(None, 4096)<br>
model.layers[-2].name<br>
'dropout_3'<br>
model.layers[-3].name<br>
'dense_2'<br>
model.layers[-1].name<br>
'dense_4'</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">Apparently, model.layers.pop() does not fully update the model. I have OS X 10.11.5 and I just updated  keras and tensorflow (I cannot use Theano since it produces  Illegal instruction: 4 error)</p>
<p dir="auto">I'm trying to start <a href="https://github.com/iamaaditya/VQA_Demo">https://github.com/iamaaditya/VQA_Demo</a> which uses pre-trained VGG16 model (<a href="https://github.com/iamaaditya/VQA_Demo/blob/master/models/CNN/VGG.py">https://github.com/iamaaditya/VQA_Demo/blob/master/models/CNN/VGG.py</a>). The last 2 layers are removed with layers.pop(). This doesn't seem to work, however. The message "ValueError: could not broadcast input array from shape (1000) into shape (4096)" is displayed, and I see the layers were not removed when I do "plot(image_model, to_file='model_vgg.png', show_shapes=True)". Thank you.</p>