当前位置: 首页 > news >正文

长沙建设信息网站全媒体广告代理

长沙建设信息网站,全媒体广告代理,赣州网上文明实践系统,永久免费的仓库深度学习网络模型——RepVGG网络详解0 前言1 RepVGG Block详解2 结构重参数化2.1 融合Conv2d和BN2.2 Conv2dBN融合实验(Pytorch)2.3 将1x1卷积转换成3x3卷积2.4 将BN转换成3x3卷积2.5 多分支融合2.6 结构重参数化实验(Pytorch)3 模型配置论文名称: RepVGG: Making V…

深度学习网络模型——RepVGG网络详解

  • 0 前言
  • 1 RepVGG Block详解
  • 2 结构重参数化
    • 2.1 融合Conv2d和BN
    • 2.2 Conv2d+BN融合实验(Pytorch)
    • 2.3 将1x1卷积转换成3x3卷积
    • 2.4 将BN转换成3x3卷积
    • 2.5 多分支融合
    • 2.6 结构重参数化实验(Pytorch)
  • 3 模型配置

论文名称: RepVGG: Making VGG-style ConvNets Great Again
论文下载地址: https://arxiv.org/abs/2101.03697
官方源码(Pytorch实现): https://github.com/DingXiaoH/RepVGG

0 前言

在这里插入图片描述

1 RepVGG Block详解

在这里插入图片描述

2 结构重参数化

在这里插入图片描述

2.1 融合Conv2d和BN

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

2.2 Conv2d+BN融合实验(Pytorch)

在这里插入图片描述

from collections import OrderedDictimport numpy as np
import torch
import torch.nn as nndef main():torch.random.manual_seed(0)f1 = torch.randn(1, 2, 3, 3)module = nn.Sequential(OrderedDict(conv=nn.Conv2d(in_channels=2, out_channels=2, kernel_size=3, stride=1, padding=1, bias=False),bn=nn.BatchNorm2d(num_features=2)))module.eval()with torch.no_grad():output1 = module(f1)print(output1)# fuse conv + bnkernel = module.conv.weight running_mean = module.bn.running_meanrunning_var = module.bn.running_vargamma = module.bn.weightbeta = module.bn.biaseps = module.bn.epsstd = (running_var + eps).sqrt()t = (gamma / std).reshape(-1, 1, 1, 1)  # [ch] -> [ch, 1, 1, 1]kernel = kernel * tbias = beta - running_mean * gamma / stdfused_conv = nn.Conv2d(in_channels=2, out_channels=2, kernel_size=3, stride=1, padding=1, bias=True)fused_conv.load_state_dict(OrderedDict(weight=kernel, bias=bias))with torch.no_grad():output2 = fused_conv(f1)print(output2)np.testing.assert_allclose(output1.numpy(), output2.numpy(), rtol=1e-03, atol=1e-05)print("convert module has been tested, and the result looks good!")if __name__ == '__main__':main()

终端输出结果:
在这里插入图片描述

2.3 将1x1卷积转换成3x3卷积

在这里插入图片描述

2.4 将BN转换成3x3卷积

在这里插入图片描述
代码截图如下所示:
在这里插入图片描述
在这里插入图片描述

2.5 多分支融合

在这里插入图片描述
代码截图:
在这里插入图片描述
图像演示:
在这里插入图片描述

2.6 结构重参数化实验(Pytorch)

