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. jquery css选择器

    1. $('node+next') == $('node').next() 2. $('node~siblings') == $('node').nextAll(); 3. :gt(index)大于i ...

  2. HTTPweb服务器——HTTP基本知识

    对于HTTP来说,我们不需要说太多,HTTP又叫做超文本传输协议,现如今利用最多的版本是1.1版本. HTTP的特点:C/S模式,B/S模式 简单快速:基于请求和响应,请求只需要传送请求方法和路径.  ...

  3. 什么是Spring框架? Spring框架有哪些主要的模块?

    Spring框架是一个为java应用程序的开发提供了综合,广泛的基础性支持的java平台.Spring帮助开发者解决了开发中基础性的问题,使得开发人员可以专注于应用程序的开发.Spring框架本身亦是 ...

  4. js怎样得出数组中某个数据最大连续出现的次数

     1:js怎样得出数组中某个数据最大连续出现的次数 var test=[1,2,3,3,2,2,2,3,3,3,3,5,3,3,3,3,3] ;    var j  = 0 ;    var max  ...

  5. 19-3-15Python中闭包,迭代器,递归

    函数名的使用 函数名可以当作值赋值给变量 函数名可以当作元素放到容器里 闭包 一个嵌套函数 在嵌套函数内的函数使用外部(非全局的变量) 满足以上两条就是闭包 python中闭包,会进行内存驻留,普通函 ...

  6. thinkphp5.1 学习笔记 【多态关联】

    $result = Draft::update($input, ['id' => $input['id']], true); if (!empty(array_get($input, 'hous ...

  7. 关于pythond在终端中运行

    下载python并安装后,如果想要在终端中直接运行,我们需要配置环境变量. 在计算机右击选择属性,,选择高级属性,点击环境变量,,即可新建环境变量, ,然后可以在终端中运行python解释器.

  8. Python学习 :socket基础

    socket基础 什么是socket? - socket为接口通道,内部封装了IP地址.端口.协议等信息:我们可以看作是以前的通过电话机拨号上网的年代,socket即为电话线 socket通信流程 我 ...

  9. Go类型特性-学习笔记

    1.组合 Go语言使用组合来完成类型的设计,设计某一类型时想要拥有其他类型的功能只需要将其他类型嵌入该类型即可. 2.接口 与其他语言不同的是,编译器会自动判断该类型是否符合某正在使用的接口,甚至不需 ...

  10. 一道hive面试题:explode map字段

    需要找到每个学生最好的课程和成绩,最差的课程和成绩,以及各科的平均分 文本数据如下: name scores张三 语文:,数学:,英语:,历史:,政治:,物理:,化学:,地理:,生物: 李四 语文:, ...