迄今为止的笔记本:笔记本
我正在尝试重塑标准Keras
VGG16
模型以用于经典的猫对狗比赛(Kaggle Cats vs Dogs)
我不得不重新创建 Keras 模型的pop()
和add()
函数Sequential()
来删除最后Dense(1000)
一层并用 layer 替换它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,所以我想知道它是否与此有关。如果是,我如何“构建”模型?任何帮助是极大的赞赏。