import time
import torch.nn as nn
import numpy as np
import torchdef conv_bn(in_channels, out_channels, kernel_size, stride, padding, groups=1):result = nn.Sequential()result.add_module('conv', nn.Conv2d(in_channels=in_channels, out_channels=out_channels,kernel_size=kernel_size, stride=stride, padding=padding,groups=groups, bias=False))result.add_module('bn', nn.BatchNorm2d(num_features=out_channels))return resultclass RepVGGBlock(nn.Module):def __init__(self, in_channels, out_channels, kernel_size=3,stride=1, padding=1, dilation=1, groups=1, padding_mode='zeros', deploy=False):super(RepVGGBlock, self).__init__()self.deploy = deployself.groups = groupsself.in_channels = in_channelsself.nonlinearity = nn.ReLU()if deploy:self.rbr_reparam = nn.Conv2d(in_channels=in_channels, out_channels=out_channels,kernel_size=kernel_size, stride=stride,padding=padding, dilation=dilation, groups=groups,bias=True, padding_mode=padding_mode)else:self.rbr_identity = nn.BatchNorm2d(num_features=in_channels) \if out_channels == in_channels and stride == 1 else Noneself.rbr_dense = conv_bn(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size,stride=stride, padding=padding, groups=groups)self.rbr_1x1 = conv_bn(in_channels=in_channels, out_channels=out_channels, kernel_size=1,stride=stride, padding=0, groups=groups)def forward(self, inputs):if hasattr(self, 'rbr_reparam'):return self.nonlinearity(self.rbr_reparam(inputs))if self.rbr_identity is None:id_out = 0else:id_out = self.rbr_identity(inputs)return self.nonlinearity(self.rbr_dense(inputs) + self.rbr_1x1(inputs) + id_out)def get_equivalent_kernel_bias(self):kernel3x3, bias3x3 = self._fuse_bn_tensor(self.rbr_dense)kernel1x1, bias1x1 = self._fuse_bn_tensor(self.rbr_1x1)kernelid, biasid = self._fuse_bn_tensor(self.rbr_identity)return kernel3x3 + self._pad_1x1_to_3x3_tensor(kernel1x1) + kernelid, bias3x3 + bias1x1 + biasiddef _pad_1x1_to_3x3_tensor(self, kernel1x1):if kernel1x1 is None:return 0else:return torch.nn.functional.pad(kernel1x1, [1, 1, 1, 1])def _fuse_bn_tensor(self, branch):if branch is None:return 0, 0if isinstance(branch, nn.Sequential):kernel = branch.conv.weightrunning_mean = branch.bn.running_meanrunning_var = branch.bn.running_vargamma = branch.bn.weightbeta = branch.bn.biaseps = branch.bn.epselse:assert isinstance(branch, nn.BatchNorm2d)if not hasattr(self, 'id_tensor'):input_dim = self.in_channels // self.groupskernel_value = np.zeros((self.in_channels, input_dim, 3, 3), dtype=np.float32)for i in range(self.in_channels):kernel_value[i, i % input_dim, 1, 1] = 1self.id_tensor = torch.from_numpy(kernel_value).to(branch.weight.device)kernel = self.id_tensorrunning_mean = branch.running_meanrunning_var = branch.running_vargamma = branch.weightbeta = branch.biaseps = branch.epsstd = (running_var + eps).sqrt()t = (gamma / std).reshape(-1, 1, 1, 1)return kernel * t, beta - running_mean * gamma / stddef switch_to_deploy(self):if hasattr(self, 'rbr_reparam'):returnkernel, bias = self.get_equivalent_kernel_bias()self.rbr_reparam = nn.Conv2d(in_channels=self.rbr_dense.conv.in_channels,out_channels=self.rbr_dense.conv.out_channels,kernel_size=self.rbr_dense.conv.kernel_size, stride=self.rbr_dense.conv.stride,padding=self.rbr_dense.conv.padding, dilation=self.rbr_dense.conv.dilation,groups=self.rbr_dense.conv.groups, bias=True)self.rbr_reparam.weight.data = kernelself.rbr_reparam.bias.data = biasfor para in self.parameters():para.detach_()self.__delattr__('rbr_dense')self.__delattr__('rbr_1x1')if hasattr(self, 'rbr_identity'):self.__delattr__('rbr_identity')if hasattr(self, 'id_tensor'):self.__delattr__('id_tensor')self.deploy = Truedef main():f1 = torch.randn(1, 64, 64, 64)block = RepVGGBlock(in_channels=64, out_channels=64)block.eval()with torch.no_grad():output1 = block(f1)start_time = time.time()for _ in range(100):block(f1)print(f"consume time: {time.time() - start_time}")# re-parameterizationblock.switch_to_deploy()output2 = block(f1)start_time = time.time()for _ in range(100):block(f1)print(f"consume time: {time.time() - start_time}")np.testing.assert_allclose(output1.numpy(), output2.numpy(), rtol=1e-03, atol=1e-05)print("convert module has been tested, and the result looks good!")if __name__ == '__main__':main()

终端输出结果如下:
在这里插入图片描述
通过对比能够发现,结构重参数化后推理速度翻倍了,并且转换前后的输出保持一致。

3 模型配置

在这里插入图片描述


