TensorFlow实现Softmax Regression手写数字识别

深度学习入门(七)-----手写数字识别 one-hot表示是仅正确解标签为1,其余皆为0的数组,就像[0,0,1,0,0,0,0,0,0,0]这样。实际上,上例中a的各元素的大小关系和y的各元素的大小关系并没有改变。load_mnist函数以“(训练图像 ,训练标签 ),(测试图像,测试标签 )”的形式返回读入的MNIST数据。在实际的问题中,由于指数函数的运算需要一定的计算机运算量,因此输出层的softmax函数一般会被省略。比如,对于某个输入图像,预测是图中的数字0到9中的哪一个的问题(10类别分类问题),将输出层的神经元设定为10个。 阅读详情

这篇文章是学习《TensorFlow实战-黄文坚》过程中的笔记,具体的实现细节请参考原书。

1.MNIST数据集

MNIST(Mixed National Istisute of Standards and Technology databast)是一个简单的机器视觉数据集,由几万张28*28像素的手写数字图片组成,图片只包含灰度信息。目标是使用Softmax对手写数字图片进行分类,数字为0~9一共10类。MNIST数据集由55000个训练样本,10000个测试样本,5000个验证样本。每一个样本都有对应的标注信息(label)。在样本集上训练模型,在验证集上检验效果病决定何时完成训练,最后在测试集上评测模型的效果。由于样本是28*28像素,展开之后会变成784维的向量(每一个点对应一个维度),这是一种简单的处理方法,舍去了图片的二维结构方面的信息。最终的训练数据的特征是一个55000*784的Tensor,第一个维度是图片的编号,第二个维度是图片中像素点的编号。训练数据的Label是55000*10的Tensor,对10个类进行one-hot编码处理,Lebel是一个10维的向量,只有一个值为1,其余全部为零。
在spyder中载入数据集后,可以用如下命令查看数据的维度(完整代码见之后的实现部分):

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

print(mnist.train.images.shape, mnist.train.labels.shape)
print(mnist.test.images.shape, mnist.test.labels.shape)
print(mnist.validation.images.shape, mnist.validation.labels.shape)

输出结果

(55000, 784) (55000, 10)    #训练集和对应标签的维度
(10000, 784) (10000, 10)    #测试集和对应标签的维度
(5000, 784) (5000, 10)      #验证集和对应标签的维度

2.one-hot编码

分类器默认数据数据是连续的,并且是有序的,但实际使用的分类标签并不是有序的,而是随机分配的。one-hot编码又称一位有效编码,其方法是使用N位状态寄存器来对N个状态进行编码,每个状态都由他独立的寄存器位,并且在任意时候,其中只有一位有效。可以这样理解,对于每一个特征,如果它有m个可能值,那么经过独热编码后,就变成了m个二元特征。并且,这些特征互斥,每次只有一个激活。因此,数据会变成稀疏的。
这样做的好处主要有:
1. 解决了分类器不好处理属性数据的问题
2. 在一定程度上也起到了扩充特征的作用

3.Softmax Regression算法

Softmax的原理比较简单,将可以判定为某一类的特征相加,转化为判定是某一类的概率,分别计算每一种类别对应的概率,再通过比较这些概率的大小,找出概率最大的类对应的数字作为模型的输出结果。其中,权重是模型根据数据自动学习,训练得出。

使用TensorFlow实现Softmax算法

首先载入TensorFlow库,并新建一个InteractiveSession(会将这个session注册为默认的session,之后的运算也默认在这个session中,不同session之间的数据和运算应该都是相互独立的)。接下来创建一个Placeholder,即输入数据的地方。其中第一个参数是数据类型,第二个参数是tensor的shape,None代表不限条数的输入。

import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, [None, 784])

接下来给Softmax Regression模型中的weights和biases创建Variable对象。因为Softmax Regression模型比较简单,将weights和biases都初始化为0,不会影响训练的过程。Variable对象在模型训练迭代中是持久化的,它可以长期存在并且在每轮迭代中被更新;另一种存储数据的tensor在使用之后则会消失。

W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))

利用y=softmax(Wx + b)实现Softmax Regression算法:
y = tf.nn.softmax(tf.matmul(x, W) + b) #注意x和W的行数和列数要满足矩阵乘法的运算规则
其中,tf.nn包含了大量神经网络的组件,softmax只是其中的一个函数。

