使用tensorflow的softmax进行mnist识别
tensorflow真是方便,看来深度学习需要怎么使用框架、如何建模~
'''
softmax classifier for mnist created on 2019.9.28
author: vince
'''
import math
import logging
import numpy
import random
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
from sklearn.metrics import accuracy_score def main():
logging.basicConfig(level = logging.INFO,
format = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S'); logging.info("trainning begin."); mnist = read_data_sets('../data/MNIST',one_hot=True) # MNIST_data指的是存放数据的文件夹路径,one_hot=True 为采用one_hot的编码方式编码标签 x = tf.placeholder(tf.float32, [None, 784]);
w = tf.Variable(tf.zeros([784, 10]));
b = tf.Variable(tf.zeros([10]));
y = tf.matmul(x, w) + b; y_ = tf.placeholder(tf.float32, [None, 10]); cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = y, labels = y_));
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy); sess = tf.InteractiveSession();
tf.global_variables_initializer().run();
for _ in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100);
sess.run(train_step, feed_dict = {x : batch_xs, y_ : batch_ys}); logging.info("trainning end.");
logging.info("testing begin."); correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1));
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32));
print(sess.run(accuracy, feed_dict = {x : mnist.test.images, y_:mnist.test.labels})); logging.info("testing end."); if __name__ == "__main__":
main();
使用tensorflow的softmax进行mnist识别的更多相关文章
- 学习笔记TF024:TensorFlow实现Softmax Regression(回归)识别手写数字
TensorFlow实现Softmax Regression(回归)识别手写数字.MNIST(Mixed National Institute of Standards and Technology ...
- 使用tensorflow实现cnn进行mnist识别
第一个CNN代码,暂时对于CNN的BP还不熟悉.但是通过这个代码对于tensorflow的运行机制有了初步的理解 ''' softmax classifier for mnist created on ...
- TensorFlow 入门之手写识别(MNIST) softmax算法
TensorFlow 入门之手写识别(MNIST) softmax算法 MNIST flyu6 softmax回归 softmax回归算法 TensorFlow实现softmax softmax回归算 ...
- TensorFlow 入门之手写识别(MNIST) softmax算法 二
TensorFlow 入门之手写识别(MNIST) softmax算法 二 MNIST Fly softmax回归 softmax回归算法 TensorFlow实现softmax softmax回归算 ...
- TensorFlow 之 手写数字识别MNIST
官方文档: MNIST For ML Beginners - https://www.tensorflow.org/get_started/mnist/beginners Deep MNIST for ...
- 深度学习-tensorflow学习笔记(1)-MNIST手写字体识别预备知识
深度学习-tensorflow学习笔记(1)-MNIST手写字体识别预备知识 在tf第一个例子的时候需要很多预备知识. tf基本知识 香农熵 交叉熵代价函数cross-entropy 卷积神经网络 s ...
- Tensorflow编程基础之Mnist手写识别实验+关于cross_entropy的理解
好久没有静下心来写点东西了,最近好像又回到了高中时候的状态,休息不好,无法全心学习,恶性循环,现在终于调整的好一点了,听着纯音乐突然非常伤感,那些曾经快乐的大学时光啊,突然又慢慢的一下子出现在了眼前, ...
- TensorFlow 入门之手写识别(MNIST) 数据处理 一
TensorFlow 入门之手写识别(MNIST) 数据处理 一 MNIST Fly softmax回归 准备数据 解压 与 重构 手写识别入门 MNIST手写数据集 图片以及标签的数据格式处理 准备 ...
- TensorFlow实现Softmax Regression识别手写数字
本章已机器学习领域的Hello World任务----MNIST手写识别做为TensorFlow的开始.MNIST是一个非常简单的机器视觉数据集,是由几万张28像素*28像素的手写数字组成,这些图片只 ...
随机推荐
- 网站提权之MSF骚操作
当我们在进行web渗透测试的时候,拿到了webshell,但是在执行net user.whoami.类似的命令会发现怎么好像用不了,没有回显,权限不够,这可怎么办呐? 测试环境: 内网,没钱买服务器, ...
- svg和css3创建环形渐变进度条
在负责的项目中,有一个环形渐变读取进度的效果的需求,于是在网上查阅相关资料整理一下.代码如下: <!DOCTYPE html> <html lang="en"&g ...
- 从String到==和hashcode
public static void main(String[] args) { String s1 = "ni"; String s2 = "hao"; St ...
- linux 安装 memcached
1.Linux系统安装memcached,首先要先安装libevent库. yum install libevent libevent-deve 2.安装memcached yum install - ...
- ES6的Proxy
最近在Javascript的设计编程中,用到的那个单例模式,感觉就类似一种代理的思想[其实就是缓存的一种机制],单例模式就是: function getSingle(fn){ var result; ...
- 【colab pytorch】使用tensorboardcolab可视化
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from ...
- Prometheus 监控平台的搭建
1. 环境准备 两台ubuntu 16.04 服务器内网IP 作用 安装软件 172.16.4.11 监控的服务端 Prometheus( ...
- LoadRunner初入门(安装)
在经过了两天网上找软件-真机上装软件-完了发现真机不能用(不能用的原因就是IE不能打开 试了很多方法现在真机上的ie变成了ie8英文版),果断用上了虚拟机 虚拟机刚开始要装镜像 一开始下的是64位的发 ...
- PHP把图片存入数据库(非路径)【待测试】
大部分人的图片上传都是保存一个路径到数据库,这样在插入时确实快,也符合web的特点,但是在删除时就很麻烦,需要找到文件并删除,该代码能够把代码直接存入数据库,删除时一并删除.请注意:这样的话数据库大小 ...
- c++作业22题
一.单选题(共22题,100.0分) 1 已知int i=5,下列do-while循环语句的循环次数是 do{ cout<<i - -<<endl; i - -; }while ...