batchnorm2d参数 torch_Pytorch-nn.BatchNorm2d()
Pytorch官方文档:
测试代码:
转自:https://blog.csdn.net/tmk_01/article/details/80679549
import torch
import torch.nn as nn
m = nn.BatchNorm2d(2,affine=True) #weight(gamma)和bias(beta)将被使用
input = torch.randn(1,2,3,4)
output = m(input)
print("输入图片:")
print(input)
print("归一化权重(公式中的gamma):")
print(m.weight)
print("归一化偏置(公式中的beta):")
print(m.bias)
print("归一化的输出:")
print(output)
print("输出的尺度:")
print(output.size())
# i = torch.randn(1,1,2)
print("输入的第一个维度:")
print(input[0][0])
firstDimenMean = torch.Tensor.mean(input[0][0])
firstDimenVar= torch.Tensor.var(input[0][0],False) #Bessel's Correction贝塞尔校正不会被使用
print(m.eps)
print("输入的第一个维度平均值:")
print(firstDimenMean)
print("输入的第一个维度方差:")
print(firstDimenVar)
bacthnormone = \
((input[0][0][0][0] - firstDimenMean)/(torch.pow(firstDimenVar+m.eps,0.5) ))\
* m.weight[0] + m.bias[0]
print(bacthnormone)
代码运行结果:
输入图片:
tensor([[[[-1.1622, -0.9170, -0.6798, -0.0270],
[ 0.2687, -1.6046, -0.2142, -0.3561],
[ 0.2908, -0.1012, 1.3594, 1.1316]],
[[ 0.4689, 1.4049, 1.2324, -1.3721],
[-0.1498, -0.3207, 0.5072, -1.2563],
[ 1.5934, -0.8010, 0.1270, 0.5993]]]])
归一化权重(公式中的gamma):
Parameter containing:
tensor([0.8681, 0.7207], requires_grad=True)
归一化偏置(公式中的beta):
Parameter containing:
tensor([0., 0.], requires_grad=True)
归一化的输出:
tensor([[[[-1.0344, -0.7794, -0.5326, 0.1463],
[ 0.4538, -1.4945, -0.0484, -0.1960],
[ 0.4767, 0.0691, 1.5881, 1.3512]],
[[ 0.2279, 0.9400, 0.8088, -1.1729],
[-0.2429, -0.3729, 0.2570, -1.0848],
[ 1.0834, -0.7384, -0.0323, 0.3271]]]],
grad_fn=)
输出的尺度:
torch.Size([1, 2, 3, 4])
输入的第一个维度:
tensor([[-1.1622, -0.9170, -0.6798, -0.0270],
[ 0.2687, -1.6046, -0.2142, -0.3561],
[ 0.2908, -0.1012, 1.3594, 1.1316]])
1e-05
输入的第一个维度平均值:
tensor(-0.1676)
输入的第一个维度方差:
tensor(0.6967)
tensor(-1.0344, grad_fn=)
BatchNorm深度理解可参考:
https://zhuanlan.zhihu.com/p/30922689
4.Normalizing activations in a network
5.Fitting Batch Norm into a neural network
6.Why does Batch Norm work?
7. Batch Norm at test time
batchnorm2d参数 torch_Pytorch-nn.BatchNorm2d()相关推荐
- batchnorm2d参数 torch_pytorch中BatchNorm1d、BatchNorm2d、BatchNorm3d
1.nn.BatchNorm1d(num_features) 1.对小批量(mini-batch)的2d或3d输入进行批标准化(Batch Normalization)操作 2.num_feature ...
- batchnorm2d参数 torch_pytorch方法测试详解——归一化(BatchNorm2d)
测试代码: import torch import torch.nn as nn m = nn.BatchNorm2d(2,affine=True) #权重w和偏重将被使用 input = torch ...
- PyTorch基础(12)-- torch.nn.BatchNorm2d()方法
Batch Normanlization简称BN,也就是数据归一化,对深度学习模型性能的提升有很大的帮助.BN的原理可以查阅我之前的一篇博客.白话详细解读(七)----- Batch Normaliz ...
- Batch Normalization原理及pytorch的nn.BatchNorm2d函数
下面通过举个例子来说明Batch Normalization的原理,我们假设在网络中间经过某些卷积操作之后的输出的feature map的尺寸为4×3×2×2,4为batch的大小,3为channel ...
- PyTorch学习笔记(1)nn.Sequential、nn.Conv2d、nn.BatchNorm2d、nn.ReLU和nn.MaxPool2d
文章目录 一.nn.Sequential 二.nn.Conv2d 三.nn.BatchNorm2d 四.nn.ReLU 五.nn.MaxPool2d 一.nn.Sequential torch.nn. ...
- nn.BatchNorm2d
今天查资料看到说batchnorm2d的作用如下 nn.BatchNorm2d(out_channel), #BatchNorm2d最常用于卷积网络中(防止梯度消失或爆炸),设置的参数 ...
- python batchnorm2d_Python nn.BatchNorm2d方法代碼示例
本文整理匯總了Python中torch.nn.BatchNorm2d方法的典型用法代碼示例.如果您正苦於以下問題:Python nn.BatchNorm2d方法的具體用法?Python nn.Batc ...
- nn.BatchNorm2d() 手推计算步骤
首先贴上官方文档 γ和β初始化时默认为1和0.输入必须是4维的张量x,而对四维张量进行归一化的步骤是: 对不同样本的同一个通道的所有像素进行求均值. 最后得到的均值是一个(1,a,1,1) 的张量, ...
- python中的*和**参数:nn.Sequential(*layers)
单星号参数 函数中的单星号参数代表此处接受任意多个非关键字参数,这些参数将以数组形式保存,例如: def foo(a, *b):print bfoo(1, 2, 3, 4, 5) 执行结果为: (2, ...
最新文章
- 原创 | 一文读懂正态分布与贝塔分布
- 【深度学习】基于Pytorch的softmax回归问题辨析和应用(二)
- js轮播图片小圆点变化_原生js实现轮播图(两种方法)
- 想做跨境的卖家新起点在哪里?亚马逊“封店潮”来袭,商家该何去何从
- poj 2492 A Bug's Life
- 简单的ftp服务器(客户端、服务器端、socket)
- easyui 动态设置单元格控件_动态显示最大最小值的折线图
- 转一个无聊的爱情故事:如果有个女生为你哭
- 三菱d700变频器模拟量控制_三菱Q系列PLC,用CCLink控制变频器正反转和多段速
- java开发环境怎样选择_怎样搭建Java开发环境?
- python虚拟人脸生成_Python-OpenCV人脸识别之数据集生成
- 重磅 | 阿里云启动AliSQL邀测,性能比MySQL提升70%,秒杀场景提升百倍
- qstringlist格式怎么写到txt_怎样把PDF转成TXT呢?
- 常用设计模式Python实现
- 学习大数据参加培训班,大概需要多长时间?
- android 腾讯x5内核 浏览器
- android 仿微信聊天界面 以及语音录制功能,Android仿微信录制语音功能
- 江南春:在不确定的市场,找到确定性的增长
- esx linux 硬盘 扩容,ESX虚拟机添加新磁盘并扩容逻辑卷
- vue+vuex+axios从后台获取数据存入vuex,组件之间共享数据
热门文章
- 创建JPA工程时提示:at least one user library must be selected
- ctrl键一直自动按住了_用好Ctrl键,效率快一半
- curl head请求_CURL速查
- iphone尺寸_iPhone折叠机概念图:屏幕双打孔,iPhone折叠机有多优秀!
- php去除中间空格,php删除字符串中间空格的方法
- android build获取ext,android – 如何在Gradle中获取当前构建类型
- python中f点flush是什么函数_Python文件操作及内置函数flush原理解析
- 查看linux mysql 账户权限设置_Linux下mysql新建账号及权限设置各种方式总结
- 国货之光业务增长背后的技术支持 - 完美日记的云原生实践
- windows10 + Anaconda搭建tensorflow-gpu环境