第一步:我们首先导入mnist的数据包:
tensorflow实现手写字体
由于read.data.sets直接导入存在问题,所以这里我们先将数据包下载下来保存在MNIST_data中,之后直接读取。
tensorflow实现手写字体
第二步:我们采用有两个隐藏层的模型结构:
tensorflow实现手写字体
最终要得到10个类别的概率.
tensorflow实现手写字体
第三步:进行前向传播:
tensorflow实现手写字体
由于这个模型比较简单,这里就直接采用sigmoid**函数。
第四步:反向传播:
tensorflow实现手写字体
这里使用softmax损失函数,学习率设置为0.001.
第四步:模型训练:
tensorflow实现手写字体
我们迭代20次,批处理为100.
第五步:展示:
tensorflow实现手写字体
tensorflow实现手写字体
从图中可以看到损失函数值从33下降到15,最终正确率达到0.95。

相关文章: