第 10 章 · 卷积网络
Understanding Deep Learning — Convolutional networks
Chapters 2–9 introduced the supervised learning pipeline for deep neural networks. However, these chapters only considered fully connected networks with a single path from input to output. Chapters 10–13 introduce more specialized network components with sparser connections, shared weights, and parallel processing paths.
This chapter describes convolutional layers, which are mainly used for processing image data.
第 2–9 章介绍了深层神经网络的监督学习流程。然而,这些章节仅考虑了具有从输入到输出单一路径的全连接网络。第 10–13 章介绍了具有更稀疏连接、共享权重和平行处理路径的更专门化网络组件。本章介绍了卷积层,它们主要用于处理图像数据。
Images have three properties that suggest the need for specialized model architecture. First, they are high-dimensional. A typical image for a classification task contains 224 × 224 RGB values (i.e., 150,528 input dimensions). Hidden layers in fully connected networks are generally larger than the input size, so even for a shallow network, the number of weights would exceed 150, 5282, or 22 billion. This poses obvious practical problems in terms of the required training data, memory, and computation.
Second, nearby image pixels are statistically related. However, fully connected networks have no notion of “nearby” and treat the relationship between every input equally. If the pixels of the training and test images were randomly permuted in the same way, the network could still be trained with no practical difference. Third, the interpretation of an image is stable under geometric transformations. An image of a tree is still an image of a tree if we shift it leftwards by a few pixels. However, this shift changes every input to the network. Hence, a fully connected model must learn the patterns of pixels that signify a tree separately at every position, which is clearly inefficient.
Convolutional layers process each local image region independently, using parameters shared across the whole image. They use fewer parameters than fully connected layers, exploit the spatial relationships between nearby pixels, and don’t have to re-learn the interpretation of the pixels at every position. A network predominantly consisting of convolutional layers is known as a convolutional neural network or CNN.
图像具有三个特性,表明需要专门的模型架构。首先,它们是高维的。分类任务中典型图像包含 224 × 224 个 RGB 值(即 150,528 个输入维度)。全连接网络中的隐藏层通常大于输入规模,因此即使是浅层网络,权重数量也会超过 150, 5282, 或 220 亿。这在所需训练数据、内存和计算方面带来了明显的实际问题。
其次,邻近的图像像素在统计上相关。然而,全连接网络没有“邻近”的概念,并且平等地对待每个输入之间的关系。如果以相同方式随机置换训练图像和测试图像的像素,网络仍然可以训练,并且没有实际差异。第三,图像的解读在几何变换下保持稳定。如果我们将一张树的图像向左平移几个像素,它仍然是一张树的图像。然而,这种平移会改变网络的每个输入。因此,全连接模型必须在每个位置分别学习表示树的像素模式,这显然效率低下。
卷积层独立处理每个局部图像区域,使用整幅图像共享的参数。它们比全连接层使用更少的参数,利用邻近像素之间的空间关系,并且无需在每个位置重新学习像素的含义。主要由卷积层构成的网络称为卷积神经网络或 CNN。
We argued above that some properties of images (e.g., tree texture) are stable under transformations. In this section, we make this idea more mathematically precise. A
function f[ x ] of an image x is invariant to a transformation t[ x ] if:
我们在上文论证了,图像的某些属性(例如树木纹理)在变换下保持稳定。在本节中,我们使这一想法在数学上更加精确。一个
函数 f[ x ] 对于图像 x 在变换 t[ x ] 下具有不变性,如果:

In other words, the output of the function f[ x ] is the same regardless of the transformation t[ x ]. Networks for image classification should be invariant to geometric transformations of the image (figure 10.1a–b). The network f[ x ] should identify an image as containing the same object, even if it has been translated, rotated, flipped, or warped.
A function f[ x ] of an image x is equivariant or covariant to a transformation t[ x ] if:
换言之,函数 f[ x ] 的输出,无论变换 t[ x ] 如何,都相同。用于图像分类的网络应对图像的几何变换具有不变性(图 10.1a–b)。网络 f[ x ] 应识别出图像中包含同一对象,即使该图像经过了平移、旋转、翻转或扭曲。
图像 x 的函数 f[ x ] 相对于变换 t[ x ] 是等变的或协变的,如果:
In other words, f[ x ] is equivariant to the transformation t[ x ] if its output changes in the same way under the transformation as the input.
Networks for per-pixel image segmentation should be equivariant to transformations (figure 10.1c–f); if the image is translated, rotated, or flipped, the network f[ x ] should return a segmentation that has been transformed in the same way.
换句话说, f[ x ] 对变换 t[ x ] 具有等变性,如果其输出在变换下的变化方式与输入相同。逐像素图像分割网络应对变换具有等变性(图 10.1c–f);如果图像被平移、旋转或翻转,网络 f[ x ] 应回报一个以相同方式变换后的分割结果。

