当前位置: 首页 > news >正文

基于Python实现的神经网络分类MNIST数据集

神经网络分类MNIST数据集
目录
神经网络分类MNIST数据集 1
一 、问题背景 1
1.1 神经网络简介 1
前馈神经网络模型: 1
1.2 MINST 数据说明 4
1.3 TensorFlow基本概念 5
二 、实现说明 5
2.1 构建神经网络模型 5

为输入输出分配占位符 5
搭建分层的神经网络 6
处理预测结果 8
2.2 运行模型 9
三 、程序测试 9
3.1 运行说明 10
3.2 运行输出 10
四 、实验总结 11
2.2运行模型
首先调用 tf.global_variables_initializer() 初始化模型的参数,Session提供了Operation执行和Tensor求值的环境
其中:
模型训练分批次,每一批用100个样本训练神经网络模型,每一批都在上一批的基础上对网络模型 的参数进行调整。
mnist.train.next_batch :返回的是一组元组,元组的第一个元素图片像素阵列,第二个元素为 one-hot 格式的预测标签。
:在一个Session 里面计算张量的值,执行定义的所有必要的操作来产生这个计算这个张量需要的输入,然后通过这些输入产生这个张量。
feed_dict 作用是给使用 placeholder 创建出来的张量赋值,上述我们使用 定义
的占位符包括输入 x 、输出 y 和Dropout 层保留比例 keep_prob 。
三 、程序测试
3.1运行说明
因为实验代码所需要的TensorFlow版本为1.4.0,而现在TensorFlow的版本已经上升到了2.x,一些以前
提供的数据集、函数已经被删除,故直接运行会报错,报错内容为找不到 包。
我们可以使用一些Online运行环境,如 Google Colab (https://colab.research.google.com/)。使用云计算来运行我们的程序,将TensorFlow降级至1.4.0,而不修改本地 Python 的配置。
将TensorFlow降级的方法如下:在文件首行加入以下代码,然后再 import tensorflow 。
执行程序后会首先出现以下输出,本文转载自http://www.biyezuopin.vip/onews.asp?id=16721程序其他部分无需修改即可以正常运行,运行结果与预期一致。
3.2运行输出
运行输出如下:可以看到随着测试规模的增加,训练和测试的准确率也不断地在上升。
step 0, training accuracy 0.07, test accuracy 0.1024
step 50, training accuracy 0.91, test accuracy 0.8892
3 step 100, training accuracy 0.95, test accuracy 0.9325
4 step 150, training accuracy 0.94, test accuracy 0.9405
5 step 200, training accuracy 0.95, test accuracy 0.9468
6 step 250, training accuracy 0.96, test accuracy 0.9518
7 step 300, training accuracy 0.94, test accuracy 0.9543
8 step 350, training accuracy 0.97, test accuracy 0.9645
9 step 400, training accuracy 0.94, test accuracy 0.9588
10 step 450, training accuracy 0.95, test accuracy 0.9655
11
12 step 500, training accuracy 1, test accuracy 0.9608
test accuracy 0.9586
尝试修改部分参数,观察输出变化情况。
提高Adam下降算法的学习率:将学习率从 提高到 、
可以看到随着学习率的提高,测试正确率有明显的提高,但耗时随之上升。
step 0, training accuracy 0.08, test accuracy 0.1123
step 50, training accuracy 0.94, test accuracy 0.913
step 100, training accuracy 0.9, test accuracy 0.9283
4 step 150, training accuracy 0.95, test accuracy 0.9442
5 step 200, training accuracy 0.91, test accuracy 0.9413
6 step 250, training accuracy 0.94, test accuracy 0.954
7 step 300, training accuracy 0.93, test accuracy 0.9513
8 step 350, training accuracy 0.99, test accuracy 0.9598
9 step 400, training accuracy 0.97, test accuracy 0.9609
10 step 450, training accuracy 0.94, test accuracy 0.9584
11 step 500, training accuracy 0.96, test accuracy 0.9609
12 test accuracy 0.9651
当学习率提高到 时,过高的学习率容易跳过最优值,预测效果反而下降。
step 0, training accuracy 0.07, test accuracy 0.0877
step 50, training accuracy 0.89, test accuracy 0.9095
3 step 100, training accuracy 0.94, test accuracy 0.9233
4 step 150, training accuracy 0.91, test accuracy 0.9267
5 step 200, training accuracy 0.89, test accuracy 0.882
6 step 250, training accuracy 0.96, test accuracy 0.9383
7 step 300, training accuracy 0.92, test accuracy 0.9426
8 step 350, training accuracy 0.96, test accuracy 0.9384
9 step 400, training accuracy 0.95, test accuracy 0.9524
10 step 450, training accuracy 0.93, test accuracy 0.9504
11 step 500, training accuracy 0.95, test accuracy 0.9563
12 test accuracy 0.9469
增加/减少神经网络隐层
经测试,网络层数(3,4,5)对模型效果的影响不明显。而层次相同的神经网络中节点数目多的 表现出性能更优。
四 、实验总结
通过本次实验,我们深入理解了前馈神经网络模型,通过示例代码,研究MINST数据集训练神经网络的过程。第一次了解 TensorFlow,学习了TensorFlow的基本概念和用法,掌握了如何运用
TensorFlow来构建一个神经网络模型。
 

http://www.lryc.cn/news/193750.html

相关文章:

  • 设计模式之是简单工厂模式
  • Java应用的混淆、加密以及加壳
  • 【Linux】:Linux中Shell命令及其运行原理/权限的理解
  • 传统项目管理与敏捷项目管理
  • 只要掌握Win32应用程序错误的来龙去脉,就没必要惊慌失措
  • ABB机器人关于重定位移动讲解
  • Ceph介绍与部署
  • sklearn 机器学习基本用法
  • Ionic4 生命周期钩子函数和angular生命周期钩子函数介绍
  • Hive+Flume+Kafka章节测试六错题总结
  • 【随笔】论多线程CPU离线渲染器的实现:A CPU BASED OFFLINE RENDERING ENGINE
  • 多输入多输出 | MATLAB实现CNN-GRU-Attention卷积神经网络-门控循环单元结合SE注意力机制的多输入多输出预测
  • Ubuntu:Arduino IDE 开发环境配置【保姆级】
  • Kafka 开启SASL/SCRAM认证 及 ACL授权(三)验证
  • Pycharm 2023 设置远程调试
  • asp.net core在其他程序集获取HttpContext
  • UWB NI框架嵌入式实现——Qorvo示例
  • Linux OS源的问题记录
  • 数据库:Hive转Presto(五)
  • SQL中for xml path 的用法
  • 【TensorFlow2 之014】在 TF 2.0 中实现 LeNet-5
  • 【2023】redis-stream配合spring的data-redis详细使用(包括广播和组接收)
  • 飞书应用机器人文件上传
  • 高版本Mac系统如何打开低版本的Xcode
  • 测试H5需要注意的交互测试用例点
  • 1014蓝桥算法双周赛,学习算法技巧,助力蓝桥杯
  • C语言之通讯录的实现篇
  • 如何降低海康、大华等网络摄像头调用的高延迟问题(二)
  • centos清理日志和缓存
  • 排序算法的稳定性