softmax regression的tensorflow实现
来源:互联网 发布:php广告系统 编辑:程序博客网 时间:2024/06/06 02:06
MNIST数据集的使用是机器学习领域的HelloWorld.
他由几万张28x28像素的图片组成,这些图片只包含灰度信息,我们要做的就是对这些图片进行分类,分为0-9共10类.
softmax regression 模型在对图片进行预测时会为每个类估算一个概率,最后取概率大的为输出结果。
处理多分类的问题通常使用该模型,CNN和RNN最后一层同样是Softmax Regression
这是代码部分
from tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True)print(mnist.train.images.shape, mnist.train.labels.shape)print(mnist.test.images.shape, mnist.test.labels.shape)print(mnist.validation.images.shape, mnist.validation.labels.shape)import tensorflow as tfsess = tf.InteractiveSession()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)tf.global_variables_initializer().run()for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) train_step.run({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(accuracy.eval({x: mnist.test.images, y_: mnist.test.labels}))
图中附有我写的解析:
这是实验结果:
建议用jupyter notebook打开,编写环境tensorflow1.1,python3.5。
点此查看Github源代码
阅读全文
0 0
- softmax regression的tensorflow实现
- 使用Tensorflow实现Softmax Regression
- tensorflow 实现一个Softmax Regression
- TensorFlow实现Softmax Regression识别手写数字
- Tensorflow实现Softmax Regression 手写识别MNIST
- TensorFlow实现Softmax Regression手写数字识别
- TensorFlow 实现 Softmax Regression 识别手写数字
- TensorFlow 实现Softmax Regression 识别数字
- TensorFlow实现Softmax Regression识别手写数字
- TensorFlow 实现Softmax Regression识别手写数字
- tensorflow实现softmax regression识别手写数字
- Tensorflow实现Softmax Regression识别手写数字
- tensorflow实现softmax回归(softmax regression)——简单的MNIST识别(第一课)
- [03]tensorflow实现softmax回归(softmax regression)
- TensorFlow的softmax regression做mnist例子
- TensorFlow(二)实现Softmax Regression 识别手写数字
- TensorFlow入门-MNIST & softmax regression
- 用TensorFlow的Softmax Regression进行手写数字识别
- 设计模式之观察者模式
- Unity UGUI 原理篇(三):RectTransform
- Codeforces 404C Restore Graph【思维】
- 浅谈lorawan 调试心得
- linux网络配置
- softmax regression的tensorflow实现
- CSU-ACM2017暑假集训比赛2 CodeForces
- 复制文档
- 矩阵快速幂 模板
- 磁盘管理3--磁盘配额
- HTML5 实现跨域消息传递
- Hdu6069 Counting Divisors(2017多校第4场)
- 拷贝图片
- 由View.post引发的问题