Convolutional networks consist of a series of convolutional layers, each of which is equivariant to translation. They also typically include pooling mechanisms that induce partial invariance to translation. For clarity of exposition, we first consider convolutional networks for 1D data, which are easier to visualize. In section 10.3, we progress to 2D convolution, which can be applied to image data.
卷积网络由一系列卷积层组成,每一层都对平移具有等变性。它们通常还包含池化机制,这些机制会诱导出对平移的部分不变性。为了表述清晰,我们先考虑用于一维数据的卷积网络,因为它们更易于可视化。在 10.3 节中,我们将进一步讨论二维卷积,它可以应用于图像数据。
Convolutional layers are network layers based on the convolution operation. In 1D, a convolution transforms an input vector x into an output vector z so that each output zi is a weighted sum of nearby inputs. The same weights are used at every position and are collectively called the convolution kernel or filter. The size of the region over which inputs are combined is termed the kernel size. For a kernel size of three, we have:
where ω=[ω1, ω2, ω3]T is the kernel (figure 10.2). 1 Notice that the convolution operation is equivariant with respect to translation. If we translate the input x, then the corresponding output z is translated in the same way.
卷积层是基于卷积操作的网络层。在一维情况下,卷积将输入向量 x 转换为输出向量 z,使得每个输出 zi 都是邻近输入的加权和。每个位置使用相同的权重,这些权重统称为卷积核或滤波器。用于组合输入的区域的尺寸称为核大小。对于核大小为 3 的情况,我们有:
其中 ω=[ω1, ω2, ω3]T 是核(图 10.2)。 1 请注意,卷积操作运算对平移具有等变性。如果我们将输入 x 平移,则对应的输出 z 也会以相同方式平移。

Equation 10.3 shows that each output is computed by taking a weighted sum of the previous, current, and subsequent positions in the input. This begs the question of how to deal with the first output (where there is no previous input) and the final output (where there is no subsequent input).
There are two common approaches. The first is to pad the edges of the inputs with new values and proceed as usual. Zero-padding assumes the input is zero outside its valid range (figure 10.2c). Other possibilities include treating the input as circular or reflecting it at the boundaries. The second approach is to discard the output positions where the kernel exceeds the range of input positions. These valid convolutions have the advantage of introducing no extra information at the edges of the input. However, they have the disadvantage that the representation decreases in size.
公式 10.3 表明,每个输出都是通过对输入中前一个、当前和后续位置的加权和来计算的。这引发了一个问题:如何处理第一个输出(没有前一个输入)和最后一个输出(没有后续输入)。
有两种常见方法。第一种是用新值填充输入的边界,然后照常进行。零填充假设输入在其有效范围之外为零(图 10.2c)。其他可能性包括将输入视为循环的,或在边界处对其进行反射。第二种方法是丢弃卷积核超出输入位置范围的输出位置。这些有效卷积的优点是不会在输入边界处引入额外信息。然而,它们的缺点是表示的尺寸会减小。
In the example above, each output was a sum of the nearest three inputs. However, this is just one of a larger family of convolution operations, the members of which are
distinguished by their stride, kernel size, and dilation rate. When we evaluate the output at every position, we term this a stride of one. However, it is also possible to shift the kernel by a stride greater than one. If we have a stride of two, we create roughly half the number of outputs (figure 10.3a–b). The kernel size can be increased to integrate over a larger area (figure 10.3c). However, it typically remains an odd number so that it can be centered around the current position. Increasing the kernel size has the disadvantage of requiring more weights. This leads to the idea of dilated or atrous convolutions, in which the kernel values are interspersed with zeros. For example, we can turn a kernel of size five into a dilated kernel of size three by setting the second and fourth elements to zero. We still integrate informa-
在上面的示例中,每个输出都是最近的三个输入之和。然而,这只是更大的一类卷积运算中的一种,其成员
由它们的步幅、卷积核大小和膨胀率来区分。当我们在每个位置计算输出时,我们称这种步幅为 1。然而,也可以以大于 1 的步幅移动卷积核。如果步幅为 2,则生成的输出数量大约减半(图 10.3a–b)。可以增大卷积核大小,以便在更大区域上进行积分(图 10.3c)。不过,它通常保持为奇数,以便以当前位置为中心。增大卷积核大小的缺点是需要更多权重。这引出了膨胀或空洞卷积的思想,其中卷积核值之间穿插零。例如,我们可以通过将第二个和第四个元素设为零,将大小为五的卷积核转换为大小为三的膨胀卷积核。我们仍然整合来自
tion from a larger input region but only require three weights to do this (figure 10.3d). The dilation rate is the number of zeros interspersed between the weights plus one.
A convolutional layer computes its output by convolving the input, adding a bias β, and passing each result through an activation function a[•]. With kernel size three, stride one, and dilation rate one, the ith hidden unit hi would be computed as:
where the bias β and kernel weights ω1, ω2, ω3 are trainable parameters, and (with zeropadding) we treat the input x as zero when it is out of the valid range. This is a special case of a fully connected layer that computes the ith hidden unit as: If there are D inputs x• and D hidden units h•, this fully connected layer would have D2 weights ω•• and D biases β•. The convolutional layer only uses three weights and one bias. A fully connected layer can reproduce this exactly if most weights are set to zero
卷积层通过对输入进行卷积、加上偏差 β,并将每个结果通过激活函数 a[•] 来计算其输出。在卷积核大小为三、步幅为一、膨胀率为一的情况下, ith 隐藏单元 hi 的计算方式为:
其中偏差 β 和核权重 ω1, ω2, ω3 是可训练参数,并且(采用零填充)当输入 x 超出有效范围时,我们将其视为零。这是计算 ith 隐藏单元的全连接层的特例:如果有 D 个输入 x• 和 D 个隐藏单元 h•,这个全连接层会有 D2 个权重 ω•• 和 D 个偏差 β•。卷积层只使用三个权重和一个偏差。如果大多数权重被设置为零
and others are constrained to be identical (figure 10.4).
而其余权重则被约束为相同(图 10.4)。
If we only apply a single convolution, information will likely be lost; we are averaging nearby inputs, and the ReLU activation function clips results that are less than zero. Hence, it is usual to compute several convolutions in parallel. Each convolution produces a new set of hidden variables, termed a feature map or channel.
如果只应用单个卷积,信息很可能会丢失;我们是在对邻近输入取平均,并且 ReLU 激活函数会截断小于零的结果。因此,通常会并行计算多个卷积。每个卷积都会产生一组新的隐藏变量,称为特征图或通道。

Figure 10.5a–b illustrates this with two convolution kernels of size three and with zero-padding. The first kernel computes a weighted sum of the nearest three pixels, adds a bias, and passes the results through the activation function to produce hidden units h1 to h6. These comprise the first channel. The second kernel computes a different weighted sum of the nearest three pixels, adds a different bias, and passes the results through the activation function to create hidden units h7 to h12. These comprise the second channel. In general, the input and the hidden layers all have multiple channels (figure 10.5c). If the incoming layer has Ci channels and we select a kernel size K per channel, the hidden units in each output channel are computed as a weighted sum over all Ci channels and K kernel entries using a weight matrix Ω ∈RCi×K and one bias. Hence, if there are Co
图 10.5a–b 使用两个大小为 3 的卷积核和零填充对此进行了说明。第一个卷积核计算最近三个像素的加权和,加上偏差,并将结果通过激活函数,以生成隐藏单元 h1 至 h6。这些构成第一个通道。第二个卷积核计算最近三个像素的另一个加权和,加上另一个偏差,并将结果通过激活函数,以创建隐藏单元 h7 至 h12。这些构成第二个通道。

channels in the next layer, then we need Ω ∈RCi×Co×K weights and β∈RCo biases.
Chapter 4 described deep networks, which consisted of a sequence of fully connected layers. Similarly, convolutional networks comprise a sequence of convolutional layers. The receptive field of a hidden unit in the network is the region of the original input that feeds into it. Consider a convolutional network where each convolutional layer has kernel size three. The hidden units in the first layer take a weighted sum of the three closest inputs, so have receptive fields of size three. The units in the second layer take a weighted sum of the three closest positions in the first layer, which are themselves weighted sums of three inputs. Hence, the hidden units in the second layer have a receptive field of size five. In this way, the receptive field of units in successive layers increases, and information from across the input is gradually integrated (figure 10.6).
第 4 章描述了由一系列全连接层组成的深度网络。类似地,卷积网络由一系列卷积层组成。网络中隐藏单元的感受野是输入到该单元的原始输入区域。考虑一个卷积网络,其中每个卷积层的核大小均为 3。第一层中的隐藏单元对三个最接近的输入进行加权求和,因此具有大小为 3 的感受野。第二层中的单元对第一层中三个最接近的位置进行加权求和,而这些位置本身又是三个输入的加权和。因此,第二层中的隐藏单元具有大小为 5 的感受野。通过这种方式,连续各层中单元的感受野逐渐增大,来自整个输入的信息被逐步整合(图 10.6)。
We now apply a convolutional network to the MNIST-1D data (see figure 8.1). The input x is a 40D vector, and the output f is a 10D vector that is passed through a softmax layer to produce class probabilities. We use a network with three hidden layers (figure 10.7). The fifteen channels of the first hidden layer H 1 are each computed using a kernel size of three and a stride of two with “valid” padding, giving nineteen spatial positions. The second hidden layer H 2 is also computed using a kernel size of three, a stride of two, and “valid” padding. The third hidden layer is computed similarly. At this stage, the representation has four spatial positions and fifteen channels. These values are reshaped into a vector of size sixty, which is mapped by a fully connected layer to the ten output activations. This network was trained for 100,000 steps using SGD without momentum, a learning rate of 0.01, and a batch size of 100 on a dataset of 4,000 examples. We compare this to a fully connected network with the same number of layers and hidden units (i.e., three hidden layers with 285, 135, and 60 hidden units, respectively). The convolutional network has 2,050 parameters, and the fully connected network has 59,065 parameters. By the logic of figure 10.4, the convolutional network is a special case of the fully connected one. The latter has enough flexibility to replicate the former exactly. Figure 10.8 shows both models fit the training data perfectly. However, the test error for the convolutional
我们现在将卷积网络应用于 MNIST-1D 数据(见图 8.1)。输入 x 是一个 40 维向量,输出 f 是一个 10 维向量,该向量经过 Softmax 层以产生类别概率。我们使用一个包含三个隐藏层的网络(图 10.7)。第一隐藏层 H 1 的十五个通道分别采用核大小为 3、步长为 2 且使用“valid”填充的方式计算,得到 19 个空间位置。第二隐藏层 H 2 也采用核大小为 3、步长为 2 且使用“valid”填充的方式计算。第三隐藏层的计算方式类似。在此阶段,表示具有 4 个空间位置和 15 个通道。这些值被重塑为大小为 60 的向量,然后由全连接层映射到 10 个输出激活。一个具有相同层数和隐藏单元数的全连接网络(即三个隐藏层分别包含 285、 135 和 60 个隐藏单元)。卷积网络有 2,050 个参数,全连接网络有 59,065 个参数。根据图 10.4 的逻辑,卷积网络是全连接网络的特例一个。后者具有足够的灵活性,可以完全复现前者。图 10.8 显示



