defevaluate_accuracy(data_iter, net): acc_sum, n = 0.0, 0 for X, y in data_iter: y = y.astype('float32') acc_sum += (net(X).argmax(axis=1) == y).sum().asscalar() n += y.size return acc_sum / n
epoch 1, loss 0.3821, train acc 0.868, test acc 0.860
epoch 2, loss 0.3823, train acc 0.868, test acc 0.857
epoch 3, loss 0.3820, train acc 0.868, test acc 0.858
epoch 4, loss 0.3819, train acc 0.869, test acc 0.858
epoch 5, loss 0.3817, train acc 0.868, test acc 0.858
epoch 6, loss 0.3817, train acc 0.868, test acc 0.857
epoch 7, loss 0.3813, train acc 0.868, test acc 0.860
epoch 8, loss 0.3813, train acc 0.868, test acc 0.858
epoch 9, loss 0.3812, train acc 0.868, test acc 0.857
epoch 10, loss 0.3813, train acc 0.868, test acc 0.859
预测
第一行为真实标签,第二行为预测标签,第三行为图像
1 2 3 4 5 6 7 8
for X, y in test_iter: break
true_labels = d2l.get_fashion_mnist_labels(y.asnumpy()) pred_labels = d2l.get_fashion_mnist_labels(net(X).argmax(axis=1).asnumpy()) titles = [true + '\n' + pred for true, pred in zip(true_labels, pred_labels)]