1
$\begingroup$

In the pre-implemented models in keras (VGG16 ect) it is specified that we can change shape of the inputs of the models and still load the pre-trained imagenet weights.

What I am confused about is then what happens to the first layer weights? If the input tensor has a different shape, then the number of weights will be different than for the pre-trained models isn't it?

Here is the implementation of the Keras VGG16 model for reference.

$\endgroup$

1 Answer 1

2
$\begingroup$

The first layers are convolution and pooling ones:

  • For the convolutional layers, the only weights are the kernels and the biases, and they have fixed size (e.g. 3x3x3, 5x5x3) and do not depend on the input tensor shape.
  • The pooling layers do not have weights at all.

That's why you can reuse the weights independently from the input tensor shape.

With dense layers (i.e. the final layers), you need shapes to match, so you cannot reuse them if they do not.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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