network is much less than for the fully connected network.
两个模型都完美拟合了训练数据。然而,卷积网络的测试误差远小于全连接网络。
This discrepancy is probably not due to the difference in the number of parameters; we know overparameterization usually improves performance (section 8.4.1). The likely explanation is that the convolutional architecture has a superior inductive bias (i.e., interpolates between the training data better) because we have embodied some prior knowledge in the architecture; we have forced the network to process each position in the input in the same way. We know that the data were created by starting with a template that is (among other operations) randomly translated, so this is sensible.
The fully connected network has to learn what each digit template looks like at every position. In contrast, the convolutional network shares information across positions and hence learns to identify each category more accurately. Another way of thinking about this is that when we train the convolutional network, we search through a smaller family of input/output mappings, all of which are plausible. Alternatively, the convolutional structure can be considered a regularizer that applies an infinite penalty to most of the solutions that a fully connected network can describe.
这种差异可能不是由于参数数量不同造成的;我们知道过参数化通常会提升性能(第 8.4.1 节)。可能的解释是,卷积架构具有更优的归纳式偏差(即,在训练数据之间更好地进行插值),因为我们在架构中体现了某些先验知识;我们强制网络以相同方式处理输入中的每个位置。我们知道这些数据是通过从一个模板开始并(除其他操作之外)随机平移而创建的,因此这是合理的。
全连接网络必须学习每个数字模板在每个位置上的样子。相比之下,卷积网络跨位置共享信息,因此能够更准确地识别每个类别。另一种理解方式是:当我们训练卷积网络时,我们在一组更小的输入 / 输出映射中进行搜索,而这些映射都是合理的。或者,卷积结构可以被视为一种正则化器,它对全连接网络所能描述的大多数解施加无限惩罚。
The previous section described convolutional networks for processing 1D data.
Such networks can be applied to financial time series, audio, and text. However, convolutional networks are more usually applied to 2D image data. The convolutional kernel is now a 2D object. A 3 × 3 kernel Ω ∈R3×3 applied to a 2D input comprising of elements xij computes a single layer of hidden units hij as: where ωmn are the entries of the convolutional kernel. This is simply a weighted sum over a square 3 × 3 input region. The kernel is translated both horizontally and vertically
上一节介绍了处理一维数据的卷积网络。这类网络可以应用于金融时间序列、音频和文本。然而,卷积网络通常更常用于二维图像数据。卷积核现在是一个二维对象。一个 3 × 3 卷积核 Ω ∈R3×3 应用于由元素 xij 组成的二维输入,计算一层隐藏单元 hij,如下:
across the 2D input (figure 10.9) to create an output at each position. Often the input is an RGB image, which is treated as a 2D signal with three channels (figure 10.10). Here, a 3 × 3 kernel would have 3 × 3 × 3 weights and be applied to the three input channels at each of the 3 × 3 positions to create a 2D output that is the same height and width as the input image (assuming zero-padding). To generate multiple output channels, we repeat this process with different kernel weights and append the results to form a 3D tensor. If the kernel is size K ×K, and there are Ci input channels, each output channel is a weighted sum of Ci ×K ×K quantities plus one bias. It follows
在二维输入上(图 10.9)平移,以在每个位置生成输出。
that to compute Co output channels, we need Ci × Co × K × K weights and Co biases.
每个输出通道是 Ci ×K ×K 个量的加权和再加上一个偏差。因此,要计算 Co 个输出通道,我们需要 Ci × Co × K × K 个权重和 Co 个偏差。

