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. java点滴之MulticastSocket的使用

    一基本概念 该类恰是上文介绍的DatagramSocket的子类. DatagramSocket仅仅同意数据报发送给指定的目标地址,而MulticastSocket能够将数据报以广播的方式发送到多个c ...

  2. 直接在apk中添加资源的研究

    原文 http://blog.votzone.com/2018/05/12/apk-merge.html 之前接手过一个sdk的开发工作,在开发过程中有一个很重要的点就是尽量使用代码来创建控件,资源文 ...

  3. Java中的集合框架-Collections和Arrays

    上一篇<Java中的集合框架-Map>把集合框架中的键值对容器Map中常用的知识记录了一下,本节记录一下集合框架的两个工具类Collections和Arrays 一,Collections ...

  4. ios - 沙盒和NSBundle

    沙盒 1.沙盒机制介绍 iOS中的沙盒机制是一种安全体系.每个iOS程序都有一个独立的文件系统(存储空间),而且只能在对应的文件系统中进行操作,此区域被称为沙盒.应用必须待在自己的沙盒里,其他应用不能 ...

  5. java核心技术-多线程之基本使用

    多线程程序好处就是可以提高cpu使用率和系统的性能.这里举个例子,民以食为天,咱们以餐馆为例(后面基本上都用餐馆作为对象),后面如果没有特殊说明均采用本节相关术语,围绕餐馆我们可以抽象出如下几个角色以 ...

  6. 浅谈JS异步轮询和单线程机制

    单线程特点执行异步操作 js是单线程语言,浏览器只分配给js一个主线程,用来执行任务(函数),但一次只能执行一个任务,这些任务就会排队形成一个任务队列排队等候执行.一般而已,相对耗时的操作是要通过异步 ...

  7. ubuntu 如何进行文件、夹删除等操作

    rm [选项] 文件-f, --force 强力删除,不要求确认-i 每删除一个文件或进入一个子目录都要求确认-I 在删除超过三个文件或者递归删除前要求确认-r, -R 递归删除子目录-d, --di ...

  8. 用CSS/CSS3 实现水平居中和垂直居中,水平垂直居中的方式

    一.水平居中 (1)行内元素解决方案:父为块元素+text-align: center 只需要把行内元素包裹在一个属性display为block的父层元素中,并且把父层元素添加如下属性即可: 使用te ...

  9. VS2015创建WDK的问题

    在微软官网找了半天.. 搜索window driver kit,好吧.进入一页英文页面.. https://docs.microsoft.com/en-us/windows-hardware/driv ...

  10. Python学习 :常用模块(四)----- 配置文档

    常用模块(四) 八.configparser 模块 官方介绍:A configuration file consists of sections, lead by a "[section]& ...