tensorflow 笔记10:tf.nn.sparse_softmax_cross_entropy_with_logits 函数
函数:tf.nn.sparse_softmax_cross_entropy_with_logits(_sentinel=None,labels=None,logits=None,name=None)
#如果遇到这个问题:Rank mismatch: Rank of labels (received 2) should equal rank of logits minus 1 (received 2). 一般是维度没有计算好;
函数是将softmax和cross_entropy放在一起计算,对于分类问题而言,最后一般都是一个单层全连接神经网络,比如softmax分类器居多,对这个函数而言,tensorflow神经网络中是没有softmax层,而是在这个函数中进行softmax函数的计算。
这里的logits通常是最后的全连接层的输出结果,labels是具体哪一类的标签,这个函数是直接使用标签数据的,而不是采用one-hot编码形式。
Args:
_sentinel: Used to prevent positional parameters. Internal, do not use.
labels: Tensor of shape [d_0, d_1, ..., d_{r-1}] (where r is rank of labels and result) and dtype int32 or int64. Each entry in labels must be an index in [0, num_classes).
Other values will raise an exception when this op is run on CPU, and return NaN for corresponding loss and gradient rows on GPU.
logits: Unscaled log probabilities of shape [d_0, d_1, ..., d_{r-1}, num_classes] and dtype float32 or float64.
name: A name for the operation (optional).
Returns:
A Tensor of the same shape as labels and of the same type as logits with the softmax cross entropy loss. Raises:
ValueError: If logits are scalars (need to have rank >= 1) or if the rank of the labels is not equal to the rank of the logits minus one.
用法:
labele:表示的训练数据的label信息
logits :表示的是模型计算出来的结果
如下例所示: batch_size = 5,num_class = 5,分为五类;
label 的shape为([batch_size,1]) #直接是分类后的结果,比如分五类,那么 就是[[3],[4]] logits 的shape为([batch_size,num_classes]) #softmax计算后的概率分布,对比上面,[[0.1,0.2,0.2,0.1,0.4],[0.1,0.1,0.1,0.1,0.6]]
以下是计算方法:

tensorflow 笔记10:tf.nn.sparse_softmax_cross_entropy_with_logits 函数的更多相关文章
- Tensorflow BatchNormalization详解:4_使用tf.nn.batch_normalization函数实现Batch Normalization操作
使用tf.nn.batch_normalization函数实现Batch Normalization操作 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 吴恩达deeplearnin ...
- 【TensorFlow】tf.nn.embedding_lookup函数的用法
tf.nn.embedding_lookup函数的用法主要是选取一个张量里面索引对应的元素.tf.nn.embedding_lookup(tensor, id):tensor就是输入张量,id就是张量 ...
- tf.nn.embedding_lookup函数的用法
关于np.random.RandomState.np.random.rand.np.random.random.np.random_sample参考https://blog.csdn.net/lanc ...
- APUE学习笔记——10.9 信号发送函数kill、 raise、alarm、pause
转载注明出处:Windeal学习笔记 kil和raise kill()用来向进程或进程组发送信号 raise()用来向自身进程发送信号. #include <signal.h> int k ...
- 小记tensorflow-1:tf.nn.conv2d 函数介绍
tf.nn.conv2d函数介绍 Input: 输入的input必须为一个4d tensor,而且每个input的格式必须为float32 或者float64. Input=[batchsize,im ...
- 对 tensorflow 中 tf.nn.embedding_lookup 函数的解释
http://stackoverflow.com/questions/34870614/what-does-tf-nn-embedding-lookup-function-do embedding_l ...
- tensorflow笔记:使用tf来实现word2vec
(一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 (四) tensorflow笔 ...
- 【TensorFlow】理解tf.nn.conv2d方法 ( 附代码详解注释 )
最近在研究学习TensorFlow,在做识别手写数字的demo时,遇到了tf.nn.conv2d这个方法,查阅了官网的API 发现讲得比较简略,还是没理解.google了一下,参考了网上一些朋友写得博 ...
- tf.nn.embedding_lookup函数
tf.nn.embedding_lookup(params, ids, partition_strategy='mod', name=None, validate_indices=True, max_ ...
随机推荐
- xhprof扩展安装与使用
目录 一.xhprof扩展安装步骤 二.xhprof的使用 总结 参考资料 一.xhprof扩展安装步骤 xhprof是PHP的一个扩展,最好也直接安装上graphviz图形绘制工具(用于xhprof ...
- HDU4372-Count the Buildings【第一类Stirling数】+【组合数】
<题目链接> <转载于 >>> > 题目大意: N座高楼,高度均不同且为1~N中的数,从前向后看能看到F个,从后向前看能看到B个,问有多少种可能的排列数. 0 ...
- 附003.Docker Compose命令详解
一 Docker Compose命令格式 Usage: docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...] docker- ...
- .net系统的MD5加密方法
/// <summary>/// .net系统的MD5加密方法/// </summary>/// <param name="strIN">< ...
- 潭州课堂25班:Ph201805201 爬虫基础 第十五课 js破解 二 (课堂笔记)
PyExecJs使用 PyExecJS是Ruby的ExecJS移植到Python的一个执行JS代码的库. 安装 pip install PyExecJS 例子 >>> import ...
- Java表达式转型规则
Java表达式转型规则由低到高转换: 1.所有的byte,short,char型的值将被提升为int型: 2.如果有一个操作数是long型,计算结果是long型: 3.如果有一个操作数是float型, ...
- nginx 方向代理 jenkins
环境 10.0.0.20 Nginx 10.0.0.21 jenkins 10.0.0.20 nginx 进入到nginx目录,去除无用字段输入到conf.d/jenkins.conf 文件中 [ro ...
- Python 八大排序算法速度比较
这篇文章并不是介绍排序算法原理的,纯粹是想比较一下各种排序算法在真实场景下的运行速度. 算法由 Python 实现,用到了一些语法糖,可能会和其他语言有些区别,仅当参考就好. 测试的数据是自动生成的, ...
- AngualrJS中每次$http请求时的一个遮罩层Directive
在AngualrJS中使用$http每次向远程API发送请求,等待响应,这中间有些许的等待过程.如何优雅地处理这个等待过程呢? 如果我们在等待过程中弹出一个遮罩层,会是一个比较优雅的做法. 这就涉及到 ...
- 从零开始优雅的使用mongodb实例
基本连接 一.创建express工程testmon express testmon 二.精简app.js var express = require("express"); var ...