为训练模型,需要定义一个loss function来描述模型对问题的分类精度。Loss越小,代表分类结果与真实值的偏差越小,拟合结果越精确。在初始化过程中,给模型填充了全零的参数,这样模型会有一个初始的loss,在训练过程中不断将这个loss减小,直到达到全局或者局部的最优值。对于多分类问题,通常使用cross-entropy作为loss function。在TensorFlow中定义cross-entropy:

y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

其中,tf.reduce_sum函数的意义为降维求和,可以参考知乎

接下来需要定义优化算法,这里采用常见的**随机梯度下降算法**SGD(Stochastic Gradient Descent)
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
设置学习速率为0.5,优化目标设定为cross-entropy最小,得到训练操作的train_step

下一步使用全局参数初始化器,并直接执行run方法:
tf.global_variables_initializer().run()

最后迭代执行训练操作:

for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    train_step.run({x:batch_xs, y_:batch_ys})

这里每次随机从训练集中抽取100条样本构成一个mini-batch,并feed给placeholder,然后调用train_step对这些样本进行训练。使用县部分样本进行训练称为随机梯度下降,大多数时候这种方法比全样本训练的收敛速度快很多。

完成训练后需要对模型的准确率进行验证。

correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))    #判断是否正确
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))  #计算正确率
print(accuracy.eval({x:mnist.test.images, y_:mnist.test.labels})    #输出

其中,tf.argmax就是返回最大的那个数值所在的下标,具体的参数定义可见 tf.argmax()以及axis解析,注意数组维度的起始值为0。

4.主要步骤

在TensorFlow上实现一个机器学习算法,主要工作可以分为以下部分:
1. 定义算法公式,也就是神经网络forward时的计算
2. 定义loss,选定优化器,定义loss function
3. 迭代对数据进行训练
4. 在测试集或验证集上对准确率进行评测

注意:定义的各个公式只是Computation Graph,在执行这些代码时,计算实际上还没有发生,直到调用run方法,并且feed数据时,计算才真正执行。其中的cross-entropy、train_step、accuracy等都是计算图中的节点,并不是数据的结果,可以用run方法来执行节点或者说运算操作来获取结果。

5.完整的代码实现

from tensorflow.examples.tutorials.mnist import input_data  # load mnist data
import tensorflow as tf

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

print(mnist.train.images.shape, mnist.train.labels.shape)
print(mnist.train.images.shape, mnist.test.labels.shape)
print(mnist.train.images.shape, mnist.validation.labels.shape)


sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))

y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

tf.global_variables_initializer().run()

for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    train_step.run({x:batch_xs, y_:batch_ys})

correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(accuracy.eval({x:mnist.test.images, y_:mnist.test.labels}))

6.总结

开始进入了机器学习这个天坑,这篇文章只是对书中一些关键点做了一些笔记,对一些不懂的细节查找资料进行解释。希望之后能够耐心坚持下去~

参考链接:
http://blog.youkuaiyun.com/dulingtingzi/article/details/51374487
https://www.zhihu.com/question/51325408?from=profile_question_card
http://blog.youkuaiyun.com/qq575379110/article/details/70538051

mnist数据识别,softmax回归识别,全连接神经网络是被,CNN网络识别 立即下载

相关推荐

python softmax实现手写数字识别

python softmax实现手写数字识别, deep learning 使用python TensorFlow实现

softmax回归实现手写数字识别

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KIAOq2DU-1689218911304)(output_6_2.png)]第一列是label,其余列是图片像素矩阵的平铺向量,共784个像素值。784个特征太多了,而且大多数都是0的稀疏矩阵,计算没什么意义。这里利用PCA多特征进行降维,减少特征的维度。

a1691125058的博客 592

保姆级拆解:HP 1312NF/CM1415打印机进纸离合器清洁与更换全记录(附B站/油管视频指路)

本文详细记录了HP 1312NF打印机进纸离合器故障的诊断与修复全过程,包括故障判断、工具准备、拆解步骤、清洁更换技巧及预防措施。特别针对离合器内部海绵老化粘连问题,提供了电工胶布和硬纸片两种实用替代方案,并附有B站/油管视频指路,帮助用户轻松完成打印机维修。

weixin_31102231的博客 376

【深度学习】Softmax实现手写数字识别

本次案例中,你需要用python实现Softmax回归方法,用于MNIST手写数字数据集分类任务。你需要完成前向计算loss和参数更新。你需要首先实现Softmax函数和交叉熵损失函数的计算。ysoftmaxWTxbLCrossEntropyylabelysoftmaxWTxbLCrossEntropyylabel在更新参数的过程中,你需要实现参数梯度的计算,并按照随机梯度下降法来更新参数。

你一定能够成为你想要去成为的人。 2151

用朴素贝叶斯分类模型判断病人是否感染幽门螺杆菌(Python实现)

朴素贝叶斯,Python

weixin_56529327的博客 1160

Windows平台MuJoCo仿真环境配置与Qt集成实战

本文详细介绍了在Windows平台上配置MuJoCo物理仿真环境并与Qt框架集成的完整实战流程。内容涵盖从环境准备、库文件配置、项目创建到核心代码编写的每一步,重点解决了Windows下常见的编译链接错误和路径问题,帮助开发者在Windows系统中高效搭建机器人仿真与可视化控制开发环境。

weixin_29221753的博客 172

深度学习实验:Softmax实现手写数字识别

深度学习项目:Softmax实现手写数字识别

suic009的博客 3916

保姆级教程:在PyCharm里用Continue插件一键接入DeepSeek API(含乱码修复)

本文详细介绍了如何在PyCharm中通过Continue插件无缝集成DeepSeek API,提供从环境准备到高级配置的全流程指南,包括解决常见的乱码问题。通过本教程,开发者可以轻松实现AI编程助手的高效调用,提升代码编写和调试效率。

weixin_30275415的博客 850

TensorFlow实现MNIST识别(softmax)

  1. MNIST的介绍 MNIST数据集是一个入门级的计算机视觉数据集,包含数万张28x28像素的灰度手写数字图片,其中数字的范围从0到9。它是机器学习领域的经典问题。 官网:http://yann.lecun.com/exdb/mnist/ 这个数据集包含60000个训练样本(55000样本的训练集,5000样本的验证集),以及10000个测试样本。 文件 ...

西之可乐的专栏 2298

微信小程序转化数据API自归因实战:PHP实现与2025升级要点解析

本文详细解析了2025年微信小程序转化数据API自归因的升级要点与PHP实战实现。核心变化包括接口地址更新、固定access_token的获取方式,以及新增timestamp与nonce等安全参数。文章提供了完整的PHP代码示例,帮助开发者高效完成数据上报,优化腾讯广告投放效果。

git9versioner的博客 989

BUCK 电路详解

参考内容: 手撕Buck!Buck公式推导过程 电力电子的基础应用 《精通开关电源设计(第二版)》 Buck电源芯片输出有问题?检查这几样 原来PWM这么简单! BUCK 电路构建 根据高中所学习的物理知识可以很容易的想到,使用一个滑动变阻器即可实现降压和稳压的效果。当负载波动时,通过改变滑动变阻器的阻值,可以调节负载所获得的电压。但是使用滑动变阻器的劣势也很明显,大量的耗能会导致器件温度快速升高。 上面所提到的电路主要缺点在于导通器件(变阻器或三极管)本身存在耗能,那么有没有不会耗能的导通器件呢?

Guanngxu的博客 3991

Tensorflow实现Softmax Regression识别手写数字

一、MNIST数据集   MNIST数据集是一个非常简单的机器视觉数据集,由几万张28*28像素的手写数字组成,且这些数字只包含灰度值信息。 二、TensorFlow代码实现 1 # -*- coding: utf-8 -*- 2 """ 3 Created on Thu May 16 21:39:25 2019 4 5 @author: CFF 6 """ ...

weixin_33711641的博客 156

自抗扰控制(ADRC)理论与工程实践:8.2 模糊ADRC、神经网络ADRC等智能融合变体

智能融合ADRC变体概述 自抗扰控制(ADRC)与智能控制方法(如模糊逻辑、神经网络)的融合,旨在突破传统ADRC在非线性、时变系统中的应用局限。智能融合ADRC主要通过以下方式实现性能提升: 模糊ADRC 参数自整定:利用模糊推理在线调节ADRC带宽参数,实现自适应控制。 非线性反馈:用模糊控制器替代线性PD,灵活设计非线性控制策略。 优势:融入专家经验,无需精确模型;局限:依赖规则库设计,稳定性分析困难。 神经网络ADRC 增强ESO:用神经网络学习扰动动态,提高估计精度。

技术工作者 228

使用TensorFlow实现Softmax Regression识别手写数字

