Coding according to TensorFlow 官方文档中文版

 import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ''' Intro. for this python file.
Objective:
Implement for a Softmax Regression Model on MNIST.
Operating Environment:
python = 3.6.4
tensorflow = 1.5.0
''' # Set a placeholder. We hope arbitrary number of images could be input to this model.
x = tf.placeholder("float", [None, 784]) # Set weight/bias variables. Their initial values could be set Randomly.
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10])) # Model implementation
y = tf.nn.softmax(tf.matmul(x, W) + b) # Set a placeholder 'y_' to accept the ground-truth values.
y_ = tf.placeholder("float", [None, 10]) # Calculate cross-entropy
cross_entropy = -tf.reduce_sum(y_ * tf.log(y)) # Train Softmax Regression Model
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) # Initialize variables
# init = tf.initialize_all_variables() # Warning
init = tf.global_variables_initializer() # Launch the graph in a session.
sess = tf.Session()
sess.run(init) for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100) # Grabbing 100 batch data points from training data randomly.
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) # Model Evaluation
''' tf.argmax(input, axis=None, name=None, dimension=None, output_type=tf.int64)
Explanation:
Returns the index with the largest value across axes of a tensor.
test = np.array([[1, 2, 3], [2, 3, 4], [5, 4, 3], [8, 7, 2]])
np.argmax(test, 0) # output:array([3, 3, 1])
np.argmax(test, 1) # output:array([2, 2, 0, 0])
Returns:
A Tensor of type output_type.
''' # correct_prediction = tf.equal(tf.arg_max(y, 1), tf.arg_max(y_, 1)) # Warning
correct_prediction = tf.equal(tf.argmax(y, axis=1), tf.argmax(y_, axis=1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})) # The result is around 0.91.

Tensorflow - Implement for a Softmax Regression Model on MNIST.的更多相关文章

  1. Tensorflow - Implement for a Convolutional Neural Network on MNIST.

    Coding according to TensorFlow 官方文档中文版 中文注释源于:tf.truncated_normal与tf.random_normal TF-卷积函数 tf.nn.con ...

  2. 基于MNIST数据的softmax regression

    跟着tensorflow上mnist基本机器学习教程联系 首先了解sklearn接口: sklearn.linear_model.LogisticRegression In the multiclas ...

  3. TensorFlow(2)Softmax Regression

    Softmax Regression Chapter Basics generate random Tensors Three usual activation function in Neural ...

  4. 学习笔记TF024:TensorFlow实现Softmax Regression(回归)识别手写数字

    TensorFlow实现Softmax Regression(回归)识别手写数字.MNIST(Mixed National Institute of Standards and Technology ...

  5. TensorFlow实战之Softmax Regression识别手写数字

         关于本文说明,本人原博客地址位于http://blog.csdn.net/qq_37608890,本文来自笔者于2018年02月21日 23:10:04所撰写内容(http://blog.c ...

  6. TensorFlow实现Softmax Regression识别手写数字

    本章已机器学习领域的Hello World任务----MNIST手写识别做为TensorFlow的开始.MNIST是一个非常简单的机器视觉数据集,是由几万张28像素*28像素的手写数字组成,这些图片只 ...

  7. (六)6.10 Neurons Networks implements of softmax regression

    softmax可以看做只有输入和输出的Neurons Networks,如下图: 其参数数量为k*(n+1) ,但在本实现中没有加入截距项,所以参数为k*n的矩阵. 对损失函数J(θ)的形式有: 算法 ...

  8. CS229 6.10 Neurons Networks implements of softmax regression

    softmax可以看做只有输入和输出的Neurons Networks,如下图: 其参数数量为k*(n+1) ,但在本实现中没有加入截距项,所以参数为k*n的矩阵. 对损失函数J(θ)的形式有: 算法 ...

  9. Exercise : Softmax Regression

    Step 0: Initialize constants and parameters Step 1: Load data Step 2: Implement softmaxCost Implemen ...

随机推荐

  1. SPOJ 4487. Can you answer these queries VI splay

    题目链接:点击打开链接 题意比較明显,不赘述. 删除时能够把i-1转到根,把i+1转到根下 则i点就在 根右子树 的左子树,且仅仅有i这一个 点 #include<stdio.h> #in ...

  2. Oracle分析函数(一)

    (一)分析函数语法 function_name(<argument>,<argument>...) over(<partition by clause><or ...

  3. 纸质文稿如何生成PDF

    步骤: (1) 将即将要转换的文稿单张向下放入打印机. (2) 将打印设备(打印机)连接至你的电脑. (3) 打开控制面板,点击"查看设备和打印机". (4) 找到你当前的打印设备 ...

  4. iOS学小程序从0到发布(适合iOS开发看)

    Emmmm,最近一波失业潮.富某康.某团.摩某.京某.知某.某浪.58 某大面积裁员,那么在这个千钧一发之际,单纯iOS开发也着实不好过,回过头看一下,裁掉的都是单一选手,为了节约成本公司留下的都是身 ...

  5. iOS之oc与html之间的交互(oc中调用js的方法)

    一.运行的效果图 1.刚开始的效果   2.运行结束后的效果   二.准备工作 1.准备一个html文件导入到oc工程中 2.jiaohu.html文件的原始内容   3.从oc语言中操作.html文 ...

  6. jquery toggleclass方法

    给元素更改样式,一般使用 addClass() 和removeClass() jquery官方文档 对 addClass的介绍: Adds the specified class(es) to eac ...

  7. Python绘制奥运五环

    绘制奥运五环主要涉及到Python中的turtle绘图库运用: turtle.forward(distance) 向当前画笔方向移动distance像素长度 turtle.backward(dista ...

  8. activemq的高级特性:消息存储持久化

    activemq的高级特性之消息存储持久化 有基于文件的,数据库的,内存的.默认的是基于文件的,在安装目录/data/kahadb.在conf/activemq.xml文件中. <persist ...

  9. python2与python3的input函数的区别

    Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...

  10. 20155204 2016-2017-2 《Java程序设计》第2周学习总结

    20155204 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 本章主要学习了Java语言的基础语法,基本同C语言逻辑相通,比较着学不算难理解,包括了一些简 ...