首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >torch.nn.SyncBatchNorm

torch.nn.SyncBatchNorm

作者头像
狼啸风云
修改于 2022-09-02 14:26:59
修改于 2022-09-02 14:26:59
2.7K00
代码可运行
举报
运行总次数:0
代码可运行

torch.nn.SyncBatchNorm(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True, process_group=None)[source]

Applies Batch Normalization over a N-Dimensional input (a mini-batch of [N-2]D inputs with additional channel dimension) as described in the paper Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift.

The mean and standard-deviation are calculated per-dimension over all mini-batches of the same process groups.

and

are learnable parameter vectors of size C (where C is the input size). By default, the elements of

are sampled from

and the elements of

are set to 0.

Also by default, during training this layer keeps running estimates of its computed mean and variance, which are then used for normalization during evaluation. The running estimates are kept with a default momentum of 0.1.

If track_running_stats is set to False, this layer then does not keep running estimates, and batch statistics are instead used during evaluation time as well.

Note

This momentum argument is different from one used in optimizer classes and the conventional notion of momentum. Mathematically, the update rule for running statistics here is

, where

is the estimated statistic and

is the new observed value.

Because the Batch Normalization is done over the C dimension, computing statistics on (N, +) slices, it’s common terminology to call this Volumetric Batch Normalization or Spatio-temporal Batch Normalization.

Currently SyncBatchNorm only supports DistributedDataParallel with single GPU per process. Use torch.nn.SyncBatchNorm.convert_sync_batchnorm() to convert BatchNorm layer to SyncBatchNorm before wrapping Network with DDP.

Parameters:

  • num_features – CCC from an expected input of size (N,C,+)
  • eps – a value added to the denominator for numerical stability. Default: 1e-5
  • momentum – the value used for the running_mean and running_var computation. Can be set to None for cumulative moving average (i.e. simple average). Default: 0.1
  • affine – a boolean value that when set to True, this module has learnable affine parameters. Default: True
  • track_running_stats – a boolean value that when set to True, this module tracks the running mean and variance, and when set to False, this module does not track such statistics and always uses batch statistics in both training and eval modes. Default: True
  • process_group – synchronization of stats happen within each process group individually. Default behavior is synchronization across the whole world

Shape:

  • Input: (N,C,+)(N, C, +)(N,C,+)
  • Output: (N,C,+)(N, C, +)(N,C,+) (same shape as input)

Examples:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
>>> # With Learnable Parameters
>>> m = nn.SyncBatchNorm(100)
>>> # creating process group (optional)
>>> # process_ids is a list of int identifying rank ids.
>>> process_group = torch.distributed.new_group(process_ids)
>>> # Without Learnable Parameters
>>> m = nn.BatchNorm3d(100, affine=False, process_group=process_group)
>>> input = torch.randn(20, 100, 35, 45, 10)
>>> output = m(input)

>>> # network is nn.BatchNorm layer
>>> sync_bn_network = nn.SyncBatchNorm.convert_sync_batchnorm(network, process_group)
>>> # only single gpu per process is currently supported
>>> ddp_sync_bn_network = torch.nn.parallel.DistributedDataParallel(
>>>                         sync_bn_network,
>>>                         device_ids=[args.local_rank],
>>>                         output_device=args.local_rank)

classmethod

convert_sync_batchnorm(module, process_group=None)[source]

Helper function to convert torch.nn.BatchNormND layer in the model to torch.nn.SyncBatchNorm layer.

Parameters:

  • module (nn.Module) – containing module
  • process_group (optional) – process group to scope synchronization,

default is the whole world.

Returns:

  • The original module with the converted torch.nn.SyncBatchNorm layer.

