diff --git a/chapter_appendix/gluonbook.md b/chapter_appendix/gluonbook.md index 6528249785d45f979a0ed14932ab22a39f46ef12..13fa2105c1531517e2c7338c04d5e1e3a84ef410 100644 --- a/chapter_appendix/gluonbook.md +++ b/chapter_appendix/gluonbook.md @@ -14,7 +14,7 @@ * `data_iter_random`,[循环神经网络](../chapter_recurrent-neural-networks/rnn.md) -* `evaluate_accuracy`,[Softmax回归的从零开始实现](../chapter_deep-learning-basics/softmax-regression-scratch.md) +* `evaluate_accuracy`, * `grad_clipping`,[循环神经网络](../chapter_recurrent-neural-networks/rnn.md) diff --git a/chapter_computer-vision/image-augmentation.md b/chapter_computer-vision/image-augmentation.md index b1aeb04858e2c56afc6e10f959e7e1da3d32761b..8e519498f47ba8fb9f4433cf1da2e7ce856f3448 100644 --- a/chapter_computer-vision/image-augmentation.md +++ b/chapter_computer-vision/image-augmentation.md @@ -114,10 +114,10 @@ def load_cifar10(is_train, augs, batch_size): ### 模型训练 -我们使用ResNet 18来训练CIFAR-10。训练的的代码与[“残差网络:ResNet”](../chapter_convolutional-neural-networks/resnet.md)中一致,除了使用所有可用的GPU和不同的学习率外。 +我们使用ResNet-18来训练CIFAR-10。训练的代码与[“残差网络:ResNet”](../chapter_convolutional-neural-networks/resnet.md)中一致,除了使用所有可用的GPU和不同的学习率外。 ```{.python .input n=13} -def train(train_augs, test_augs, lr=0.1): +def train_with_data_aug(train_augs, test_augs, lr=0.1): batch_size = 256 ctx = gb.try_all_gpus() net = gb.resnet18(10) @@ -132,13 +132,13 @@ def train(train_augs, test_augs, lr=0.1): 首先我们看使用了图片增广的情况。 ```{.python .input n=14} -train(train_augs, test_augs) +train_with_data_aug(train_augs, test_augs) ``` 作为对比,我们尝试只对训练数据做中间剪裁。 ```{.python .input n=15} -train(test_augs, test_augs) +train_with_data_aug(test_augs, test_augs) ``` 可以看到,即使是简单的随机翻转也会有明显的效果。图片增广类似于正则项,它使得训练精度变低,但可以提高测试精度。 diff --git a/gluonbook/utils.py b/gluonbook/utils.py index 2d9537e1543068d9d880290195274ca36a7add6a..d118f357d223086f4f8fab7ad6c3a9ac58bf845a 100644 --- a/gluonbook/utils.py +++ b/gluonbook/utils.py @@ -399,7 +399,7 @@ def train(train_iter, test_iter, net, loss, trainer, ctx, num_epochs, trainer.step(batch_size) n += batch_size m += sum([y.size for y in ys]) - if print_batches and (i+1) % print_batches == 0: + if print_batches and (i + 1) % print_batches == 0: print('batch %d, loss %f, train acc %f' % ( n, train_l_sum / n, train_acc_sum / m )) @@ -488,7 +488,7 @@ def train_ch3(net, train_iter, test_iter, loss, num_epochs, batch_size, def try_all_gpus(): - """Return all available GPUs, or [mx.gpu()] if there is no GPU.""" + """Return all available GPUs, or [mx.cpu()] if there is no GPU.""" ctxes = [] try: for i in range(16):