【问题标题】:output feature map dimension of VGG16 modelVGG16模型的输出特征图维度
【发布时间】:2017-07-12 15:07:12
【问题描述】:

我在keras doc看到了特征提取的例子,并使用以下代码从输入图像中提取特征

input_shape = (224, 224, 3)
model = VGG16(weights = 'imagenet', input_shape = (input_shape[0], 
input_shape[1], input_shape[2]), pooling = 'max', include_top = False)
img = image.load_img(img_path, target_size=(input_shape[0], 
input_shape[1]))
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
img = preprocess_input(img)
feature =  model.predict(img)

然后当我输出feature变量的形状时,我发现它是(1, 512)。为什么是这个维度? print model.summary() 显示了 maxpooling 后最后一个 conv 层输出的形状为 (7, 7, 512),这是我期望 feature 应该的尺寸。

【问题讨论】:

    标签: computer-vision conv-neural-network feature-extraction


    【解决方案1】:

    感谢Yong Yuan 帮助我解决这个问题。由于他在回答 SO 上的问题时遇到了一些问题,所以我只是将他的答案放在这里,以防其他人有同样的问题。

    基本上这是因为在这个模型中指定了一个全局最大池化层(正如我们在model = VGG16(....., pooling = 'max', ....) 行中看到的那样,它从 7*7 单元中选择最大的单元。在 keras documents 中也说过:

     pooling: Optional pooling mode for feature extraction when include_top is False.
    

    在model.summary()给出的输出中,我们可以看到在第五个卷积块的最大池化之后实际上有一个global_max_pooling2d_1层,因此最终维度变为512。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-21
      • 2020-05-25
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 2021-12-27
      相关资源
      最近更新 更多