Caffe shape mismatch error using pretrained VGG-16 model

I am using PyCaffe to implement a neural network inspired by the VGG 16 layer network. I want to use the pre-trained model available from their GitHub page. Generally this works by matching layer names.

The problem is not with 4096 but rather with 25088. You need to calculate the output feature maps for each layer of your network based on the input feature maps. Note that the fc layer takes an input of fixed size so the output of the previous conv layer must match the input size required by the fc layer. Calculate your fc6 input feature map size (this is the output feature map of the previous conv layer) using the input feature map size of the previous conv layer. Here's the formula: