第8章現代の畳み込みニューラルネットワーク
8.1.2. AlexNet8.1.2 AlexNet
AlexNet, which employed an 8-layer CNN, won the ImageNet Large Scale Visual Recognition Challenge 2012 by a large margin (Russakovsky et al., 2013). This network showed, for the first time, that the features obtained by learning can transcend manually-designed features, breaking the previous paradigm in computer vision.
英語のヒント
8層のCNNを使ったAlexNetは、ImageNet Large Scale Visual Recognition Challenge 2012で大差をつけて優勝した(Russakovsky et al., 2013)。このネットワークは、学習によって得られた特徴量が、手作業で設計した特徴量を超えうることを初めて示し、コンピュータビジョンのそれまでのパラダイムを打ち破った。
The architectures of AlexNet and LeNet are strikingly similar, as Fig. 8.1.2 illustrates. Note that we provide a slightly streamlined version of AlexNet removing some of the design quirks that were needed in 2012 to make the model fit on two small GPUs.
英語のヒント
図8.1.2が示すように、AlexNetとLeNetの構造は驚くほど似ている。ここでは、2012年にモデルを二つの小さなGPUに収めるために必要だった設計上の癖をいくつか取り除いた、少しすっきりさせた版のAlexNetを示すことに注意してほしい。
Fig. 8.1.2図8.1.2
From LeNet (left) to AlexNet (right).
英語のヒント
LeNet(左)からAlexNet(右)へ。
There are also significant differences between AlexNet and LeNet. First, AlexNet is much deeper than the comparatively small LeNet-5. AlexNet consists of eight layers: five convolutional layers, two fully connected hidden layers, and one fully connected output layer. Second, AlexNet used the ReLU instead of the sigmoid as its activation function. Let’s delve into the details below.
英語のヒント
AlexNetとLeNetのあいだには、大きな違いもある。第一に、AlexNetは比較的小さなLeNet-5よりずっと深い。AlexNetは八つの層からなる。五つの畳み込み層、二つの全結合の隠れ層、一つの全結合の出力層である。第二に、AlexNetは活性化関数として、シグモイドの代わりにReLUを使った。以下でその細部に踏み込もう。
8.1.2.1. Architecture8.1.2.1 構造
In AlexNet’s first layer, the convolution window shape is . Since the images in ImageNet are eight times taller and wider than the MNIST images, objects in ImageNet data tend to occupy more pixels with more visual detail. Consequently, a larger convolution window is needed to capture the object. The convolution window shape in the second layer is reduced to , followed by . In addition, after the first, second, and fifth convolutional layers, the network adds max-pooling layers with a window shape of and a stride of 2. Moreover, AlexNet has ten times more convolution channels than LeNet.
英語のヒント
AlexNetの最初の層では、畳み込みの窓の形状はである。ImageNetの画像はMNISTの画像より高さも幅も8倍あるので、ImageNetのデータの物体は、もっと多くの画素を占め、視覚的な細部も多い傾向がある。そのため、物体をとらえるには、もっと大きな畳み込みの窓が必要になる。2番目の層では畳み込みの窓の形状はに縮められ、その後はが続く。さらに、1番目、2番目、5番目の畳み込み層の後に、ネットワークは窓の形状がでストライドが2の最大プーリング層を加える。また、AlexNetの畳み込みのチャネルはLeNetの10倍ある。
After the final convolutional layer, there are two huge fully connected layers with 4096 outputs. These layers require nearly 1GB model parameters. Because of the limited memory in early GPUs, the original AlexNet used a dual data stream design, so that each of their two GPUs could be responsible for storing and computing only its half of the model. Fortunately, GPU memory is comparatively abundant now, so we rarely need to break up models across GPUs these days (our version of the AlexNet model deviates from the original paper in this aspect).
英語のヒント
最後の畳み込み層の後には、出力が4096の巨大な全結合層が二つある。これらの層には、1GB近いモデルパラメータが必要である。初期のGPUはメモリが限られていたので、元のAlexNetは二重のデータの流れの設計を使い、二つのGPUがそれぞれモデルの半分だけを保存し計算すればよいようにした。幸い、今ではGPUのメモリは比較的豊富なので、最近はモデルを複数のGPUに分ける必要はめったにない(この点で、ここでのAlexNetのモデルは元の論文と異なる)。
8.1.2.2. Activation Functions8.1.2.2 活性化関数
Furthermore, AlexNet changed the sigmoid activation function to a simpler ReLU activation function. On the one hand, the computation of the ReLU activation function is simpler. For example, it does not have the exponentiation operation found in the sigmoid activation function. On the other hand, the ReLU activation function makes model training easier when using different parameter initialization methods. This is because, when the output of the sigmoid activation function is very close to 0 or 1, the gradient of these regions is almost 0, so that backpropagation cannot continue to update some of the model parameters. By contrast, the gradient of the ReLU activation function in the positive interval is always 1 (Section 5.1.2). Therefore, if the model parameters are not properly initialized, the sigmoid function may obtain a gradient of almost 0 in the positive interval, meaning that the model cannot be effectively trained.
英語のヒント
さらに、AlexNetはシグモイド活性化関数を、もっと単純なReLU活性化関数に変えた。一方では、ReLU活性化関数の計算はもっと単純である。たとえば、シグモイド活性化関数に見られる指数関数の演算がない。他方では、ReLU活性化関数は、さまざまなパラメータの初期化の方法を使うときに、モデルの訓練をもっと簡単にする。シグモイド活性化関数の出力が0や1にとても近いとき、そうした領域の勾配はほとんど0になり、逆伝播でモデルのパラメータの一部を更新し続けられなくなるからである。これに対して、正の区間でのReLU活性化関数の勾配はいつも1である(5.1.2節)。したがって、モデルのパラメータが適切に初期化されていないと、シグモイド関数は正の区間でほとんど0の勾配しか得られないことがあり、つまりモデルを効果的に訓練できなくなる。
8.1.2.3. Capacity Control and Preprocessing8.1.2.3 容量の制御と前処理
AlexNet controls the model complexity of the fully connected layer by dropout (Section 5.6), while LeNet only uses weight decay. To augment the data even further, the training loop of AlexNet added a great deal of image augmentation, such as flipping, clipping, and color changes. This makes the model more robust and the larger sample size effectively reduces overfitting. See Buslaev et al. (2020) for an in-depth review of such preprocessing steps.
英語のヒント
class AlexNet(d2l.Classifier):
def __init__(self, lr=0.1, num_classes=10):
super().__init__()
self.save_hyperparameters()
self.net = nn.Sequential(
nn.LazyConv2d(96, kernel_size=11, stride=4, padding=1),
nn.ReLU(), nn.MaxPool2d(kernel_size=3, stride=2),
nn.LazyConv2d(256, kernel_size=5, padding=2), nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.LazyConv2d(384, kernel_size=3, padding=1), nn.ReLU(),
nn.LazyConv2d(384, kernel_size=3, padding=1), nn.ReLU(),
nn.LazyConv2d(256, kernel_size=3, padding=1), nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2), nn.Flatten(),
nn.LazyLinear(4096), nn.ReLU(), nn.Dropout(p=0.5),
nn.LazyLinear(4096), nn.ReLU(),nn.Dropout(p=0.5),
nn.LazyLinear(num_classes))
self.net.apply(d2l.init_cnn)We construct a single-channel data example with both height and width of 224 to observe the output shape of each layer. It matches the AlexNet architecture in Fig. 8.1.2.
英語のヒント
各層の出力の形状を観察するため、高さも幅も224の、一つのチャネルのデータ事例を作る。それは図8.1.2のAlexNetの構造と一致する。
AlexNet().layer_summary((1, 1, 224, 224))Conv2d output shape: torch.Size([1, 96, 54, 54])
ReLU output shape: torch.Size([1, 96, 54, 54])
MaxPool2d output shape: torch.Size([1, 96, 26, 26])
Conv2d output shape: torch.Size([1, 256, 26, 26])
ReLU output shape: torch.Size([1, 256, 26, 26])
MaxPool2d output shape: torch.Size([1, 256, 12, 12])
Conv2d output shape: torch.Size([1, 384, 12, 12])
ReLU output shape: torch.Size([1, 384, 12, 12])
Conv2d output shape: torch.Size([1, 384, 12, 12])
ReLU output shape: torch.Size([1, 384, 12, 12])
Conv2d output shape: torch.Size([1, 256, 12, 12])
ReLU output shape: torch.Size([1, 256, 12, 12])
MaxPool2d output shape: torch.Size([1, 256, 5, 5])
Flatten output shape: torch.Size([1, 6400])
Linear output shape: torch.Size([1, 4096])
ReLU output shape: torch.Size([1, 4096])
Dropout output shape: torch.Size([1, 4096])
Linear output shape: torch.Size([1, 4096])
ReLU output shape: torch.Size([1, 4096])
Dropout output shape: torch.Size([1, 4096])
Linear output shape: torch.Size([1, 10])