我使用了两个图像网络训练模型,即VGG16和inception,使用Keras API在python中使用以下代码行;其中x是输入图像,批处理大小是为了简单起见=1。
VGGbase_model = InceptionV3(weights='imagenet', include_top=False,
input_shape=(299,299,3))
Inceptionbase_model = VGG16(weights='imagenet', include_top=False,
input_shape=(224,224,3))
predictVgg16= VGGbase_model.predict_on_batch(x)
predictinception= Inceptionbase_model.predict_on_batch(x)我观察到VGG16模型预测的输出维度为(1, 512 ),我理解512是VGG16预测的特征。然而,初始模型输出的维度为1,8,8,2048。我知道2048是inception预测的特征向量,但是什么是8,8,以及为什么VGG16只有2个维度,而inception有3个维度。有什么意见请发表意见。
发布于 2019-07-11 19:05:19
只需键入以下命令即可查看所有图层的大小:
print(Inceptionbase_model.summary())
print(VGGbase_model.summary())你可以在这里看到:InceptionV3,vgg16
InceptionV3在最后一卷积层具有shape (None,8,8,2048)和vgg16 (None, 7, 7, 512)。如果你想从每个模型中获取特征,你可以通过使用include_top=False和pooling='avg'或pooling='max'调用模型来实现(这将在最后添加一个池层,并将为InceptionV3模型输出2048个特征,为vgg16输出512个特征。
例如。
img_shape=(299,299,3)
Inceptionbase_model = InceptionV3(input_shape=img_shape, weights='imagenet', include_top=False, pooling='avg')https://stackoverflow.com/questions/56987277
复制相似问题