I was trying to rewrite vgg16.py from scratch but instead building vgg19 instead. I actually wanted to build a different model from scratch to see if it really affects accuracy. I went through the code for vgg19 and vgg16 from the keras repo. I saw that the difference lies in the extra convolution blocks in vgg19.
And also, the pre-trained weights for both of them differ. I’m pasting the part where my code for vgg16 and vgg19 differ here.
self.ConvBlock(2, 64) self.ConvBlock(2, 128) self.ConvBlock(4, 256) self.ConvBlock(4, 512) self.ConvBlock(4, 512)
And, I’m loading the pre-trained weights this way:
TH_WEIGHTS_PATH = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_th_dim_ordering_th_kernels.h5' TH_WEIGHTS_PATH_NO_TOP = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_th_dim_ordering_th_kernels_notop.h5' ..... def create(self,size,include_top): ..... if not include_top: fname = 'vgg19_weights_th_dim_ordering_th_kernels_notop.h5' model.load_weights(get_file(fname, TH_WEIGHTS_PATH_NO_TOP, cache_subdir='models')) return model.add(Flatten()) self.FCBlock() self.FCBlock() model.add(Dense(1000, activation='softmax')) fname = 'vgg19_weights_th_dim_ordering_th_kernels.h5' model.load_weights(get_file(fname, TH_WEIGHTS_PATH, cache_subdir='models'))
I’m getting the following error when i try to instantiate vgg19 in my redux.ipynb file.
ValueError: You are trying to load a weight file containing 18 layers into a model with 21 layers.
The exact line of error pointed out is.
89 self.FCBlock() 90 model.add(Dense(1000, activation='softmax')) ---> 91 92 fname = 'vgg19_weights_th_dim_ordering_th_kernels.h5' 93 model.load_weights(get_file(fname, TH_WEIGHTS_PATH, cache_subdir='models'))
I double-checked the path for my weights and they seem correct. Please do let me know what I’m doing wrong here.