nll_loss
'''
torch.nn torch.nn.functional (F)
CrossEntropyLoss cross_entropy
LogSoftmax log_softmax
NLLLoss nll_loss '''
import torch
import torch.nn.functional as F input=torch.randn(3,4)
label=torch.tensor([0,2,1])
print("input",input) softmax=F.softmax(input,dim=1)
print("softmax",softmax) log_softmax=F.log_softmax(input,dim=1)
print("log_softmax",log_softmax) loss_nll=F.nll_loss(log_softmax,label)
print("loss_nll",loss_nll) loss_cross=F.cross_entropy(input,label)
print("loss_cross",loss_cross) '''
input tensor([[ 0.0363, 0.1419, 2.1639, 1.5429],
[-0.6606, -0.0991, -0.6160, -2.4418],
[-1.1279, -1.5333, -0.2142, 0.8669]])
softmax tensor([[0.0666, 0.0740, 0.5590, 0.3004],
[0.2521, 0.4419, 0.2636, 0.0425],
[0.0869, 0.0579, 0.2166, 0.6386]])
log_softmax tensor([[-2.7092, -2.6036, -0.5816, -1.2026],
[-1.3781, -0.8166, -1.3335, -3.1592],
[-2.4433, -2.8488, -1.5296, -0.4485]])
loss_nll tensor(1.4971)
loss_cross tensor(1.4971) 0.0363 0.1419 2.1639 1.5429
-0.6606 -0.0991 -0.616 -2.4418
-1.1279 -1.5333 -0.2142 0.8669 dim=0
exp sum
1.0370 1.1525 8.7050 4.6781 15.57258663
0.5165 0.9057 0.5401 0.0870 2.049298083
0.3237 0.2158 0.8072 2.3795 3.726244435 softmax
0.0666 0.0740 0.5590 0.3004
0.2521 0.4419 0.2636 0.0425
0.0869 0.0579 0.2166 0.6386 log_softmax
-2.7092 -2.6036 -0.5816 -1.2026
-1.3781 -0.8166 -1.3335 -3.1593
-2.4433 -2.8487 -1.5296 -0.4485 1.0370=exp(0.0363)
0.0666=1.0370/15.57258663
-2.7092=ln(0.0666)
1.497070103=abs(-2.7092-1.3335-0.44850/3 '''
nll_loss的更多相关文章
- resnet18全连接层改成卷积层
想要尝试一下将resnet18最后一层的全连接层改成卷积层看会不会对网络效果和网络大小有什么影响 1.首先先对train.py中的更改是: train.py代码可见:pytorch实现性别检测 # m ...
- TensorRT&Sample&Python[network_api_pytorch_mnist]
本文是基于TensorRT 5.0.2基础上,关于其内部的network_api_pytorch_mnist例子的分析和介绍. 本例子直接基于pytorch进行训练,然后直接导出权重值为字典,此时并未 ...
- Pytorch里的CrossEntropyLoss详解
在使用Pytorch时经常碰见这些函数cross_entropy,CrossEntropyLoss, log_softmax, softmax.看得我头大,所以整理本文以备日后查阅. 首先要知道上面提 ...
- Summary on deep learning framework --- PyTorch
Summary on deep learning framework --- PyTorch Updated on 2018-07-22 21:25:42 import osos.environ[ ...
- pytorch0.4版的CNN对minist分类
卷积神经网络(Convolutional Neural Network, CNN)是深度学习技术中极具代表的网络结构之一,在图像处理领域取得了很大的成功,在国际标准的ImageNet数据集上,许多成功 ...
- 记录下pytorch代码从0.3版本迁移到0.4版本要做的一些更改。
1. UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to in ...
- 使用xshell+xmanager+pycharm搭建pytorch远程调试开发环境
1. 相关软件版本 xshell: xmanager: pycharm: pycharm破解服务器:https://jetlicense.nss.im/ 2. 将相应的软件安装(pojie好) a&g ...
- tensorflow/pytorch/mxnet的pip安装,非源代码编译,基于cuda10/cudnn7.4.1/ubuntu18.04.md
os安装 目前对tensorflow和cuda支持最好的是ubuntu的18.04 ,16.04这种lts,推荐使用18.04版本.非lts的版本一般不推荐. Windows倒是也能用来装深度GPU环 ...
- 深度学习课程笔记(一)CNN 卷积神经网络
深度学习课程笔记(一)CNN 解析篇 相关资料来自:http://speech.ee.ntu.edu.tw/~tlkagk/courses_ML17_2.html 首先提到 Why CNN for I ...
随机推荐
- EMQTT测试--安装与测试 (windows)
我下载的是windows版 安装 参考http://emqtt.com/docs/install.html 将下载的压缩包解压,我解压到了D盘 命令行窗口,cd到程序目录 控制台模式启动: .\bin ...
- spingboot之Java邮件发送
注意: 该项目的工具类可以直接应用于项目 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> < ...
- Appium+python自动化-输入中文
一.定位搜索 1.打开淘宝点击搜索按钮,进入到搜索页面 2.然后定位到搜索框后用sendkeys方法输入‘hao’,这里定位元素使用uiautomatorviewer工具即可 3.脚本如下,输入的是英 ...
- LeetCode.914-一副牌中的X(X of a Kind in a Deck of Cards)
这是悦乐书的第352次更新,第377篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第214题(顺位题号是914).在一副牌中,每张牌上都写有一个整数. 当且仅当您可以选择 ...
- Angular5 tslint错误:The selector of the component “XXXComponent” should be used as element
错误描述 在项目中自己封装了一个 select 组件 @Component({ selector: '[app-choosen-select]', templateUrl: './selectcomm ...
- python 并发编程 多线程 定时器
定时器 就是隔多长时间去触发任务执行 指定n秒后执行某操作 Timer如何使用,看Timer源码 class Timer(Thread): """Call a funct ...
- [Python3] 030 常用模块 os
目录 os 1. os.getcwd() 2. os.chdir() 3. os.listdir() 4. os.makedir() 5. os.system() 6. os.getenv() 7. ...
- spring boot-14.集成MyBatis
1.如何使用注解版Mybatis? (1)引入mybatis ,druid,Mysql 的依赖,环境搭建可以参考第13篇的内容 <dependency> <groupId>or ...
- MySQL -2- 体系结构
1. 体系结构 1.1 C/S(客户端/服务端)模型介绍 image TCP/IP方式(远程.本地): mysql -uroot -poldboy123 -h 10.0.0.51 -P3306 S ...
- dp常见优化方法
noip范围内的dp优化方法: 加速状态转移 1.前缀和优化 2.单调队列优化 3.线段树或树状数组优化 精简状态 3:精简状态往往是通过对题目本身性质的分析,去省掉一些冗余的状态.相对以上三条套路性 ...