softmax+交叉熵

softmax函数与交叉熵损失详解 由于Softmax函数的数值计算过程中,很容易因为输出节点的输出值比较大而发生数值溢出的现象,在计算交叉熵的时候也可能会出现数值溢出的问题。softmax直白来说就是将原来输出是3,1,-3通过softmax函数一作用,就映射成为(0,1)的值,而这些值的累和为1(满足概率的性质),那么我们就可以将它理解成概率,在最后选取输出结点的时候,我们就可以选取概率最大(也就是值对应最大的)结点,作为我们的预测目标!结果还是挺明显的,经过使用指数形式的Softmax函数能够将差距大的数值距离拉的更大。 阅读详情

1、softmax函数

softmax函数的定义为:
在这里插入图片描述
softmax函数的特点:
● 函数值在[0,1]之间;
● 所有的softmax(xi)相加的总和是1
面对一个分类问题,能将输出的yi转换成[0,1]的概率,选择最大的概率yi作为分类的结果。
在这里插入图片描述
sigmoid函数定义为:
在这里插入图片描述
sigmoid函数将每个yi映射到[0,1]之间,但每个yi之间是相互独立的,∑yi与1没有关系,可以用作二分类;而softmax函数的本质是将一个k维数据[a1,a2,a3,…,ak]映射成另外一个K维向量[b1,b2,b3,…,bk],每个值之间是相互存在关系的,∑ai=∑bi=1,可以用于多分类问题,选取权重最大的一维。

区分sigmoid和softmax使用的场景:
1、有四个类别的音乐,分别为:古典音乐、乡村音乐、摇滚乐和爵士乐,假设每个训练样本只会被打上一个标签(即:一首歌只能属于这四种音乐类型的其中一种),此时你应该使用类别数 k = 4 的softmax回归。
2、有四个类别如下:人声音乐、舞曲、影视原声、流行歌曲,那么这些类别之间并不是互斥的。例如:一首歌曲可以来源于影视原声,同时也包含人声 。这种情况下,使用4个二分类的 logistic 回归分类器更为合适。这样,对于每个新的音乐作品 ,我们的算法可以分别判断它是否属于各个类别。

计算机视觉领域:
1、假设这三个

关于交叉熵(Cross Entropy)与Softmax 目录 写在前面 KL散度 交叉熵 Softmax 交叉熵与Softmax的关系 交叉熵损失 Softmax的求导 堆叠+向量化 其他关于Softmax函数的问题 赠品 写在前面 Softmax、交叉熵、交叉熵损失是机器学习与神经网络模型的重要组成部分,一般来说,Softmax一般用于criterion(标准),交叉熵与交叉熵损失用来衡量模型预测与实际结果间的差别并产生用于反向传播的梯度。... 阅读详情

相关推荐

【深度学习】softmax和交叉熵的配合求导

在分类问题中,尤其是在神经网络中,交叉熵函数非常常见。因为经常涉及到分类问题,需要计算各类别的概率,所以交叉熵损失函数又都是与sigmoid函数或者softmax函数成对出现。

Dong_ZH的博客 9863

交叉熵与softmax

介绍改进神经网络的基本方法:交叉熵代价函数与softmax。 二次代价函数 之前我们一直使用二次代价函数,貌似在一定程度上也挺work。但其实,当输入值与目标值差距很大时,二次代价函数就不是很恰当了;这是因为当差距很大时,此函数的学习速率会很慢。我们可以通过一个简单的例子观察这种变化: 假设我们只使用一个神经元与一个输出神经元,定义代价函数为: C=(y−a)22C=(y−a)...

crazy_scott的博客 6139

【PyTorch】第九节:Softmax 函数与交叉熵函数

本实验主要讲解了分类问题中的二分类问题和多分类问题之间的区别,以及每种问题下的交叉熵损失的定义方法。由于多分类问题的输出为属于每个类别的概率,要求概率和为 1 。因此,我们还介绍了如何利用 Softmax 函数,处理神经网络的输出,使其满足损失函数的格式要求。

荷叶田田的博客 3943

Softmax 与交叉熵:数学原理与梯度推导

Softmax 函数和交叉熵损失函数的组合在多分类任务中非常高效。Softmax 函数将神经网络的输出转化为概率分布,而交叉熵损失函数则衡量预测分布与真实分布之间的差异。这种组合不仅能够有效衡量模型的预测性能,还能在反向传播过程中提供简洁且稳定的梯度更新。希望本文能够帮助你更好地理解 Softmax 和交叉熵的数学原理及其在深度学习中的应用。