The network in figure 10.7 increased receptive field size by scaling down the representation at each layer using stride two convolutions. We now consider methods for scaling down or downsampling 2D input representations. We also describe methods for scaling them back up (upsampling), which is useful when the output is also an image. Finally, we consider methods to change the number of channels between layers. This is helpful when recombining representations from two branches of a network (chapter 11).
图 10.7 中的网络通过在每一层使用步长为 2 的卷积来缩小表示,从而增大了感受野大小。我们现在考虑缩小或下采样二维输入表示的方法。我们还会描述将它们重新放大(上采样)的方法,当输出也是图像时,这很有用。最后,我们考虑改变层间通道数的方法。这在重新组合网络两个分支的表示时很有帮助(第 11 章)。
There are three main approaches to scaling down a 2D representation. Here, we consider the most common case of scaling down both dimensions by a factor of two. First, we can sample every other position. When we use a stride of two, we effectively apply this method simultaneously with the convolution operation (figure 10.11a).
降低二维表示尺寸主要有三种方法。这里,我们考虑最常见的情况,即将两个维度都缩小一半。首先,我们可以每隔一个位置进行采样。当使用步长为 2 时,我们实际上是在采用这种方式
该方法与卷积运算同时进行(图 10.11a)。
Second, maxpooling retains the maximum of the 2 × 2 input values (figure 10.11b). This induces some invariance to translation; if the input is shifted by one pixel, many of these maximum values remain the same. Finally, mean pooling or average pooling averages the inputs.
For all approaches, we apply downsampling separately to each channel, so the output has half the width and height but the same number of channels.
第二,最大池化保留 2 × 2 个输入值中的最大值(图 10.11b)。这会带来一些平移不变性;如果输入平移一个像素,许多这些最大值保持不变。最后,平均池化或平均池化对输入求平均。对于所有方法,我们对每个通道分别应用下采样,因此输出的宽度和高度都减半,但通道数相同。
将网络层放大至分辨率翻倍的最简单方法,是在每个空间位置将所有通道复制四次(图 10.12a)。第二种方法是最大反池化;这种方法用于此前使用最大池化操作进行下采样的情形,并将数值分配到它们的来源位置(图 10.12b)。第三种方法使用双线性插值,在有采样的点之间填补缺失值(图 10.12c)。第四种方法大致类似于步长为二的下采样。在
The simplest way to scale up a network layer to double the resolution is to duplicate all the channels at each spatial position four times (figure 10.12a). A second method is max unpooling; this is used where we have previously used a max pooling operation for downsampling, and we distribute the values to the positions they originated from (figure 10.12b). A third approach uses bilinear interpolation to fill in the missing values between the points where we have samples. (figure 10.12c). A fourth approach is roughly analogous to downsampling using a stride of two. In that method, there were half as many outputs as inputs, and for kernel size three, each output was a weighted sum of the three closest inputs (figure 10.13a). In transposed convolution, this picture is reversed (figure 10.13c). There are twice as many outputs




as inputs, and each input contributes to three of the outputs. When we consider the associated weight matrix of this upsampling mechanism (figure 10.13d), we see that it is the transpose of the matrix for the downsampling mechanism (figure 10.13b).
作为输入,每个输入对三个输出都有贡献。当我们考虑这种上采样机制的相应权重矩阵(图 10.13d)时,可以看到它是下采样机制的矩阵(图 10.13b)的转置。
Sometimes we want to change the number of channels between one hidden layer and the next without further spatial pooling. This is usually so we can combine the representation with another parallel computation (see chapter 11).
To accomplish this, we apply a convolution with kernel size one.
Each element of the output layer is computed by taking a weighted sum of all the channels at the same position (figure 10.14). We can repeat this multiple times with different weights to generate as many output channels as we need. The associated convolution weights have size 1 × 1 × Ci × Co. Hence, this is known as 1×1 convolution. Combined with a bias and activation function, it is equivalent to running the same fully connected network on the input channels at every position.
有时,我们希望在某个隐藏层与下一个隐藏层之间改变通道数,而不进行进一步的空间池化。这通常是为了将表示与另一个并行计算结合起来(参见第 11 章)。为此,我们应用核大小为 1 的卷积。输出层的每个元素都通过对同一位置的所有通道进行加权求和来计算(图 10.14)。我们可以用不同的权重重复这一操作多次,以生成所需数量的输出通道。相应的卷积权重的大小为 1 × 1 × Ci × Co。因此,这被称为 1×1 卷积。与偏差和激活函数结合后,它等价于在每个位置对输入通道运行同一个全连接网络。
We conclude by describing three computer vision applications. We describe convolutional networks for image classification where the goal is to assign the image to one of a predetermined set of categories. Then we consider object detection, where the goal is to identify multiple objects in an image and find the bounding box around each. Finally, we describe an early system for semantic segmentation where the goal is to assign a label to each pixel according to which object is present.
我们以描述三个计算机视觉应用作结。我们描述用于图像分类的卷积网络,其目标是将图像归入预设类别集合中的某一类。然后我们考虑目标检测,其目标是识别图像中的多个目标并为每个目标找到边界框。最后,我们描述一个早期的语义分割系统,其目标是根据每个像素上存在哪个物体,为每个像素分配标签。
Much of the pioneering work on deep learning in computer vision focused on image classification using the ImageNet dataset (figure 10.15). This contains 1,281,167 training images, 50,000 validation images, and 100,000 test images, and every image is labeled as belonging to one of 1000 possible categories.
Most methods reshape the input images to a standard size; in a typical system, the input x to the network is a 224 × 224 RGB image, and the output is a probability distribution over the 1000 classes. The task is challenging; there are a large number of classes, and they exhibit considerable variation (figure 10.15). In 2011, before deep networks were applied, the state-of-the-art method classified the test images with ∼25% errors for the correct class being in the top five suggestions. Five years later, the best deep learning models eclipsed human performance. In 2012, AlexNet was the first convolutional network to perform well on this task. It consists of eight hidden layers with ReLU activation functions, of which the first five are convolutional and the rest fully connected (figure 10.16). The network starts by downsampling the input using an 11 × 11 kernel with a stride of four to create 96 channels. It then downsamples again using a max pooling layer before applying a 5 × 5 kernel to create 256 channels. There are three more convolutional layers with kernel size 3 × 3,
计算机视觉中许多开创性的深度学习工作都集中于使用 ImageNet 数据集进行图像分类(图 10.15)。该数据集包含 1,281,167 张训练图像、 50,000 张验证图像和 100,000 张测试图像,并且每张图像都带有标签,表示其属于 1000 种可能类别之一。
大多数方法会将输入图像调整为标准尺寸;在典型系统中,网络输入 x 是一张 224 × 224 RGB 图像,输出是 1000 个类别上的概率分布。这项任务具有挑战性;类别数量庞大,并且表现出很大差异(图 10.15)。 2011 年,在深度网络被应用之前,最先进的方法在测试图像分类中,正确类别不在前五个候选类别中的错误率为 ∼25%。五年后,最好的深度学习模型超越了人类表现。 2012 年, AlexNet 是第一个在该任务上表现良好的卷积网络。它由八个带有 ReLU 激活函数的隐藏层组成,其中前五个是卷积层,其余为全连接层(图 10.16)。该网络从