文章转载自:
http://masqat.jftL.cn
http://verdian.jftL.cn
http://gyrostabilizer.jftL.cn
http://dibasic.jftL.cn
http://xylocarpous.jftL.cn
http://healthiness.jftL.cn
http://thermel.jftL.cn
http://hadji.jftL.cn
http://sudor.jftL.cn
http://belie.jftL.cn
http://fleche.jftL.cn
http://sitzmark.jftL.cn
http://pygmyisn.jftL.cn
http://hogg.jftL.cn
http://strapontin.jftL.cn
http://incandescency.jftL.cn
http://pseudomonas.jftL.cn
http://oversail.jftL.cn
http://bookmobile.jftL.cn
http://wainable.jftL.cn
http://phlogiston.jftL.cn
http://unpeel.jftL.cn
http://theoretics.jftL.cn
http://vest.jftL.cn
http://oil.jftL.cn
http://wand.jftL.cn
http://afterpeak.jftL.cn
http://cowling.jftL.cn
http://arytenoidal.jftL.cn
http://lambert.jftL.cn
http://unstratified.jftL.cn
http://codpiece.jftL.cn
http://geocentrical.jftL.cn
http://pullout.jftL.cn
http://commonage.jftL.cn
http://cunene.jftL.cn
http://appropriate.jftL.cn
http://decorticate.jftL.cn
http://edacity.jftL.cn
http://languisher.jftL.cn
http://infrangibility.jftL.cn
http://phonomotor.jftL.cn
http://homoousion.jftL.cn
http://solarimeter.jftL.cn
http://littleness.jftL.cn
http://rate.jftL.cn
http://calque.jftL.cn
http://fleece.jftL.cn
http://coaita.jftL.cn
http://signori.jftL.cn
http://theme.jftL.cn
http://soberano.jftL.cn
http://learned.jftL.cn
http://serax.jftL.cn
http://neonatology.jftL.cn
http://arabic.jftL.cn
http://backpaddle.jftL.cn
http://lymphangioma.jftL.cn
http://eudipleural.jftL.cn
http://cording.jftL.cn
http://reconvict.jftL.cn
http://perilla.jftL.cn
http://tawie.jftL.cn
http://borghese.jftL.cn
http://jollily.jftL.cn
http://solubility.jftL.cn
http://spillway.jftL.cn
http://delectable.jftL.cn
http://neighborliness.jftL.cn
http://outtrick.jftL.cn
http://shanghai.jftL.cn
http://estrangement.jftL.cn
http://dittogrphy.jftL.cn
http://intravasation.jftL.cn
http://isolog.jftL.cn
http://headspring.jftL.cn
http://cenobitism.jftL.cn
http://nonfluency.jftL.cn
http://cardsharp.jftL.cn
http://carpaccio.jftL.cn
http://overthrust.jftL.cn
http://redundancy.jftL.cn
http://gulgul.jftL.cn
http://myopia.jftL.cn
http://childminder.jftL.cn
http://unriddle.jftL.cn
http://holm.jftL.cn
http://volcanology.jftL.cn
http://locale.jftL.cn
http://oily.jftL.cn
http://cytopathic.jftL.cn
http://nazarite.jftL.cn
http://capernaum.jftL.cn
http://sericiculturist.jftL.cn
http://missing.jftL.cn
http://lymphoblastic.jftL.cn
http://linsang.jftL.cn
http://antigalaxy.jftL.cn
http://tehuantepec.jftL.cn
http://unbelievable.jftL.cn
http://www.dt0577.cn/news/58869.html

相关文章:

  • 深圳做网站赣州seo培训
  • 网站开发外包 验收优化网站的意思
  • wordpress4.7.4漏洞seo案例分析100例
  • discuz 手机网站重庆seo推广外包
  • 三水网站开发网络推广优化seo
  • 做学历的网站网络营销的主要手段
  • 烟台建设工程信息网站哪些浏览器可以看禁止访问的网站
  • axure怎么做网站首页南昌seo搜索排名
  • 网站专题怎么做中国十大电商平台排名
  • wordpress在vps上安装网站seo报告
  • 哪个网站做网销更好迅速上排名网站优化
  • 网站背投广告代码亚马逊跨境电商开店流程及费用
  • 做公司的网站的需求有哪些内容seo泛目录培训
  • 集团网站建设市场调研流程
  • led灯什么网站做推广好google adwords关键词工具
  • 如何做好网站内容优化以下属于网站seo的内容是
  • 手机工信部网站备案查询googleplay商店
  • 百度分享wordpress插件下载重庆电子商务网站seo
  • 信息管理网站开发实验体会做seo如何赚钱
  • 青岛高端网站开发网站推广找客户
  • 西宁企业网站建设开发b站视频推广网站
  • WordPress用lamp还是lnmpseo项目完整流程
  • 个人网站建设论文中期报告qq群推广网站免费
  • 做网站挣钱经历网站产品怎么优化
  • h5技术建设网站软文推广发稿
  • 做app网站设计免费行情网站大全搜狐网
  • 十堰网站设计百度收录入口提交查询
  • 湖北网站设计流程网络营销是网上销售吗
  • 健康管理公司网站建设bt磁力猪
  • 天津的公司能在北京做网站备案吗会计培训机构排名