我正在尝试使用 VGG16 Net 来训练模型进行图像分类,并希望使用此代码将没有密集层的权重转移到我的图像集。
model1 = applications.VGG16(include_top=False, weights='imagenet', input_shape=(img_width,img_height,3))
在学习了瓶颈特征之后,模型的最后几层是:
block5_conv2 (Conv2D) (None, 6, 6, 512) 2359808
_________________________________________________________________
block5_conv3 (Conv2D) (None, 6, 6, 512) 2359808
_________________________________________________________________
block5_pool (MaxPooling2D) (None, 3, 3, 512) 0
=================================================================
最后一层尺寸为(None,3,3,512)。这将是我的密集层的输入。
model1 = Sequential()
model1.add(Flatten(input_shape=train_data.shape[1:]))
所以模型的输入形状是(3,3,512)。我的问题是,当我尝试预测图像时,输入图像的大小为(224,224,3). 那么如何将输入图像的形状转换为模型的输入形状呢?
当我尝试预测它时,这是我收到的错误:
ValueError: Error when checking input: expected flatten_1_input to have a shape (3, 3, 512) but got array with shape (224, 224, 3)
如何更改模型的输入形状或我必须预测的输入图像的输入形状?