eventually resulting in a 13 × 13 representation with 256 channels. A final max-pooling layer yields a 6 × 6 representation with 256 channels which is resized into a vector of length 9, 216 and passed through three fully connected layers containing 4096, 4096, and 1000 hidden units, respectively. The last layer is passed through the softmax function to output a probability distribution over the 1000 classes. The complete network contains ∼ 60 million parameters, most of which are in the fully connected layers. The dataset size was augmented by a factor of 2048 using (i) spatial transformations and (ii) modifications of the input intensities. At test time, five different cropped and mirrored versions of the image were run through the network, and their predictions
最终得到具有 256 通道的 13 × 13 表示。最后一个最大池化层产生具有 256 通道的 6 × 6 表示,该表示被调整为长度为 9 , 216 的向量,并依次通过包含 4096、 4096 和 1000 个隐藏单元的三个全连接层。最后一层经过 Softmax 函数,输出 1000 个类别上的概率分布。整个网络包含 ∼ 60 百万个参数,其中大多数位于全连接层。数据集规模通过 (i) 空间变换被增广为原来的 2048 倍以及 (ii) 对输入强度的修改。在测试时,将图像的五种不同裁剪和镜像版本通过网络,
averaged. The system was learned using SGD with a momentum coefficient of 0.9 and a batch size of 128. Dropout was applied in the fully connected layers, and an L2 (weight decay) regularizer was used. This system achieved a 16.4% top-5 error rate and a 38.1% top-1 error rate. At the time, this was an enormous leap forward in performance at a task considered far beyond the capabilities of contemporary methods. This result revealed the potential of deep learning and kick-started the modern era of AI research.
The VGG network was also targeted at classification in the ImageNet task and achieved a considerably better performance of 6.8% top-5 error rate and a 23.7% top-1 error rate. This network is similarly composed of a series of interspersed convolutional and max pooling layers, where the spatial size of the representation gradually decreases, but the number of channels increase. These are followed by three fully connected layers (figure 10.17). The VGG network was also trained using data augmentation, weight decay, and dropout. Although there were various minor differences in the training regime, the most important change between AlexNet and VGG was the depth of the network. The latter used
并对其预测结果进行平均。该系统使用动量系数为 0.9、批量大小为 128 的 SGD 进行训练。在全连接层中应用了随机失活,并使用了 L2 (权重衰减)正则化器。该系统实现了 16.4% 的 top-5 错误率和 38.1% 的 top-1 错误率。在当时,这在一项被认为远超当代方法能力范围的任务上实现了巨大的性能飞跃。这一结果揭示了深度学习的潜力,并开启了现代 AI 研究的时代。
VGG 网络同样以 ImageNet 任务中的分类为目标,并取得了显著更好的性能, top-5 错误率为 6.8%, top-1 错误率为 23.7%。该网络同样由一系列交替排列的卷积层和最大池化层组成,其中表示的空间尺寸逐渐减小,但通道数增加。其后是三个全连接层(图 10.17)。 VGG 网络也使用了数据增强、权重衰减和随机失活进行训练。
19 hidden layers and 144 million parameters. The networks in figures 10.16 and 10.17 are depicted at the same scale for comparison. There was a general trend for several years for performance on this task to improve as the depth of the networks increased, and this is evidence that depth is important in neural networks.
19 个隐藏层和 1.44 亿个参数。图 10.16 和图 10.17 中的网络以相同比例绘制,以便比较。多年来,随着网络深度增加,该任务上的性能普遍呈提升趋势,这表明深度在神经网络中很重要。

