プリンキピア

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

8.3.2. NiN Model8.3.2 NiNモデル

NiN uses the same initial convolution sizes as AlexNet (it was proposed shortly thereafter). The kernel sizes are 11×11, 5×5, and 3×3, respectively, and the numbers of output channels match those of AlexNet. Each NiN block is followed by a max-pooling layer with a stride of 2 and a window shape of 3×3.
英語のヒント
NiNは、AlexNetと同じ最初の畳み込みの大きさを使う(NiNはAlexNetの直後に提案された)。カーネルの大きさはそれぞれ11×11、5×5、3×3で、出力チャネルの数はAlexNetのものと一致する。各NiNブロックの後には、ストライドが2で窓の形状が3×3の最大プーリング層が続く。
The second significant difference between NiN and both AlexNet and VGG is that NiN avoids fully connected layers altogether. Instead, NiN uses a NiN block with a number of output channels equal to the number of label classes, followed by a global average pooling layer, yielding a vector of logits. This design significantly reduces the number of required model parameters, albeit at the expense of a potential increase in training time.
英語のヒント
NiNとAlexNetおよびVGGとの二つ目の大きな違いは、NiNが全結合層をまったく使わないことである。代わりに、NiNは、出力チャネルの数がラベルのクラスの数と等しいNiNブロックを使い、その後に大域平均プーリング層を続けて、ロジットのベクトルを得る。この設計は、訓練時間が増えるかもしれないという代償はあるものの、必要なモデルパラメータの数を大きく減らす。
class NiN(d2l.Classifier):
    def __init__(self, lr=0.1, num_classes=10):
        super().__init__()
        self.save_hyperparameters()
        self.net = nn.Sequential(
            nin_block(96, kernel_size=11, strides=4, padding=0),
            nn.MaxPool2d(3, stride=2),
            nin_block(256, kernel_size=5, strides=1, padding=2),
            nn.MaxPool2d(3, stride=2),
            nin_block(384, kernel_size=3, strides=1, padding=1),
            nn.MaxPool2d(3, stride=2),
            nn.Dropout(0.5),
            nin_block(num_classes, kernel_size=3, strides=1, padding=1),
            nn.AdaptiveAvgPool2d((1, 1)),
            nn.Flatten())
        self.net.apply(d2l.init_cnn)
We create a data example to see the output shape of each block.
英語のヒント
各ブロックの出力の形状を見るために、データの事例を一つ作る。
NiN().layer_summary((1, 1, 224, 224))
Sequential output shape:     torch.Size([1, 96, 54, 54])
MaxPool2d output shape:      torch.Size([1, 96, 26, 26])
Sequential output shape:     torch.Size([1, 256, 26, 26])
MaxPool2d output shape:      torch.Size([1, 256, 12, 12])
Sequential output shape:     torch.Size([1, 384, 12, 12])
MaxPool2d output shape:      torch.Size([1, 384, 5, 5])
Dropout output shape:        torch.Size([1, 384, 5, 5])
Sequential output shape:     torch.Size([1, 10, 5, 5])
AdaptiveAvgPool2d output shape:      torch.Size([1, 10, 1, 1])
Flatten output shape:        torch.Size([1, 10])