检查模型目标时出错:预期预测具有形状(无,1000)但是具有形状的数组(64,2)

时间:2017-01-23 23:27:14

标签: deep-learning keras kaggle keras-layer imagenet

到目前为止

笔记本:Notebook

我正在尝试重塑标准Keras VGG16模型,以用于经典的猫与狗比赛(Kaggle Cats vs Dogs

我必须重新创建pop() Keras模型的add()Sequential()函数,以删除最后一个Dense(1000)图层并将其替换为Dense(2)图层。

但是,当我尝试使用fit_generator()函数时,出现以下错误:

ValueError: Error when checking model target: expected predictions to have shape (None, 1000) but got array with shape (64, 2)

听起来我的模型仍然期望输出1000个类别而不是2.为什么会这样?

以下模型摘要:

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

.add()函数将model.built变量设置为False,因此我想知道它是否与此有关。如果是的话,我该如何构建"该模型?非常感谢任何帮助。

0 个答案:

没有答案