In object detection, the goal is to identify and localize multiple objects within the image. An early method based on convolutional networks was You Only Look Once, or YOLO for short. The input to the YOLO network is a 448 × 448 RGB image. This is passed through 24 convolutional layers that gradually decrease the representation size using max pooling operations while concurrently increasing the number of channels, similarly to the VGG network. The final convolutional layer is of size 7×7 and has 1024 channels. This is reshaped to a vector, and a fully connected layer maps it to 4096 values. One further fully connected layer maps this representation to the output.
The output values encode which class is present at each of a 7 × 7 grid of locations (figure 10.18a–b). For each location, the output values also encode a fixed number of bounding boxes. Five parameters define each box: the x- and y-positions of the center, the height and width of the box, and the confidence of the prediction (figure 10.18c). The confidence estimates the overlap between the predicted and ground truth bounding boxes. The system is trained using momentum, weight decay, dropout, and data augmentation.
在目标检测中,目标是识别并定位图像中的多个目标。一种早期的基于卷积网络的方法是只看一次,简称 YOLO。 YOLO 网络的输入是一张 448 × 448 RGB 图像。该图像会经过 24 个卷积层,这些层通过最大池化操作逐渐减小表示尺寸,同时增加通道数,类似于 VGG 网络。最后一个卷积层的尺寸为 7×7,具有 1024 个通道。这会被重塑为一个向量,然后由一个全连接层将其映射为 4096 个值。再经过一个全连接层,将该表示映射到输出。
输出值编码了 7 × 7 位置网格中每个位置存在的类别(图 10.18a–b)。对于每个位置,输出值还编码了固定数量的边界框。五个参数定义每个框:中心的 x 和 y 位置、框的高度和宽度,以及预测的置信度(图 10.18c)。置信度估计预测边界框与真值边界框之间的重叠。该系统使用动量、权重衰减、随机失活和数据增强进行训练。采用迁移学习;该网络最初在 ImageNet 分类任务上训练,然后针对目标检测进行微调。
Transfer learning is employed; the network is initially trained on the ImageNet classification task and is then fine-tuned for object detection.
After the network is run, a heuristic process is used to remove rectangles with low confidence and to suppress predicted bounding boxes that correspond to the same object so only the most confident one is retained.
网络运行后,会采用启发式过程移除置信度较低的矩形,并抑制对应同一对象的预测边界框,从而只保留置信度最高的一个。

The goal of semantic segmentation is to assign a label to each pixel according to the object that it belongs to or no label if that pixel does not correspond to anything in the training database. An early network for semantic segmentation is depicted in figure 10.19. The input is a 224 × 224 RGB image, and the output is a 224 × 224 × 21 array that contains the probability of each of 21 possible classes at each position.
语义分割的目标是根据每个像素所属的对象为其分配标签;如果该像素不对应训练数据库中的任何对象,则不分配标签。图 10.19 展示了一个早期的语义分割网络。输入是一张 224 × 224 RGB 图像,输出是一个 224 × 224 × 21 数组,其中包含每个位置上 21 个可能类别中每个类别的概率。
The first part of the network is a smaller version of VGG (figure 10.17) that contains thirteen rather than sixteen convolutional layers and downsizes the representation to size 14 × 14. There is then one more max pooling operation, followed by two fully connected layers that map to two 1D representations of size 4096. These layers do not represent spatial position but instead, combine information from across the whole image. Here, the architecture diverges from VGG. Another fully connected layer reconstitutes the representation into 7 × 7 spatial positions and 512 channels. This is followed
网络的第一部分是 VGG 的较小版本(图 10.17),包含十三个而不是十六个卷积层,并将表示缩小到尺寸 14 × 14。随后进行一次最大池化操作,接着是两个全连接层,将表示映射为两个大小为 4096 的一维表示。这些层不表示空间位置,而是整合整幅图像的信息。在这里,该架构与 VGG 不同。另一个全连接层将表示重新构建为 7 × 7 个空间位置和 512 个通道。随后是

