Hi,
Notebook so far: Notebook
I am trying to solve the homework for Lesson 1 by using the standard VGG16 built into Keras.
I had to recreate the pop() and add() functions to remove the last Dense(1000) layer and replace it with Dense(2) layer.
However, when I try to use the fit_generator function, I get the following error:
ValueError: Error when checking model target: expected predictions to have shape (None, 1000) but got array with shape (64, 2)
It sounds like my model is still expecting to output 1000 categories rather than 2. Why is this?
Model summary below:
Layer (type) Output Shape Param # Connected to
input_27 (InputLayer) (None, 224, 224, 3) 0
block1_conv1 (Convolution2D) (None, 224, 224, 64) 1792 input_27[0][0]
block1_conv2 (Convolution2D) (None, 224, 224, 64) 36928 block1_conv1[0][0]
block1_pool (MaxPooling2D) (None, 112, 112, 64) 0 block1_conv2[0][0]
block2_conv1 (Convolution2D) (None, 112, 112, 128) 73856 block1_pool[0][0]
block2_conv2 (Convolution2D) (None, 112, 112, 128) 147584 block2_conv1[0][0]
block2_pool (MaxPooling2D) (None, 56, 56, 128) 0 block2_conv2[0][0]
block3_conv1 (Convolution2D) (None, 56, 56, 256) 295168 block2_pool[0][0]
block3_conv2 (Convolution2D) (None, 56, 56, 256) 590080 block3_conv1[0][0]
block3_conv3 (Convolution2D) (None, 56, 56, 256) 590080 block3_conv2[0][0]
block3_pool (MaxPooling2D) (None, 28, 28, 256) 0 block3_conv3[0][0]
block4_conv1 (Convolution2D) (None, 28, 28, 512) 1180160 block3_pool[0][0]
block4_conv2 (Convolution2D) (None, 28, 28, 512) 2359808 block4_conv1[0][0]
block4_conv3 (Convolution2D) (None, 28, 28, 512) 2359808 block4_conv2[0][0]
block4_pool (MaxPooling2D) (None, 14, 14, 512) 0 block4_conv3[0][0]
block5_conv1 (Convolution2D) (None, 14, 14, 512) 2359808 block4_pool[0][0]
block5_conv2 (Convolution2D) (None, 14, 14, 512) 2359808 block5_conv1[0][0]
block5_conv3 (Convolution2D) (None, 14, 14, 512) 2359808 block5_conv2[0][0]
block5_pool (MaxPooling2D) (None, 7, 7, 512) 0 block5_conv3[0][0]
flatten (Flatten) (None, 25088) 0 block5_pool[0][0]
fc1 (Dense) (None, 4096) 102764544 flatten[0][0]
fc2 (Dense) (None, 4096) 16781312 fc1[0][0]
predictions (Dense) (None, 2) 8194 fc2[0][0]
Total params: 134,268,738
Trainable params: 8,194
Non-trainable params: 134,260,544
The .add() function sets the model.built variable to False, so I am wondering if itâs anything to do with that. And if it is, how do I âbuildâ the model? Any help is greatly appreciated.