提交 699b1b19 编写于 作者: A Aston Zhang

img aug

上级 4aecbe43
......@@ -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)
......
......@@ -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)
```
可以看到,即使是简单的随机翻转也会有明显的效果。图片增广类似于正则项,它使得训练精度变低,但可以提高测试精度。
......
......@@ -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):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册