46、tensorflow入门初步,手写识别0,1,2,3,4,5,6
2024-08-24 03:57:22
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
最新文章
- linux各目录的作用
- ActiveMQ第三弹:在Spring中使用内置的Message Broker
- (实用篇)PHP页面跳转到另一个页面的方法总结
- AsMVC:一个简单的MVC框架的Java实现
- No curses/termcap library found
- EOS 上线前,先搞懂这两个基本概念
- 计蒜客NOIP模拟赛(2) D1T2 表演艺术
- selenium常用内容
- 浏览器url地址殊字符转义编码
- linux 系统下安装多个php版本
- mybits根据表自动生成 java类和mapper 文件
- Android、IOS文字居中偏离的解决方案
- G - Rabbit and Grass
- crud树型结构数据
- ShellExecuteA URLDownloadToFileA
- Home Assistant 安装Samba和SSH server 插件
- ubuntu 13.04 编译 安装 升级 gcc 4.9.0 address sanitizer
- mvc-单例多线程模式
- Python中的迭代器漫谈
- 《Java I/O 从0到1》 - 第Ⅰ滴血 File
热门文章
- vlc 学习网
- iview+vue 表格任一项实现鼠标划上显示内容
- js记住密码
- JavaScript-打开新窗口(window.open)和 关闭窗口(window.close)
- Learning OSG programing---osgScribe
- sublime text3中使用PHP编译系统
- Spring Cloud 使用Spring Cloud Loadbalancer访问服务地址
- bzoi1152 [CTSC2006]歌唱王国Singleland
- sql查询静态数据
- ubuntu服务器端使用无界面selenium+ chrome + headless