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 ...
随机推荐
- 三线SWD模式Jlink
三线SWD模式Jlink 在公司实习,部门经理让我做一个USB-CAN的适配器. 在网上找资料,找到一个开源的USB-CAN的适配器的资料. 采用的是CP2102芯片实现USB转串口.STM32作 ...
- QTP-创建一个word文件
'创建word实例 Set oWordApp = CreateObject("Word.Application") oWordApp.Visible =True '添加一个word ...
- Linux操作系统(二)_快速入门
环境 安装VM ware,输入VM key 在VM上安装CentOS 6.5 设置网络,能在本机上ping通 通过终端连接工具:Xshell或SecureCRT,连接Linux服务器 实操可能出现的问 ...
- HP Loadrunner 12.53的下载与安装
HP Loadrunner 12.53的下载与安装 HP Loadrunner 12.53的下载:http://pan.baidu.com/s/1c23axHm HP Loadrunner 12. ...
- 用css3写出的倒三角形
<!DOCTYPE html><html><head><meta charset="gb2312" /><title>无 ...
- C++中类模板的深入理解
1,多参数类模板: 1,类模板可以定义任意多个不同的类型参数: 1,代码示例: template <typename T1, typename T2> class Test { publi ...
- 使用vue配合组件--转载
1.由饿了么 UED (知乎专栏)设计的桌面端组件库已经开源,文档:Element,仓库: GitHub - ElemeFE/element: Desktop UI elements for Vue. ...
- Python的基础类型(int,bool,str):
Python的基础类型(int,bool,str): 1.int -------> 整形:主要用力进行数字计算 2.string ------>字符串:可以保存少量数据并进行相关的操作 3 ...
- Python3学习笔记(MOOC)
文本进度条实例 #!/usr/bin/env python3 import time #for i in range(101): # print ("\r{:3.0f}%".for ...
- 【问题解决方案】anaconda-python在cmd-pip安装requests后依然提示No module named requests
参考: 知乎回答:python的requests安装后idle依然提示No module named requests? 环境: win7-64位 anaconda3-Python3.7 & ...