本文实例为大家分享了基于Tensorflow的MNIST手写数字识别分类的具体实现代码,供大家参考,具体内容如下
代码如下:
import tensorflow as tf
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.contrib.tensorboard.plugins import projector
import time
IMAGE_PIXELS = 28
hidden_unit = 100
output_nums = 10
learning_rate = 0.001
train_steps = 50000
batch_size = 500
test_data_size = 10000
#日志目录(这里根据自己的目录修改)
logdir = 'D:/Develop_Software/Anaconda3/WorkDirectory/summary/mnist'
#导入mnist数据
mnist = input_data.read_data_sets('MNIST_data', one_hot = True)
#全局训练步数
global_step = tf.Variable(0, name = 'global_step', trainable = False)
with tf.name_scope('input'):
#输入数据
with tf.name_scope('x'):
x = tf.placeholder(
dtype = tf.float32, shape = (None, IMAGE_PIXELS * IMAGE_PIXELS))
#收集x图像的会总数据
with tf.name_scope('x_summary'):
shaped_image_batch = tf.reshape(
tensor = x,
shape = (-1, IMAGE_PIXELS, IMAGE_PIXELS, 1),
name = 'shaped_image_batch')
tf.summary.i