【发布时间】:2019-06-25 00:52:28
【问题描述】:
我正在研究 Keras 的来龙去脉。所以,在这方面,我正在检查model.summary() 函数。
我使用的是 Keras 自己提供的简单 image classification example,并加载了提供的各种预训练模型(Xception、VGG16 等)。
如前所述,我使用model.summary() 检查了每个模型架构。然后我注意到由于某种原因,Connected to 列(即第 4 列)并未出现在每个模型摘要中。例如MobileNetV2 我得到(只显示了前几行):
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, 224, 224, 3) 0
__________________________________________________________________________________________________
Conv1_pad (ZeroPadding2D) (None, 225, 225, 3) 0 input_1[0][0]
__________________________________________________________________________________________________
Conv1 (Conv2D) (None, 112, 112, 32) 864 Conv1_pad[0][0]
但是对于MobileNet,我得到:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 224, 224, 3) 0
_________________________________________________________________
conv1_pad (ZeroPadding2D) (None, 225, 225, 3) 0
_________________________________________________________________
conv1 (Conv2D) (None, 112, 112, 32) 864
在模型加载后执行此输出,无需采取任何额外操作(无训练、无推理等)。
这看起来很奇怪,我不确定这里发生了什么。例如,从这个问题here(直到model0.fit(...) 部分)创建这个简单模型并运行model0.summary() 给我一个没有Connected to 列的摘要,这也与此问题中发布的摘要相反。
那么,输出的这种变化? model.summary() 是怎么回事?我们对输出有一些控制吗(尽管上面的例子并不暗示)?还是输出与模型的结构方式有关?
编辑:
根据评论中的要求,我添加了用于重现两个模型摘要的(琐碎的)代码。
from keras.applications.mobilenet_v2 import MobileNetV2
from keras.applications.mobilenet import MobileNet
model1 = MobileNetV2(weights='imagenet')
print(model1.summary())
model2 = MobileNet(weights='imagenet')
print(model2.summary())
另外,如果这些信息有用的话,我的系统使用 Keras 2.2.4、Tensorflow 1.12.0 和 Ubuntu 16.04。
【问题讨论】:
-
您应该包含产生这两种结果的实际代码,包括导入。