旋转图片,增加神经网络的准确率

前面我们用全量mnist数据集测试的准确率大概在75%左右,当然是没有经过改进之前的测试。

而我们用少量mnist数据集测试的准确率只有60%左右。两个的区别在于mnist训练数据集的大小,如果我们在全量数据集的基础上在增加新的图片会不会提高准确率呢。下面我们试下通过旋转已知图片的方法看准确率是否有增加。

1.训练

在训练的过程中旋转图片,再训练新的图片。

inputs_plusx_img = scipy.ndimage.interpolation.rotate(input_list.reshape(28,28), 10, cval=0.01, order=1, reshape=False)
mnist.train(inputs_plusx_img.reshape(784), target_list)
# rotated clockwise by x degrees
inputs_minusx_img = scipy.ndimage.interpolation.rotate(input_list.reshape(28,28), -10, cval=0.01, order=1, reshape=False)
mnist.train(inputs_minusx_img.reshape(784), target_list)

分别为增加10度和减少10度

2.测试

测试步骤和前面的一样,测试结果为:

 和上面的结果对比,此次的准确率最低都为83.1%,可以说是提高了一大截。

代码地址为:https://github.com/pythonAndAI/nerve-net/blob/master/com/test/otherExercises/mnistrotate.py

原文地址:https://www.cnblogs.com/bestExpert/p/10361359.html