softmax_regression完成mnist手写体数据集的识别
---恢复内容开始---
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) x = tf.placeholder(tf.float32, [None, 784])
y_ = tf.placeholder(tf.float32, [None, 10]) W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b) # 根据y, y_构造交叉熵损失
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y))) # 有了损失,我们就可以用随机梯度下降针对模型的参数(W和b)进行优化
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess = tf.InteractiveSession() tf.global_variables_initializer().run() print('start training...') # 进行1000步梯度下降 for i in range(5000):
batch = mnist.train.next_batch(50)# 默认 shuffle=True
if i%100==0:
train_accuracy = accuracy.eval({x:batch[0], y_:batch[1]})
print("step:%d accuracy is %g" %(i , train_accuracy) ) sess.run(train_step, feed_dict={x: batch[0], y_: batch[1]}) #print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})) print(accuracy.eval(feed_dict={x:mnist.test.images,y_:mnist.test.labels}))
---恢复内容结束---
softmax_regression完成mnist手写体数据集的识别的更多相关文章
- 实现手写体 mnist 数据集的识别任务
实现手写体 mnist 数据集的识别任务,共分为三个模块文件,分别是描述网络结构的前向传播过程文件(mnist_forward.py). 描述网络参数优化方法的反向传播 过 程 文件 ( mnist_ ...
- R︱Softmax Regression建模 (MNIST 手写体识别和文档多分类应用)
本文转载自经管之家论坛, R语言中的Softmax Regression建模 (MNIST 手写体识别和文档多分类应用) R中的softmaxreg包,发自2016-09-09,链接:https:// ...
- 深度学习-mnist手写体识别
mnist手写体识别 Mnist数据集可以从官网下载,网址: http://yann.lecun.com/exdb/mnist/ 下载下来的数据集被分成两部分:55000行的训练数据集(mnist.t ...
- mnist 数据集的识别源码解析
在基本跑完识别代码后,再来谈一谈自己对代码的理解: 1 前向传播过程文件(mnist_forward.py) 第一个函数get_weight(shape, regularizer); 定义了 ...
- 使用 MNIST 图像识别数据集
机器学习领域中最迷人的主题之一是图像识别 (IR). 使用红外系统的示例包括使用指纹或视网膜识别的计算机登录程序和机场安全系统的扫描乘客脸寻找某种通缉名单上的个人.MNIST 数据集是可用于实验的简单 ...
- 导出MNIST的数据集
在TensorFlow的官方入门课程中,多次用到mnist数据集. mnist数据集是一个数字手写体图片库,但它的存储格式并非常见的图片格式,所有的图片都集中保存在四个扩展名为idx3-ubyte的二 ...
- 记录二:tensorflow2.0写MNIST手写体
最近学习神经网络,tensorflow,看了好多视频,查找了好多资料,感觉东西都没有融入自己的思维中.今天用tensorflow2.0写了一个MNIST手写体的版本,记录下学习的过程. 复现手写体识别 ...
- Android+TensorFlow+CNN+MNIST 手写数字识别实现
Android+TensorFlow+CNN+MNIST 手写数字识别实现 SkySeraph 2018 Email:skyseraph00#163.com 更多精彩请直接访问SkySeraph个人站 ...
- 深度学习-tensorflow学习笔记(2)-MNIST手写字体识别
深度学习-tensorflow学习笔记(2)-MNIST手写字体识别超级详细版 这是tf入门的第一个例子.minst应该是内置的数据集. 前置知识在学习笔记(1)里面讲过了 这里直接上代码 # -*- ...
随机推荐
- jqGrid Bootstrap
<!DOCTYPE html> <html lang="en"> <head> <!-- The jQuery library is a ...
- docker容器基础
一.docker容器基础6种名称空间:UTS.MOunt.IPC.PID.User.Net (1) Linux Namespaces:namespace 系统调用参数 隔离内容 内核版本 UTS ...
- E20180502-hm
inject vt. (给…)注射(药物等) ; (给…)注射(液体) ; (给…) 添加; (给…)投入(资金) ; reduce vt. 减少; 缩小; 使还原; 使变弱; vi. ...
- E20180422-hm
tint n. 浅色; 色彩,色泽; 气息,迹象,痕迹 vt. 染色; 着色于…; 染(发) introduce vt. 介绍; 引进; 提出; 作为…的开头; variation n. 变化,变动 ...
- 51nod 1133【贪心】
思路: 按照终点升序,然后遍历一下就好了: #include <bits/stdc++.h> using namespace std; typedef long long LL; cons ...
- IT兄弟连 JavaWeb教程 Servlet 状态管理 会话跟踪
HTTP协议是无状态的,我们的客户端与服务器的每一次请求与响应,我们服务器都没有记忆能力将客户端与服务器的多次交互数据进行存储与管理共有两种技术实现: ● 基于客户端实现:Cookie,将状态保存在 ...
- sybase修改默认字符集为cp936
原文地址:http://blog.sina.com.cn/s/blog_4d6854860100xn3f.html 报错信息:2402 error converting characters into ...
- python实现计数排序
计数排序有局限性,最小值和最大值决定着数组的长度,如果分配均匀的话可以用 # @File: count_sort import random def count_sort(li, max_num=10 ...
- New Land LightOJ - 1424
New Land LightOJ - 1424 题意:找出01矩阵中最大的完全由0组成的矩阵. 方法: 重点在于转化. 先预处理(i,j)点向上最长能取到的连续的全0条的长度.然后枚举某一行作为矩阵的 ...
- oracle 10g standby 设置
##########sample alter system set log_archive_dest_1 = 'LOCATION=USE_DB_RECOVERY_FILE_DEST' scope=bo ...