Example:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
>>> # Network with nn.BatchNorm layer
>>> module = torch.nn.Sequential(
>>>            torch.nn.Linear(20, 100),
>>>            torch.nn.BatchNorm1d(100)
>>>          ).cuda()
>>> # creating process group (optional)
>>> # process_ids is a list of int identifying rank ids.
>>> process_group = torch.distributed.new_group(process_ids)
>>> sync_bn_module = convert_sync_batchnorm(module, process_group)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
实现无刷新DropDownList联动效果
在做一个文章添加功能时,想在选择大类后,自动将其所属二级小类显示出来,使用DropDownList的SelectedIndexChanged事件可以很容易实现,但每次选择后页面总要刷新一次,让人感觉很不爽。为实现DropDownList无刷新二级联动,这几天在网上找了些资料,但都无法达到我想要的效果,经过反复调试,现已基本实现了此功能,现将代码附下。
Java架构师必看
2021/03/22
2K0
dropdownlist控件绑定_dropdownlist控件联动
也谈谈动态绑定dropdownlist CSDN 2004年7月31日 <script src=”http://www.jaron.cn/cms-server/ArticleViewTim
全栈程序员站长
2022/11/08
1.6K0
GridView控件修改、删除示例(修改含有DropDownList控件)
GridView控件修改、删除例子,修改时含有DropDownList控件。 示例运行效果图:
Java架构师必看
2021/03/22
7210
DropDownList绑定数据库「建议收藏」
//获取文本 this.DropDownList1.SelectedItem.Text;
全栈程序员站长
2022/11/08
7310
Gridview导出到Excel,Gridview中的各类控件,Gridview中删除记录的处理
Asp.net 2.0中新增的gridview控件,是十分强大的数据展示控件,在前面的系列文章里,分别展示了其中很多的基本用法和技巧(详见< ASP.NET 2.0中Gridview控件高级技巧>)。在本文中,将继续探讨有关的技巧。
Java架构师必看
2021/03/22
3.2K0
怎么样给下拉框加载背景色
选择自PPLUNCLE的Blog部分代码:------aspx页面:  说明:下拉框必须写成数据库
Java架构师必看
2020/10/26
4260
也谈谈动态绑定dropdownlist(1)
说来,很多的dropdownlist选项都不是固定的,是会动态改变的,一种方法是在页面上写死,改变时,直接修改页面就可以了。但是很多人是使用动态绑定的,因此dropdownlist的Text和Value是需要动态生成的。
全栈程序员站长
2022/09/07
5400
repeater控件用法_propertygrid控件
大家好,又见面了,我是你们的朋友全栈君。 在我们编写程序的时候经常会遇到控件嵌套的问题。 通常最经常用到的控件时repeater,以下是一两个列子。 HTML <asp:repeater id=
全栈程序员站长
2022/11/04
1.9K0
在GridView内访问特定控件
本文我将为你演示如何访问GridView中的特定控件。我们会看到怎样去访问TextBox控件,DropDownList控件以及ListBox控件。
Java架构师必看
2021/03/22
3.1K0
向DropDownList 下拉框添加新选项[通俗易懂]
大家有没有遇见过这样的情况,假如有一个下拉框,现在让你在下拉框里面添加一个新的选项如“请选择”,而数据库里面又不存在这一选项》要怎么做,下面为大家推荐两种写法:
全栈程序员站长
2022/10/03
2.6K0
向DropDownList 下拉框添加新选项[通俗易懂]
DropDownList绑定及修改
转载于:https://www.cnblogs.com/hulang/archive/2010/12/29/1920662.html
全栈程序员站长
2022/11/03
6730
GridView自定义分页导航
<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " StfCmpManager.aspx.cs "  Inherits = " StfCmpManager " %>
Java架构师必看
2021/03/22
8600
GridView自定义分页导航
SQLServer中使用SUBSTRING截取字符串[通俗易懂]
SUBSTRING 返回字符、binary、text 或 image 表达式的一部分。有关可与该函数一起使用的有效 Microsoft&reg; SQL Server&#8482; 数据类型的更多信息,请参见数据类型。
全栈程序员站长
2022/08/31
13.3K0
drop in session_drop constraint
//aspx <asp:Repeater ID=”Repeater1″ runat=”server” OnItemDataBound=”Repeater1_ItemDataBound”> <ItemTemplate> <asp:Label ID=”Label1″ runat=”server” Text='<%# DataBinder.Eval(Container.DataItem, “au_id” ) %>’></asp:Label> <asp:DropDownList ID=”DropDownList1″ runat=”server”> </asp:DropDownList> <br /> </ItemTemplate> </asp:Repeater>
全栈程序员站长
2022/09/27
6160
asp.net dropdownlist绑定省份_droplist
<asp:DropDownList runat=”server” ID=”ddl_GetThailandProvinceList” class=”form-select” aria-label=”Default select example” ></asp:DropDownList>
全栈程序员站长
2022/11/08
4980
Enterprise Library 企业库「建议收藏」
1. Enterprise Library 企业库介绍 是微软模式与 实践团队 开的应用程序块 安装Enterprise Library 下载 w
全栈程序员站长
2022/11/01
6840
数据库向DropDownList1绑定数据
string ConnString = @”Data Source=PC-20140331BMRR\SQLEXPRESS;Initial Catalog=lianxi;Integrated Security=True”; //创建一个SqlConnection SqlConnection Conn = new SqlConnection(ConnString);
全栈程序员站长
2022/09/09
3400
如何给DataGrid添加自动增长列
如何给DataGrid添加自动增长列 我想我们都知道在数据库中如何添加自增长列,我们可以将这个自增长列绑定到DataGrid上使得用户方便的知道现在是第几行,今天我介绍一种不用数据库就可以简单显示出自增长列的方法,有人可能会说既然数据库支持我们为什么这样做?我想有如下的两个理由:1、不是所有的表都有自增长列。2、当自增长列不自动复制的时候会出现断号的现象,即使复制这也是有可能发生的。但是先要说明的是这个方法只能显示出来当前页的序号,也就是说如果有分页它只能标记当前这一页的序号。如果要同样实现分页的功能我想使
阿新
2018/04/13
1.9K0
给DataGrid添加确定删除的功能
给DataGrid添加确定删除的功能 DataGrid的功能我想大家是知道的,我在实际的应用中遇到如下的问题,客户要求在删除之前做一次提示。类
Java架构师必看
2021/03/22
1K0
BS1032-基于C#+SqlServer+CS架构实现学生选课信息管理系统,学生选课录入系统
采用C#+SqlServer+CS架构实现的学生选课管理系统,学生选课录入系统,系统采用多层C/S软件架构,采用C#编程语言开发技术实现界面窗口版本的学生管理系统程序界面,实现CS架构窗口事件监听,完成学生选课创建,编辑,删除等。
计算机程序优异哥
2022/12/02
1.1K0
推荐阅读
相关推荐
实现无刷新DropDownList联动效果
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档