Keras,图层形状缺失

时间:2018-03-16 11:00:32

标签: keras

当我将模型加载到Keras并使用以下打印摘要时

model = applications.VGG16(include_top=True)
print(model.summary())

我可以看到所有形状:

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 224, 224, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0         
...

但是当我不包括top(include_top = False)时,我看不到形状:

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, None, None, 3)     0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, None, None, 64)    1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, None, None, 64)    36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, None, None, 64)    0         
...

为什么?或者也许不应该那样,我有一些问题?

1 个答案:

答案 0 :(得分:1)

好的,我找到了答案。如果没有顶级网络,可以针对不同的图片分辨率使用不同的输入尺寸,并且“无”。意味着它可以接受任何形状,所以如果我使用它:

model = applications.VGG16(include_top=False, input_shape=(128, 128, 3))

它将计算网络的实际形状并打印:

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 128, 128, 3)       0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 128, 128, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 128, 128, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 64, 64, 64)        0