因为新冠病毒疫情,在家学习,没有带回什么书回家。今天在当当上网购的一本书《TensorFlow实战》到了,因为实验要使用BLSTM+CRF,所以先自己进行简单的学习,对照着里面的例子自己敲和理解,这里做一下记录。 这个例子使用简单的Softmax Regression进行MNIST手写数字识别。将灰度图片展开为28*28=784的一维向量,识别的结果为0-9共10个结果,所以有10个分类。下面是...

June0805的博客 327

SPAD IMX479规格_VOP

对于VOP的定义,很多人可能是不理解这一路的供电,实际上这一路供电是非常重要的,这是给器件SPAD供电,决定SPAD是否work,在大部分的paper以及大部分公司,基本都是叫VOP,名称是SPAD breakdown voltage power supply,严格意义上叫Operating Voltage,工作电压。当然有些公司也有一些其他叫法就不提了。其实大家可以明显的看出,典型值-20.5没有发生变化,市面上绝大多数VOP的典型值也都是在-20V这边。

致力于lidar应用开发 701

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Tensorflow实战1:Tensorflow实现Softmax Regression识别手写数字

实现过程的详细介绍 对Minist数据进行加载,利用Tensorflow提供的封装函数 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) 查看一下mnist数据集的情况,可以发现训练集有55000个...

I good vegetable a! 396

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Tensorflow实现softmax Regression识别手写数字(简单神经网络)

# ==================================================== #tensorflow实现softmax Regression识别手写数字 # #构造一个简单的神经网络不含隐藏层分成四步 # 1.定义算法公式,前向计算 # 2.定义loss函数,选择优化器,让优化器优化loss # 3.迭代对数据训练 # 4.用测试数据测得准...

xifengw的博客 236

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

TensorFlow实现Softmax Regression识别手写数字

代码(源代码都有详细的注释)和数据集可以在github下载: https://github.com/crazyyanchao/TensorFlow-HelloWorld 这个版本准确率在0.9173左右没有经过优化。但是展示了TensorFlow的总体使用方法。//# -* coding:UTF-8 *- //# TensorFlow实现Softmax Regression识别手写数字 impo

马超的博客 1248

TensorFlow 实现Softmax Regression识别手写数字

TensorFlow 实现Softmax Regression识别手写数字 1.数据准备 1.1.图像是28像素*28像素大小的灰度图片,即每个样本又784维特征(28*28 = 784);故丢弃图像的二维结构信息 ,图片变成一个很长的1维向量。空间结构信息,将在卷积神经网络被使用。 1.2 训练数据特征 :55000*784 第一维度 是图片编号;第二维度是图片中像素点编号。 1.3 数...

pain_gain0的博客 700

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

TensorFlow实现Softmax Regression(回归)识别手写数字。MNIST(Mixed National Institute of Standards and Technology database),简单机器视觉数据集,28X28像素手写数字,只有灰度值信息,空白部分为0,笔迹根据颜色深浅取[0, 1], 784维,丢弃二维空间信息,目标分0~9共10类。数据加载,data.r...

weixin_39693950的博客 239

TensorFlow实现 Softmax Regression 识别手写数字

#1.进入python环境 #python #2.加载数据集 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/",one_hot=True) #3.打印数据集的信息 print(mnist.train.images.shape,mni...

wfx18765903641的博客 296

Tensorflow 实现Softmax Regression手写数字识别

# -*- coding: utf-8 -*- """ Created on Sun Jul 21 23:01:29 2019 @author: hm """ import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # 导入数据 mnist = input_data.read_dat...

weixin_42206852的博客 153

《TensorfFlow实战》读书笔记(三) —— Tensorflow 实现 Softmax Regression 识别手写数字

《TensorfFlow实战》读书笔记(三) —— Tensorflow 实现 Softmax Regression 识别手写数字

dzdjt3104的博客 795

tensorflow实现softmax regression识别手写数字

from tensorflow.examples.tutorials.mnist import input_data  mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)  # 使用one-hot编码  print(mnist.train.images.shape, mnist.train.labels.shape) 

youxin1990122q的博客 329
上一篇: Ubuntu 16.04安装NVIDIA显卡驱动 、CUDA-8.0、cuDNN和TensorFlow问题及解决方法
下一篇: Batch Normalization详细解读
东风逍遥游
博客等级 码龄11年 56粉丝 7原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值