第7章畳み込みニューラルネットワーク
7.6.2. Training7.6.2 訓練
Now that we have implemented the model, let’s run an experiment to see how the LeNet-5 model fares on Fashion-MNIST.
英語のヒント
モデルを実装したので、LeNet-5のモデルがFashion-MNISTでどれだけうまくいくかを見る実験をしよう。
While CNNs have fewer parameters, they can still be more expensive to compute than similarly deep MLPs because each parameter participates in many more multiplications. If you have access to a GPU, this might be a good time to put it into action to speed up training. Note that the
d2l.Trainer class takes care of all details. By default, it initializes the model parameters on the available devices. Just as with MLPs, our loss function is cross-entropy, and we minimize it via minibatch stochastic gradient descent.英語のヒント
CNNはパラメータが少ないものの、各パラメータがずっと多くの掛け算に加わるので、同じくらいの深さのMLPより計算の費用がかかることがある。GPUが使えるなら、今こそそれを動かして訓練を速めるのによい時かもしれない。
d2l.Trainerクラスが細部をすべて引き受けてくれることに注意してほしい。既定では、使えるデバイスの上でモデルのパラメータを初期化する。MLPとちょうど同じく、損失関数は交差エントロピーで、それをミニバッチ確率的勾配降下法で最小にする。trainer = d2l.Trainer(max_epochs=10, num_gpus=1)
data = d2l.FashionMNIST(batch_size=128)
model = LeNet(lr=0.1)
model.apply_init([next(iter(data.get_dataloader(True)))[0]], init_cnn)
trainer.fit(model, data)