Mike的博客 1521

关于交叉熵下softmax和sigmoid的求导

原创不易,转载请注明出处 ^ _ ^ 1、 交叉熵 + sigmoid 反向传播 sigmoid函数: 这里xxx表示神经网络最后一层输出的一个神经元的激活值 σ(x)=11+exp(−x)\sigma(x) = \frac{1}{1+exp(-x)}σ(x)=1+exp(−x)1​ sigmoid函数对xxx求导: ∂σ(x)∂x=σ(x)(1−σ(x))\frac{\partial{\sigma(x)}}{\partial{x}} = \sigma(x)(1-\sigma(x))∂x∂σ(x)​=σ(

Jerry_Lu_ruc的博客 2331

AlphaPose复现配置教程

AlphaPose是一种准确的多人姿态估计器,这是第一个在COCO数据集上达到70+ mAP (75 mAP)和在MPII数据集上达到80+ mAP (82.1 mAP)的开源系统。为了匹配跨帧的同一人的姿态,我们还提供了一种高效的在线姿态跟踪器,称为Pose Flow。这是第一个在PoseTrack挑战数据集上达到60+ mAP (66.5 mAP)和50+ MOTA (58.3 MOTA)的开源在线姿态跟踪器。AlphaPose支持Linux和Windows操作系统!指路👉。

m0_56661101的博客 4527

GIS分析-利用K-Means方法进行地震分析

通过“聚类”可以获得有关我们所拥有的数据的各种线索,这是数据挖掘技术之一。分析创建的组有助于决策过程。在这项研究中,我们将使用数据挖掘工具之一的K-Means方法研究安纳托利亚东部地区近100年发生的地震的空间分布,并试图获得有用的信息,以供未来的研究使用。我从局地震目录页面获得了研究所需的地震数据,并从获得了区域边界数据。

gis收藏家的博客 1570

YOLOv11多模态融合实战:基于YOLOFuse的RGB与红外线(IR)协同检测技术解析

本文深入解析了YOLOv11多模态融合技术,重点介绍基于YOLOFuse框架的RGB与红外线(IR)协同检测方法。通过动态权重分配、跨模态特征对齐等创新设计,实现在低光照等复杂环境下的高精度目标检测,mAP提升高达37%。文章包含实战案例、训练技巧和部署方案,为计算机视觉开发者提供完整的多模态融合解决方案。

weixin_29038345的博客 292

高通QCS2290 SecureBoot全流程实战:从密钥生成到NON-HLOS.bin生成

本文详细拆解了高通QCS2290平台SecureBoot安全启动技术的端到端实战流程。从开发环境搭建、RSA密钥对生成与证书链构建,到关键XML配置文件修改、固件编译与数字签名,最终完成NON-HLOS.bin集成打包,为嵌入式开发者提供了一份清晰、可操作的安全启动部署指南。

weixin_28273593的博客 299

【FOC无刷电机控制】六步换向、FOC,STM32cubemx从零开始搭建BLDC六步换相代码、FOC代码(基于霍尔传感器)

FOC、六步换相,无刷电机控制

xifan的博客 3万+

汽车标定技术(七)--英飞凌TC3xx_Overlay实现页切换

今天说要开个专栏讲讲XCP标定,但在将标定之前,先把英飞凌专门为标定功能设计overlay功能讲解清楚。

认真搞搞汽车MCU 4015

模型实战(31)之 yolo26 实现对手部关键点数据集 的训练与关键点检测

模型实战(31)之 yolo26 实现对手部关键点数据集 的训练与关键点检测

yohnyang的博客 209

人工智能在慢病管理中的具体应用全集:从技术落地到场景创新

这一成果的取得,得益于 AI 对居民血压数据的实时监测和分析,以及及时的干预措施。据统计,医疗支出下降了 18%,这主要是由于 AI 慢病管理系统实现了对慢病患者的早筛早诊早治,减少了并发症的发生,降低了医疗资源的浪费,从而减轻了患者和社会的医疗负担。医院信息系统(HIS)、电子病历(EMR)、区域卫生平台、可穿戴设备(如三诺血糖仪、华为手环)、第三方健康APP以及体检中心的数据往往采用不同的数据标准和格式(如HL7、FHIR、JSON、CSV等),且存储在相互隔离的系统中,形成典型的数据孤岛。

AllenLV的博客 2091

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: pytorch学习笔记十:权值初始化的十种方法
下一篇: pytorch学习笔记十一:损失函数
Dear_林
博客等级 码龄5年 37粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值