0
$\begingroup$

So, I have to work with Vgg16 in my semester group project, and was following this to do transfer learning.

I don't understand CNN much, but am learning currently.

The very first problem was that Vgg16 has 16 layers, whereas the base_model.summary() had 26 when initialised with VGGFace(include_top=True and 19 when VGGFace(include_top=False. Looks like the 16 layers are those with weight.

Now, tutorial uses include_top=False and did

x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
x = Dense(1024, activation='relu')(x)
x = Dense(512, activation='relu')(x)

preds = Dense(NO_CLASSES, activation='softmax')(x)

model = Model(base_model.input, preds)

As much as I understood, we first took output layer of base_model and it added 5 layers to that 1 GlobalAveragePooling2d, 4 Dense layers.

My question is why did it modify the Vgg16 layer structure. Why do we need to repace last 7 layers with 5 different layers. Couldn't we set the same 7 layers as trainable or just add identical layers. What is the actual advantage of this replacement.

Before replacement enter image description here

After replacement

'global_average_pooling2d_11', 'dense_42', 'dense_43', 'dense_44', 'dense_45'
$\endgroup$

1 Answer 1

0
$\begingroup$

Sometimes, the changes of layers are necessary based on the data and what the developer wants. The GlobalAveragePooling2D and MaxPooling2D are the layer for pooling the result of feature extraction/convolution to make the features ready to be learned by the classification layers (Dense layers and softmax layer).

However, those two pooling functions have different method of pooling and obviously different math process. You may also try with the current model without changing it as well. It may also result different data dimensions therefore one need to adjust the number of nodes in the Dense layer to match the output from previous layer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.