注册 登录
    • 为了保证你在浏览本网站时有着更好的体验,建议使用类似Chrome、Firefox之类的浏览器~~
    • 如果你喜欢本站的内容何不Ctrl+D收藏一下呢,与大家一起分享各种编程知识~
    • 本网站研究机器学习、计算机视觉、模式识别~当然不局限于此,生命在于折腾,何不年轻时多折腾一下

Deep Learning TensorFlow实践:mnist手写识别(一)

Qt gegey 76次浏览 0个评论 扫描二维码

Deep Learning TensorFlow实践:mnist手写识别(一)

Deep Learning TensorFlow实践:mnist手写识别(一)

代码如下:

#!/usr/bin/python
#-*- coding:utf-8 -*-  
############################  
#File Name: Softmax_Regression.py
#Author: yang
#Mail: milkyang2008@126.com  
#Created Time: 2017-08-22 20:51:58
############################


import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

#load training data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/",one_hot=True)

import tensorflow as tf

x = tf.placeholder("float",[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("float", [None,10])
cross_entropy = -tf.reduce_sum(y_*tf.log(y))

train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)

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_predition = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))

accuracy = tf.reduce_mean(tf.cast(correct_predition, "float"))
result =sess.run(accuracy, feed_dict={x: mnist.test.images,y_: mnist.test.labels})
print("the accuracy is: %g " % result)

训练结果如下:

cting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
the accuracy is: 0.9154

Deep Learning TensorFlow实践:mnist手写识别(一)


Deeplearn, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Deep Learning TensorFlow实践:mnist手写识别(一)
喜欢 (0)
[xiaocui]
分享 (0)

您必须 登录 才能发表评论!