by a series of max unpooling layers (see figure 10.12b) and deconvolution layers. These are transposed convolutions (see figure 10.13) but in 2D and without the upsampling. Finally, there is a 1 × 1 convolution to create 21 channels representing the possible classes and a softmax operation at each spatial position to map the activations to class probabilities. The downsampling side of the network is sometimes referred to as an encoder, and the upsampling side as a decoder, so networks of this type are sometimes called encoder-decoder networks or hourglass networks due to their shape.
The final segmentation is generated using a heuristic method that greedily searches for the class that is most represented and infers its region, taking into account the probabilities but also encouraging connectedness. Then the next most-represented class is added where it dominates at the remaining unlabeled pixels. This continues until there is insufficient evidence to add more (figure 10.20).
一系列最大反池化层(见图 10.12b)和反卷积层。它们是转置卷积(见图 10.13),但为二维形式且没有上采样。最后,有一个 1 × 1 卷积,用于创建 21 个表示可能类别的通道,并在每个空间位置执行 Softmax 操作,将激活值映射为类别概率。网络的下采样侧有时被称为编码器,上采样侧则被称为解码器,因此这类网络有时因其形状而被称为编码器 - 解码器网络或沙漏网络。
最终分割结果通过一种启发式方法生成:贪婪地搜索最具代表性的类别,并推断其区域,同时考虑概率并鼓励连通性。然后,在剩余未标记像素中,加入下一个最具代表性且占主导地位的类别。这一过程持续进行,直到没有足够证据添加更多类别(图 10.20)。
In convolutional layers, each hidden unit is computed by taking a weighted sum of the nearby inputs, adding a bias, and applying an activation function. The weights and the bias are the same at every spatial position, so there are far fewer parameters than in a fully connected network, and the number of parameters doesn’t increase with the input image size. To ensure that information is not lost, this operation is repeated with
在卷积层中,每个隐藏单元是通过对邻近输入进行加权求和、加上偏差并应用激活函数来计算的。权重和偏差在每个空间位置都相同,因此参数远少于全连接网络,并且参数数量不会随输入图像尺寸而增加。为确保信息不会丢失,该操作会使用

different weights and biases to create multiple channels at each spatial position.
Typical convolutional networks consist of convolutional layers interspersed with layers that downsample by a factor of two. As a data example passes through the network, the spatial dimensions usually decrease by factors of two, and the channels increase by factors of two. At the end of the network, there are typically one or more fully connected layers that integrate information from across the entire input and create the desired output. If the output is an image, a mirrored “decoder” upsamples back to the original size.
The translational equivariance of convolutional layers imposes a useful inductive bias that increases performance for image-based tasks relative to fully connected networks. We described image classification, object detection, and semantic segmentation networks. Image classification performance was shown to improve as the network became deeper. However, subsequent experiments showed that increasing the network depth indefinitely doesn’t continue to help; after a certain depth, the system becomes difficult to train. This is the motivation for residual connections, which are the topic of the next chapter.
不同的权重和偏差在每个空间位置创建多个通道。
典型的卷积网络由卷积层和以 2 为因子进行下采样的层交替组成。当数据样本通过网络时,空间维度通常以 2 为因子减小,通道数通常以 2 为因子增加。在网络末尾,通常有一个或多个全连接层,用于整合来自整个输入的信息并生成期望的输出。如果输出是图像,则镜像的“解码器”会将其上采样回原始尺寸。
卷积层的平移等变性施加了一种有用的归纳式偏差,相对于全连接网络提高了基于图像的任务的性能。我们描述了图像分类、目标检测和语义分割网络。研究表明,随着网络变得更深,图像分类性能会提高。然而,后续实验表明,无限增加网络深度并不会持续有所帮助;达到一定深度后,系统变得难以训练。这正是残差连接的动机,残差连接是下一章的主题。
Convolutional networks:
ImageNet Challenge:
Types of convolutional layers:
Downsampling and upsampling:

Figure 10.21 ImageNet performance. Each circle represents a different published model. Blue circles represent models that were state-of-the-art. cussed in this book are also highlighted. The AlexNet and VGG networks were remarkable for their time but are now far from state of the art. ResNet-200 and DenseNet are discussed in chapter 11. ImageGPT, ViT, SWIN, and DaViT are discussed in chapter 12. Adapted from https://paperswithcode.com/sota/imageclassification-on-imagenet. an L∞ norm to the hidden units that are to be pooled. This led to applying other Lk norms Appendix B.3.2 (Springenberg et al., 2015; Sainath et al., 2013), although these require more computation and Vector norms are not widely used. Zhang (2019) introduced max-blur-pooling, in which a low-pass filter is applied before downsampling to prevent aliasing, and showed that this improves generalization over translation of the inputs and protects against adversarial attacks (see section 20.4.6). Shi et al. (2016) introduced PixelShuffle, which used convolutional filters with a stride of 1/s to scale up 1D signals by a factor of s. used to create the outputs, and the ones that fall between positions are discarded. This can be implemented by multiplying the number of channels in the kernel by a factor of s, where the sth output position is computed from just the sth subset of channels. This can be trivially extended to 2D convolution, which requires s2 channels.
Convolution in 1D and 3D:

Invariance and equivariance:
初始化和正则化:卷积网络通常使用 Xavier 初始化(Glorot & Bengio, 2010)或 He 初始化(He
Initialization and regularization:
Adaptive Kernels:
Object detection and semantic segmentation:
Visualizing Convolutional Networks:

