mnist

简介:


'''
sess
prdict y=softmax(wx+b)
label y_
cross-entropy
train
initial
accuracy
test
save
restore
'''

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data

file = './MNIST/MNIST_data/'
mnist = input_data.read_data_sets(file,one_hot=True)
sess = tf.InteractiveSession()

x = tf.placeholder(dtype=tf.float32,shape=[None,784],name='x')
W = tf.Variable(tf.zeros(shape=[784,10]))
b = tf.Variable(tf.zeros(shape=[10]))
y = tf.nn.softmax(tf.matmul(x,W) + b)

y_ = tf.placeholder(dtype=tf.float32,shape=[None,10],name='y_')
cross_entropy = tf.reduce_mean(-tf.reduce_sum(input_tensor=y_*tf.log(y),reduction_indices=[1]))

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

saver = tf.train.Saver()

tf.global_variables_initializer().run()

for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
train_step.run(feed_dict={x:batch_xs, y_:batch_ys})


correct_prediction = tf.equal(tf.argmax(input=y, axis=1),tf.argmax(input=y_, axis=1))
accuracy = tf.reduce_mean(tf.cast(x=correct_prediction,dtype=tf.float32))
save_path = saver.save(sess=sess, save_path='./model_mnist.ckpt')

test_accuracy = accuracy.eval({x:mnist.test.images, y_:mnist.test.labels})
print(test_accuracy)


saver.restore(sess,'./model_mnist.ckpt')
result = accuracy.eval({x:mnist.test.images, y_:mnist.test.labels})

print(result)


92%


目录
相关文章
|
2月前
|
机器学习/深度学习 监控 数据处理
手写数字识别mnist
本文介绍了使用Keras框架对MNIST手写数字识别数据集进行处理、建立神经网络模型、编译、训练、评估直至模型精度分析的完整流程。
|
2月前
|
机器学习/深度学习 TensorFlow 算法框架/工具
【Tensorflow+Keras】keras实现条件生成对抗网络DCGAN--以Minis和fashion_mnist数据集为例
如何使用TensorFlow和Keras实现条件生成对抗网络(CGAN)并以MNIST和Fashion MNIST数据集为例进行演示。
35 3
|
5月前
|
存储 数据可视化 PyTorch
PyTorch中 Datasets & DataLoader 的介绍
PyTorch中 Datasets & DataLoader 的介绍
122 0
|
5月前
|
机器学习/深度学习 数据可视化 PyTorch
利用PyTorch实现基于MNIST数据集的手写数字识别
利用PyTorch实现基于MNIST数据集的手写数字识别
99 2
|
机器学习/深度学习 数据采集 编解码
CIFAR-10
CIFAR-10 数据集是机器学习领域中一个常用的数据集,主要用于图像分类任务。它包含 60000 张 32x32 彩色图片,分为 10 个类别,每个类别有 6000 张图片。其中,50000 张图片用于训练,10000 张图片用于测试。
164 1
|
机器学习/深度学习 数据可视化 自动驾驶
图像分类 | 基于 MNIST 数据集
图像分类 | 基于 MNIST 数据集
|
机器学习/深度学习 数据采集 PyTorch
pytorch笔记:Dataset 和 DataLoader
pytorch笔记:Dataset 和 DataLoader
289 0
|
TensorFlow 算法框架/工具
实现mnist手写数字识别
实现mnist手写数字识别
|
机器学习/深度学习 PyTorch 测试技术
|
PyTorch 算法框架/工具
【pytorch】pytorch代码中实现MNIST、cifar10等数据集本地读取
pytorch代码中实现MNIST、cifar10等数据集本地读取
【pytorch】pytorch代码中实现MNIST、cifar10等数据集本地读取