プリンキピア

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

8.2.2. VGG Network8.2.2 VGGネットワーク

Like AlexNet and LeNet, the VGG Network can be partitioned into two parts: the first consisting mostly of convolutional and pooling layers and the second consisting of fully connected layers that are identical to those in AlexNet. The key difference is that the convolutional layers are grouped in nonlinear transformations that leave the dimensonality unchanged, followed by a resolution-reduction step, as depicted in Fig. 8.2.1.
英語のヒント
AlexNetやLeNetと同じように、VGGネットワークは二つの部分に分けられる。一つ目はおもに畳み込み層とプーリング層からなり、二つ目はAlexNetのものと同じ全結合層からなる。鍵となる違いは、畳み込み層が、次元を変えない非線形変換としてまとめられ、その後に解像度を下げる段階が続くことである。図8.2.1に描いたとおりである。
Fig. 8.2.1図8.2.1
From AlexNet to VGG. The key difference is that VGG consists of blocks of layers, whereas AlexNet’s layers are all designed individually.
英語のヒント
AlexNetからVGGへ。鍵となる違いは、VGGが層のブロックからなるのに対し、AlexNetの層はすべて個別に設計されていることである。
The convolutional part of the network connects several VGG blocks from Fig. 8.2.1 (also defined in the vgg_block function) in succession. This grouping of convolutions is a pattern that has remained almost unchanged over the past decade, although the specific choice of operations has undergone considerable modifications. The variable arch consists of a list of tuples (one per block), where each contains two values: the number of convolutional layers and the number of output channels, which are precisely the arguments required to call the vgg_block function. As such, VGG defines a family of networks rather than just a specific manifestation. To build a specific network we simply iterate over arch to compose the blocks.
英語のヒント
ネットワークの畳み込みの部分は、図8.2.1のVGGブロック(vgg_block関数でも定義した)をいくつか続けてつなぐ。この畳み込みのまとめ方は、具体的な演算の選び方はかなり変わってきたものの、過去10年ほとんど変わらずに残っているパターンである。変数archはタプル(ブロックごとに一つ)のリストからなり、各タプルは二つの値を含む。畳み込み層の数と出力チャネルの数であり、これはちょうどvgg_block関数を呼ぶのに必要な引数である。そのため、VGGは一つの具体的な姿ではなく、ネットワークの一族を定める。具体的なネットワークを作るには、archを順にたどってブロックを組み立てればよい。
class VGG(d2l.Classifier):
    def __init__(self, arch, lr=0.1, num_classes=10):
        super().__init__()
        self.save_hyperparameters()
        conv_blks = []
        for (num_convs, out_channels) in arch:
            conv_blks.append(vgg_block(num_convs, out_channels))
        self.net = nn.Sequential(
            *conv_blks, nn.Flatten(),
            nn.LazyLinear(4096), nn.ReLU(), nn.Dropout(0.5),
            nn.LazyLinear(4096), nn.ReLU(), nn.Dropout(0.5),
            nn.LazyLinear(num_classes))
        self.net.apply(d2l.init_cnn)
The original VGG network had five convolutional blocks, among which the first two have one convolutional layer each and the latter three contain two convolutional layers each. The first block has 64 output channels and each subsequent block doubles the number of output channels, until that number reaches 512. Since this network uses eight convolutional layers and three fully connected layers, it is often called VGG-11.
英語のヒント
元のVGGネットワークには五つの畳み込みブロックがあり、そのうち最初の二つはそれぞれ畳み込み層を一つ、後の三つはそれぞれ畳み込み層を二つ含む。最初のブロックは出力チャネルが64で、続く各ブロックは出力チャネルの数を2倍にしていき、それが512に達するまで続ける。このネットワークは畳み込み層8つと全結合層3つを使うので、しばしばVGG-11と呼ばれる。
VGG(arch=((1, 64), (1, 128), (2, 256), (2, 512), (2, 512))).layer_summary(
    (1, 1, 224, 224))
Sequential output shape:     torch.Size([1, 64, 112, 112])
Sequential output shape:     torch.Size([1, 128, 56, 56])
Sequential output shape:     torch.Size([1, 256, 28, 28])
Sequential output shape:     torch.Size([1, 512, 14, 14])
Sequential output shape:     torch.Size([1, 512, 7, 7])
Flatten output shape:        torch.Size([1, 25088])
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])
As you can see, we halve height and width at each block, finally reaching a height and width of 7 before flattening the representations for processing by the fully connected part of the network. Simonyan and Zisserman (2014) described several other variants of VGG. In fact, it has become the norm to propose families of networks with different speed–accuracy trade-off when introducing a new architecture.
英語のヒント
見てのとおり、各ブロックで高さと幅を半分にしていき、最終的に高さと幅が7になったところで、表現を平らにしてネットワークの全結合の部分で処理する。Simonyan and Zisserman (2014)は、VGGのほかの変種もいくつか説明している。実際、新しい構造を紹介するときには、速度と正解率のトレードオフが異なるネットワークの一族を提案するのが当たり前になっている。