第14章コンピュータビジョン
14.11.4. Training14.11.4 訓練
Now we can train our constructed fully convolutional network. The loss function and accuracy calculation here are not essentially different from those in image classification of earlier chapters. Because we use the output channel of the transposed convolutional layer to predict the class for each pixel, the channel dimension is specified in the loss calculation. In addition, the accuracy is calculated based on correctness of the predicted class for all the pixels.
英語のヒント
これで、作った全畳み込みネットワークを訓練できる。ここでの損失関数と正解率の計算は、前の章の画像分類のものと本質的に変わらない。転置畳み込み層の出力チャネルを使って各画素のクラスを予測するので、損失の計算ではチャネルの次元を指定する。さらに、正解率は、すべての画素について予測したクラスの正しさにもとづいて計算される。
def loss(inputs, targets):
return F.cross_entropy(inputs, targets, reduction='none').mean(1).mean(1)
num_epochs, lr, wd, devices = 5, 0.001, 1e-3, d2l.try_all_gpus()
trainer = torch.optim.SGD(net.parameters(), lr=lr, weight_decay=wd)
d2l.train_ch13(net, train_iter, test_iter, loss, trainer, num_epochs, devices)loss 0.449, train acc 0.861, test acc 0.852
226.7 examples/sec on [device(type='cuda', index=0), device(type='cuda', index=1)]