首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >理解model.summary Keras

理解model.summary Keras
EN

Stack Overflow用户
提问于 2017-08-08 06:56:53
回答 1查看 5.5K关注 0票数 5

我正在努力理解Keras中的model.summary()。我有以下卷积神经网络。第一次卷积的值是:

代码语言:javascript
复制
conv2d_4 (Conv2D)            (None, 148, 148, 16)      448 

148和448来自哪里?

代码语言:javascript
复制
image_input = layers.Input(shape=(150, 150, 3))
x = layers.Conv2D(16, 3, activation='relu')(image_input)

x = layers.MaxPooling2D(2)(x)
x = layers.Conv2D(32, 3, activation='relu')(x)

x = layers.MaxPooling2D(2)(x)
x = layers.Conv2D(64, 3, activation='relu')(x)

x = layers.MaxPooling2D(2)(x)
x = layers.Flatten()(x)
x = layers.Dense(512, activation='relu')(x)
output = layers.Dense(1, activation='sigmoid')(x)

# Keras Model definition
# input = input feature map
# output = input feature map + stacked convolution/maxpooling layers + fully connected layer + sigmoid output layer
model = Model(image_input, output)
model.summary()

输出

代码语言:javascript
复制
Layer (type)                 Output Shape              Param #   
=================================================================
input_2 (InputLayer)         (None, 150, 150, 3)       0         
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 148, 148, 16)      448       
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 74, 74, 16)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 72, 72, 32)        4640      
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 36, 36, 32)        0         
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 34, 34, 64)        18496     
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 17, 17, 64)        0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 18496)             0         
_________________________________________________________________
dense_1 (Dense)              (None, 512)               9470464   
_________________________________________________________________
dense_2 (Dense)              (None, 1)                 513     
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-08 07:36:29

Keras文档中,您可以看到填充是由default=valid填充的,因此没有填充,跨距大小为1。然后输出形状明显是148 x 148。

要计算这个值,可以使用以下公式:

代码语言:javascript
复制
O = (W - K + 2P)/S + 1

其中O是输出高度/宽度,W是输入高度/宽度,K是滤波器尺寸,P是填充,S是步长。

关于第二个参数,您有一个16的特征映射,内核大小为3x3,因此您有16x(3x3),即144。然后,你有三个颜色通道,使144 x3= 432,然后你需要添加16个偏差,这使448;)希望这有帮助!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45561306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档