> For the complete documentation index, see [llms.txt](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-si-men-ke-juan-ji-shen-jing-wang-luo-convolutional-neural-networks/convolutional-neural-networks/foundations-of-convolutional-neural-networks/17-dan-ceng-juan-ji-wang-luo-ff08-one-layer-of-a-convolutional-network.md).

# 1.7 单层卷积网络（One layer of a convolutional network）

卷积神经网络的单层结构如下所示：

![](/files/-Le0cdLFpDYuRarJ42l7)

相比之前的卷积过程，CNN的单层结构多了激活函数$$ReLU$$和偏移量$$b$$。整个过程与标准的神经网络单层结构非常类似：

$$
Z^{\[l]}=W^{\[l]}A^{\[l-1]}+b^{\[l]}
$$

$$
A^{\[l]}=g^{\[l]}(Z^{\[l]})
$$

卷积运算对应着上式中的乘积运算，滤波器组数值对应着权重$$W^{\[l]}$$，所选的激活函数为$$ReLU$$

每个滤波器组有3x3x3=27个参数，还有1个偏移量$$b$$，则每个滤波器组有27+1=28个参数，两个滤波器组总共包含28x2=56个参数。选定滤波器组后，参数数目与输入图片尺寸无关。所以不存在由于图片尺寸过大，造成参数过多的情况，这就是卷积神经网络的一个特征，叫作“**避免过拟合**”。例如一张1000x1000x3的图片，标准神经网络输入层的维度将达到3百万，而在CNN中，参数数目只由滤波器组决定，数目相对来说要少得多，这是CNN的优势之一

设层数为$$l$$，CNN单层结构的所有标记符号：

* $$f^{\[l]}$$**= filter size**
* $$p^{\[l]}$$**= padding**
* $$s^{\[l]}$$**= stride**
* $$n\_c^{\[l]}$$**= number of filters**

输入维度为：$$n\_H^{\[l-1]}\times n\_W^{\[l-1]}\times n\_c^{\[l-1]}$$，因为是上一层的激活值\
每个滤波器组维度为：$$f^{\[l]}\times f^{\[l]}\times n\_c^{\[l-1]}$$

权重维度为：$$f^{\[l]}\times f^{\[l]}\times n\_c^{\[l-1]}\times n\_c^{\[l]}$$

偏置维度为：$$1 \times 1\times 1 \times n\_c^{\[l]}$$

输出维度为：$$n\_H^{\[l]}\times n\_W^{\[l]}\times n\_c^{\[l]}$$

其中：

$$
n\_H^{\[l]}=\lfloor \frac{n\_H^{\[l-1]}+2p^{\[l]}-f^{\[l]}}{s^{\[l]}}+1 \rfloor
$$

$$
n\_W^{\[l]}=\lfloor \frac{n\_W^{\[l-1]}+2p^{\[l]}-f^{\[l]}}{s^{\[l]}}+1 \rfloor
$$

如果有$$m$$个样本，进行向量化运算，相应的输出维度为：

$$
m \times n\_H^{\[l]}\times n\_W^{\[l]}\times n\_c^{\[l]}
$$
