第8章現代の畳み込みニューラルネットワーク
8.6.5. ResNeXt8.6.5 ResNeXt
One of the challenges one encounters in the design of ResNet is the trade-off between nonlinearity and dimensionality within a given block. That is, we could add more nonlinearity by increasing the number of layers, or by increasing the width of the convolutions. An alternative strategy is to increase the number of channels that can carry information between blocks. Unfortunately, the latter comes with a quadratic penalty since the computational cost of ingesting channels and emitting channels is proportional to (see our discussion in Section 7.4).
英語のヒント
ResNetの設計で直面する難題の一つは、あるブロックの中での非線形性と次元とのトレードオフである。つまり、層の数を増やすか、畳み込みの幅を広げることで、非線形性を増やせる。もう一つの戦略は、ブロックのあいだで情報を運べるチャネルの数を増やすことである。残念ながら、後者には2乗の代償が伴う。チャネルを取り込んでチャネルを出す計算の費用はに比例するからである(7.4節での議論を参照)。
We can take some inspiration from the Inception block of Fig. 8.4.1 which has information flowing through the block in separate groups. Applying the idea of multiple independent groups to the ResNet block of Fig. 8.6.3 led to the design of ResNeXt (Xie et al., 2017). Different from the smorgasbord of transformations in Inception, ResNeXt adopts the same transformation in all branches, thus minimizing the need for manual tuning of each branch.
英語のヒント
図8.4.1のInceptionブロックから着想を得られる。そこでは、情報はブロックの中を別々のグループに分かれて流れる。複数の独立したグループという考えを図8.6.3のResNetブロックに当てはめたことが、ResNeXt(Xie et al., 2017)の設計につながった。Inceptionのさまざまな変換の寄せ集めとは違って、ResNeXtはすべての枝で同じ変換を採用し、それによって各枝を手作業で調整する必要を最小にする。
Fig. 8.6.5図8.6.5
The ResNeXt block. The use of grouped convolution with groups is times faster than a dense convolution. It is a bottleneck residual block when the number of intermediate channels is less than .
英語のヒント
ResNeXtブロック。個のグループによるグループ化畳み込みを使うと、密な畳み込みより倍速い。中間のチャネルの数がより少ないとき、これはボトルネック残差ブロックになる。
Breaking up a convolution from to channels into one of groups of size generating outputs of size is called, quite fittingly, a grouped convolution. The computational cost (proportionally) is reduced from to , i.e., it is times faster. Even better, the number of parameters needed to generate the output is also reduced from a matrix to smaller matrices of size , again a times reduction. In what follows we assume that both and are divisible by .
英語のヒント
チャネルからチャネルへの畳み込みを、大きさの個のグループに分け、大きさの出力を個生成するようにすることを、まさにふさわしい名前だが、グループ化畳み込みと呼ぶ。計算の費用は(比例的に)からに減る。つまり倍速くなる。さらによいことに、出力を生成するのに必要なパラメータの数も、の行列一つから、大きさの小さな行列個へと減り、やはり分の1になる。以下では、とがどちらもで割り切れると仮定する。
The only challenge in this design is that no information is exchanged between the groups. The ResNeXt block of Fig. 8.6.5 amends this in two ways: the grouped convolution with a kernel is sandwiched in between two convolutions. The second one serves double duty in changing the number of channels back. The benefit is that we only pay the cost for kernels and can make do with an cost for kernels. Similar to the residual block implementation in Section 8.6.2, the residual connection is replaced (thus generalized) by a convolution.
英語のヒント
The right-hand figure in Fig. 8.6.5 provides a much more concise summary of the resulting network block. It will also play a major role in the design of generic modern CNNs in Section 8.8. Note that the idea of grouped convolutions dates back to the implementation of AlexNet (Krizhevsky et al., 2012). When distributing the network across two GPUs with limited memory, the implementation treated each GPU as its own channel with no ill effects.
英語のヒント
図8.6.5の右側の図は、こうしてできるネットワークのブロックをずっと簡潔にまとめている。これは、8.8節での汎用的な現代のCNNの設計でも大きな役割を果たす。グループ化畳み込みの考えは、AlexNetの実装(Krizhevsky et al., 2012)にさかのぼることに注意してほしい。メモリの限られた二つのGPUにネットワークを分けたとき、その実装は各GPUをそれ自体のチャネルとして扱ったが、悪影響はなかった。
The following implementation of the
ResNeXtBlock class takes as argument groups (), with bot_channels () intermediate (bottleneck) channels. Lastly, when we need to reduce the height and width of the representation, we add a stride of by setting use_1x1conv=True, strides=2.英語のヒント
以下の
ResNeXtBlockクラスの実装は、引数としてグループ数groups()と、中間の(ボトルネックの)チャネル数bot_channels()をとる。最後に、表現の高さと幅を減らす必要があるときは、use_1x1conv=True, strides=2と設定してストライドを加える。class ResNeXtBlock(nn.Module): #@save
"""The ResNeXt block."""
def __init__(self, num_channels, groups, bot_mul, use_1x1conv=False,
strides=1):
super().__init__()
bot_channels = int(round(num_channels * bot_mul))
self.conv1 = nn.LazyConv2d(bot_channels, kernel_size=1, stride=1)
self.conv2 = nn.LazyConv2d(bot_channels, kernel_size=3,
stride=strides, padding=1,
groups=bot_channels//groups)
self.conv3 = nn.LazyConv2d(num_channels, kernel_size=1, stride=1)
self.bn1 = nn.LazyBatchNorm2d()
self.bn2 = nn.LazyBatchNorm2d()
self.bn3 = nn.LazyBatchNorm2d()
if use_1x1conv:
self.conv4 = nn.LazyConv2d(num_channels, kernel_size=1,
stride=strides)
self.bn4 = nn.LazyBatchNorm2d()
else:
self.conv4 = None
def forward(self, X):
Y = F.relu(self.bn1(self.conv1(X)))
Y = F.relu(self.bn2(self.conv2(Y)))
Y = self.bn3(self.conv3(Y))
if self.conv4:
X = self.bn4(self.conv4(X))
return F.relu(Y + X)Its use is entirely analogous to that of the
ResNetBlock discussed previously. For instance, when using (use_1x1conv=False, strides=1), the input and output are of the same shape. Alternatively, setting use_1x1conv=True, strides=2 halves the output height and width.英語のヒント
その使い方は、前に論じた
ResNetBlockとまったく同じである。たとえば、use_1x1conv=False, strides=1を使うと、入力と出力は同じ形状になる。あるいは、use_1x1conv=True, strides=2と設定すると、出力の高さと幅が半分になる。blk = ResNeXtBlock(32, 16, 1)
X = torch.randn(4, 32, 96, 96)
blk(X).shapetorch.Size([4, 32, 96, 96])