46、tensorflow入门初步,手写识别0,1,2,3,4,5,6
1、使用tensorflow的SoftMax函数,对手写数字进行识别
Administrator@SuperComputer MINGW64 ~
$ docker run -it -p 8888:8888 registry.cn-hangzhou.aliyuncs.com/denverdino/tens
orflow bash
root@b3e200093da9:/notebooks# python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tensorflow.examples.tutorials.mnist import input_data
-----------------------------------------------------------对于中间这个数据是怎么来的,我只能说是从网上下的,具体存放在哪个文件间中,我至今都没有找到
>>> mnist = input_data.read_data_sets("/MNIST_data/",one_hot = True)
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting /MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting /MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /MNIST_data/t10k-labels-idx1-ubyte.gz
>>> import tensorflow as tf
>>> x = tf.placeholder(tf.float32,[None,784])
>>> W = tf.Variable(tf.zeros([784,10]))
>>> b = tf.Variable(tf.zeros([10]))
>>> y = tf.nn.softmax(tf.matmul(x,W)+b)
>>> y_ = tf.placeholder(tf.float32,[None,10])
>>> cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_*tf.log(y),reduction_indices=[1]))
>>> train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
>>> init = tf.initialize_all_variables()//这个函数现在已经不用了,应该使用下边的那一行函数
WARNING:tensorflow:From <stdin>:1 in <module>.: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
>>> init = tf.global_variables_initializer()
>>> sess = tf.Session()
>>> sess.run(init)
>>> for i in range(1000):
... batch_xs,batch_ys = mnist.train.next_batch(100)
... sess.run(train_step,feed_dict = {x:batch_xs,y_:batch_ys})
...
>>> correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1))
>>> accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
>>> print(sess.run(accuracy,feed_dict={x:mnist.test.images,y_:mnist.test.labels}
))
0.9167
>>>
最后,训练后得到的模型在测试数据上的正确率是0.9167
46、tensorflow入门初步,手写识别0,1,2,3,4,5,6的更多相关文章
- TensorFlow 入门之手写识别(MNIST) softmax算法
TensorFlow 入门之手写识别(MNIST) softmax算法 MNIST flyu6 softmax回归 softmax回归算法 TensorFlow实现softmax softmax回归算 ...
- TensorFlow 入门之手写识别CNN 三
TensorFlow 入门之手写识别CNN 三 MNIST 卷积神经网络 Fly 多层卷积网络 多层卷积网络的基本理论 构建一个多层卷积网络 权值初始化 卷积和池化 第一层卷积 第二层卷积 密集层连接 ...
- TensorFlow 入门之手写识别(MNIST) softmax算法 二
TensorFlow 入门之手写识别(MNIST) softmax算法 二 MNIST Fly softmax回归 softmax回归算法 TensorFlow实现softmax softmax回归算 ...
- TensorFlow 入门之手写识别(MNIST) 数据处理 一
TensorFlow 入门之手写识别(MNIST) 数据处理 一 MNIST Fly softmax回归 准备数据 解压 与 重构 手写识别入门 MNIST手写数据集 图片以及标签的数据格式处理 准备 ...
- TensorFlow MNIST(手写识别 softmax)实例运行
TensorFlow MNIST(手写识别 softmax)实例运行 首先要有编译环境,并且已经正确的编译安装,关于环境配置参考:http://www.cnblogs.com/dyufei/p/802 ...
- 使用tensorflow实现mnist手写识别(单层神经网络实现)
import tensorflow as tf import tensorflow.examples.tutorials.mnist.input_data as input_data import n ...
- 基于tensorflow的MNIST手写识别
这个例子,是学习tensorflow的人员通常会用到的,也是基本的学习曲线中的一环.我也是! 这个例子很简单,这里,就是简单的说下,不同的tensorflow版本,相关的接口函数,可能会有不一样哟.在 ...
- densenet tensorflow 中文汉字手写识别
densenet 中文汉字手写识别,代码如下: import tensorflow as tf import os import random import math import tensorflo ...
- 基于tensorflow实现mnist手写识别 (多层神经网络)
标题党其实也不多,一个输入层,三个隐藏层,一个输出层 老样子先上代码 导入mnist的路径很长,现在还记不住 import tensorflow as tf import tensorflow.exa ...
随机推荐
- 《JavaScript DOM 编程艺术》学习成果
(在线演示地址)[http://thqy39.github.io/works/03.Js%20DOM%20website/index.html]
- python 装饰器 第十步:装饰器来装饰器一个类
第十步:装饰器来装饰一个类 def kuozhan(cls): print(cls) #声明一个类并且返回 def newHuman(): # 扩展类的功能1 cls.cloth = '漂亮的小裙子' ...
- 10分钟掌握Python-机器学习小项目
学习机器学习相关技术的最好方式就是先自己设计和完成一些小项目. Python 是一种非常流行和强大的解释性编程语言.不像 R 语言,Python 是个很完整的语言和平台,你既可以用来做研发,也可以用来 ...
- 教你如何创建vue环境
教你如何创建vue的环境 wdnmd我操作了一万年,终于成功创建了vue的环境,现在就来讲一下,到底应该怎么操作才能成功创建vue的 第一步 : 我们应该做的不是别的,而是去官方网站下载文件 node ...
- springCloud的使用03-----服务消费者(feign)
1 创建springboot项目,引入jar依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=& ...
- 新手学习 React 迷惑的点
网上各种言论说 React 上手比 Vue 难,可能难就难不能深刻理解 JSX,或者对 ES6 的一些特性理解得不够深刻,导致觉得有些点难以理解,然后说 React 比较难上手,还反人类啥的,所以我打 ...
- MyEclipse2017搭建android开发环境
1 安装MyEclipse2017cli7; 2 准备安装ADT插件和 Android SDK 开发包;比如:ADT-24.0.2 android-sdk_r24.4.1-windows; 工具栏点击 ...
- 在linux中出现there are stopped jobs 的解决方法【转自:http://www.linuxdiyf.com/viewarticle.php?id=104604】
在用管理员执行一个命令后,我用Ctrl+Z把命令转移到了后台天.导致我无法退出root的. 输入命令:logout终端显示:There are stopped jobs. 解决方法:输入命令:jobs ...
- 有趣的taskset命令,使进程再指定CPU上运行
前言 taskset命令,用于进程的CPU调优,可以把某进程,指定再某CPU内工作. 如还不明白,可以参考此文 http://www.361way.com/linux-context-switch/5 ...
- 由hbase.client.scanner.caching参数引发的血案(转)
转自:http://blog.csdn.net/rzhzhz/article/details/7536285 环境描述 Hadoop 0.20.203.0Hbase 0.90.3Hive 0.80.1 ...