MNIST和softmax回归(softmax regression)
来源:互联网 发布:淘宝美工字体 编辑:程序博客网 时间:2024/06/09 17:02
MNIST是一个入门级的计算机视觉数据集,它包含各种手写数字图片,我们将训练一个机器学习模型用于预测图片里面的数字.这个的实现代码很短,而且真正有意思的内容只包含在三行代码里面。理解包含在这些代码里面的设计思想是非常重要的.我们知道MNIST的每一张图片都表示一个数字,从0到9。我们希望得到给定图片代表每个数字的概率。比如说,我们的模型可能推测一张包含9的图片代表数字9的概率是80%但是判断它是8的概率是5%(因为8和9都有上半部分的小圆),然后给予它代表其他数字的概率更小的值。这是一个使用softmax回归(softmax regression)模型的经典案例。softmax模型可以用来给不同的对象分配概率。即使在之后,我们训练更加精细的模型时,最后一步也需要用softmax来分配概率。
具体代码:
import osimport tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dataos.environ['TF_CPP_MIN_LOG_LEVEL']='2'#加载MNIST数据mnist = input_data.read_data_sets("../../../datasets/MNIST_data", one_hot=True)#创建操作符号变量来描述这些可交互的操作单元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))#用梯度下降算法以0.01的学习速率最小化交叉熵train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)#添加一个操作来初始化我们创建的变量init = tf.initialize_all_variables()sess = tf.InteractiveSession()sess.run(init)for i in range(1000):batch = mnist.train.next_batch(50)train_step.run(feed_dict={x: batch[0], y_: batch[1]})#评估我们的模型correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))print(accuracy.eval(feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
阅读全文
1 0
- MNIST和softmax回归(softmax regression)
- softmax回归(Softmax Regression)
- MNIST和softmax回归模型
- Softmax回归(Softmax Regression)
- Softmax回归(Softmax Regression)
- Softmax回归(Softmax Regression)
- Softmax Regression with MNIST
- Logistic and Softmax Regression (逻辑回归和Softmax回归)
- Logistic and Softmax Regression (逻辑回归和Softmax回归)
- 基于TensorFLow实现MNIST和softmax回归
- TensorFlow入门-MNIST & softmax regression
- tensorflow实现softmax回归(softmax regression)——简单的MNIST识别(第一课)
- Ufldl Exercise:Softmax Regression Softmax回归练习
- MNIST——softmax回归
- 使用Softmax回归实现MNIST
- Tensorflow实现Softmax Regression 手写识别MNIST
- Tensorflow学习笔记(3)-mnist(softmax regression)
- TensorFlow的softmax regression做mnist例子
- Effective STL学习笔记-条款20
- BZOJ 1036 [ZJOI 2008] 树链剖分 解题报告
- 单机任务重试机制——重启不丢任务
- A. Odds and Ends
- Bootstrap插件(八)——轮播(Carousel.js)
- MNIST和softmax回归(softmax regression)
- Linux(xubuntu)下访问windows共享文件夹
- Cg Programming/Unity/Silhouette Enhancement轮廓增强
- 例题7-1 除法(Division, UVa 725)
- bzoj3862Little Devil I(树链剖分+线段树)
- 使用scala计算两个Gps点之间的距离
- 找到几个在线查看函数图像的网站
- 最小的k个数
- BZOJ 3991 寻宝游戏 (dfs序 RMQ set维护动态链的并集)