プリンキピア

第8章現代の畳み込みニューラルネットワーク

8.2.1. VGG Blocks8.2.1 VGGブロック

The basic building block of CNNs is a sequence of the following: (i) a convolutional layer with padding to maintain the resolution, (ii) a nonlinearity such as a ReLU, (iii) a pooling layer such as max-pooling to reduce the resolution. One of the problems with this approach is that the spatial resolution decreases quite rapidly. In particular, this imposes a hard limit of log2⁡d convolutional layers on the network before all dimensions (d) are used up. For instance, in the case of ImageNet, it would be impossible to have more than 8 convolutional layers in this way.
英語のヒント
CNNの基本的な構成要素は、次のものを順に並べたものである。(i)解像度を保つためにパディングを入れた畳み込み層、(ii)ReLUのような非線形性、(iii)解像度を下げるための、最大プーリングのようなプーリング層。このやり方の問題の一つは、空間的な解像度がかなり急速に下がることである。特に、これにより、すべての次元(d)を使い切るまでにネットワークに置ける畳み込み層はlog2⁡d層まで、という厳しい上限が課される。たとえば、ImageNetの場合、この方法では8層を超える畳み込み層をもつことはできない。
The key idea of Simonyan and Zisserman (2014) was to use multiple convolutions in between downsampling via max-pooling in the form of a block. They were primarily interested in whether deep or wide networks perform better. For instance, the successive application of two 3×3 convolutions touches the same pixels as a single 5×5 convolution does. At the same time, the latter uses approximately as many parameters (25⋅c2) as three 3×3 convolutions do (3⋅9⋅c2). In a rather detailed analysis they showed that deep and narrow networks significantly outperform their shallow counterparts. This set deep learning on a quest for ever deeper networks with over 100 layers for typical applications. Stacking 3×3 convolutions has become a gold standard in later deep networks (a design decision only to be revisited recently by Liu et al. (2022)). Consequently, fast implementations for small convolutions have become a staple on GPUs (Lavin and Gray, 2016).
英語のヒント
Simonyan and Zisserman (2014)の鍵となる考えは、最大プーリングによるダウンサンプリングのあいだに、複数の畳み込みをブロックの形で使うことだった。彼らの主な関心は、深いネットワークと広いネットワークのどちらが性能がよいかにあった。たとえば、3×3の畳み込みを2回続けて当てはめると、一つの5×5の畳み込みと同じ画素に触れる。同時に、後者は、三つの3×3の畳み込み(3⋅9⋅c2)とほぼ同じ数のパラメータ(25⋅c2)を使う。かなり詳しい分析で、彼らは、深く細いネットワークが浅いネットワークを大きく上回ることを示した。これによって深層学習は、典型的な応用で100層を超える、いっそう深いネットワークを追い求めるようになった。3×3の畳み込みを積み重ねることは、後の深いネットワークで標準となった(この設計判断は、ごく最近になってLiu et al. (2022)が見直したばかりである)。その結果、小さな畳み込みの高速な実装は、GPUでの定番になった(Lavin and Gray, 2016)。
Back to VGG: a VGG block consists of a sequence of convolutions with 3×3 kernels with padding of 1 (keeping height and width) followed by a 2×2 max-pooling layer with stride of 2 (halving height and width after each block). In the code below, we define a function called vgg_block to implement one VGG block.
英語のヒント
VGGに戻ろう。VGGブロックは、パディング1の3×3のカーネルによる畳み込み(高さと幅を保つ)を並べ、その後にストライド2の2×2の最大プーリング層(各ブロックの後で高さと幅を半分にする)を続けたものである。以下のコードでは、一つのVGGブロックを実装するため、vgg_blockという関数を定義する。
The function below takes two arguments, corresponding to the number of convolutional layers num_convs and the number of output channels num_channels.
英語のヒント
下の関数は二つの引数をとる。畳み込み層の数num_convsと、出力チャネルの数num_channelsである。
def vgg_block(num_convs, out_channels):
    layers = []
    for _ in range(num_convs):
        layers.append(nn.LazyConv2d(out_channels, kernel_size=3, padding=1))
        layers.append(nn.ReLU())
    layers.append(nn.MaxPool2d(kernel_size=2,stride=2))
    return nn.Sequential(*layers)