简体   繁体   English

使用keras python输出卷积层

[英]Output convolutional layer using keras python

I need help in understanding CNN. 我需要了解CNN的帮助。

model = keras.models.Sequential()

model.add(convolutional.Convolution2D(32, (8,8), activation='relu', strides=(4, 4), padding='same',input_shape=(80,80,4)))

model.add(convolutional.Convolution2D(64, (4, 4), activation='relu', strides=(2, 2), padding='same'))

model.add(convolutional.Convolution2D(64, (3, 3), activation='relu', strides=(1, 1), padding='same'))

I'm not sure about the output of the first CNN. 我不确定第一个CNN的输出。 I know that it goes over 32 filters, the kernel size is 8x8 and strides 4x4. 我知道它超过了32个过滤器,内核大小为8x8,跨度为4x4。 I also know about this formula on calculating the width: 我也知道有关计算宽度的公式:

W=(W−F+2P)/S+1 W =(W-F + 2P)/ S + 1

W = (80 - 8 + ?? ) / 4 + 1 W =(80-8 + ??)/ 4 + 1

I'm not sure what to put on P - which means padding . 我不确定要在P上加上什么-这意味着填充。 Can you help me understand the size of the output of the first CNN ? 您能帮助我了解第一个CNN输出的大小吗? Also, can you help me understand why the filters are changed from 32 to 64 after the first step? 另外,您能否帮助我理解为什么第一步之后将过滤器从32更改为64? Is there any good reason for that? 有什么充分的理由吗?

The parameter padding=same means that your input will be padded so that the output of this layer has the same length as the original input. 参数padding=same表示将填充您的输入,以便该层的输出与原始输入的长度相同。 Adding padding to the input just means adding pixels (commonly of value 0) around the outside edges of the input. 在输入中添加填充仅表示在输入的外部边缘周围添加像素(通常值为0)。 You want to do this so that the specified filters are able to convolve the entire input without missing some of the pixel values on the edges. 您希望这样做,以便指定的滤镜能够对整个输入进行卷积而不会丢失边缘上的某些像素值。 More details on the use of this parameter in a Keras conv layer can be found in the Keras docs here . 在一个Keras CONV层使用此参数的更多细节可以在Keras文档中找到这里

To see the output size of these layers, run model.summary() . 要查看这些图层的输出大小,请运行model.summary() This will show you the output size of each layer in your model. 这将显示模型中每个图层的输出大小。

Lastly, the filter size is chosen/set arbitrarily, but generally speaking, filters usually increase in size in later layers as the model becomes deeper and more complex. 最后,过滤器的大小是任意选择/设置的,但是通常来说,随着模型变得更深,更复杂,过滤器的大小通常会在后面的层中增加。 I have a video on CNNs that explain these concepts and show the process visually, which you may find useful. 我有一段关于CNN视频 ,解释了这些概念并直观地显示了该过程,您可能会发现这很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM