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

赤峰网站建设red帮助网站源码

赤峰网站建设red,帮助网站源码,在线直播免费服务器,做网站应该学什么深度学习网络模型——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 模型配置论文名称#xff1a; RepVGG: Making V… 深度学习网络模型——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 VGG-style ConvNets Great Again论文下载地址 https://arxiv.org/abs/2101.03697官方源码Pytorch实现 https://github.com/DingXiaoH/RepVGG0 前言 1 RepVGG Block详解 2 结构重参数化 2.1 融合Conv2d和BN 2.2 Conv2dBN融合实验(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(convnn.Conv2d(in_channels2, out_channels2, kernel_size3, stride1, padding1, biasFalse),bnnn.BatchNorm2d(num_features2)))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_channels2, out_channels2, kernel_size3, stride1, padding1, biasTrue)fused_conv.load_state_dict(OrderedDict(weightkernel, biasbias))with torch.no_grad():output2 fused_conv(f1)print(output2)np.testing.assert_allclose(output1.numpy(), output2.numpy(), rtol1e-03, atol1e-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, groups1):result nn.Sequential()result.add_module(conv, nn.Conv2d(in_channelsin_channels, out_channelsout_channels,kernel_sizekernel_size, stridestride, paddingpadding,groupsgroups, biasFalse))result.add_module(bn, nn.BatchNorm2d(num_featuresout_channels))return resultclass RepVGGBlock(nn.Module):def __init__(self, in_channels, out_channels, kernel_size3,stride1, padding1, dilation1, groups1, padding_modezeros, deployFalse):super(RepVGGBlock, self).__init__()self.deploy deployself.groups groupsself.in_channels in_channelsself.nonlinearity nn.ReLU()if deploy:self.rbr_reparam nn.Conv2d(in_channelsin_channels, out_channelsout_channels,kernel_sizekernel_size, stridestride,paddingpadding, dilationdilation, groupsgroups,biasTrue, padding_modepadding_mode)else:self.rbr_identity nn.BatchNorm2d(num_featuresin_channels) \if out_channels in_channels and stride 1 else Noneself.rbr_dense conv_bn(in_channelsin_channels, out_channelsout_channels, kernel_sizekernel_size,stridestride, paddingpadding, groupsgroups)self.rbr_1x1 conv_bn(in_channelsin_channels, out_channelsout_channels, kernel_size1,stridestride, padding0, groupsgroups)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), dtypenp.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_channelsself.rbr_dense.conv.in_channels,out_channelsself.rbr_dense.conv.out_channels,kernel_sizeself.rbr_dense.conv.kernel_size, strideself.rbr_dense.conv.stride,paddingself.rbr_dense.conv.padding, dilationself.rbr_dense.conv.dilation,groupsself.rbr_dense.conv.groups, biasTrue)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_channels64, out_channels64)block.eval()with torch.no_grad():output1 block(f1)start_time time.time()for _ in range(100):block(f1)print(fconsume time: {time.time() - start_time})# re-parameterizationblock.switch_to_deploy()output2 block(f1)start_time time.time()for _ in range(100):block(f1)print(fconsume time: {time.time() - start_time})np.testing.assert_allclose(output1.numpy(), output2.numpy(), rtol1e-03, atol1e-05)print(convert module has been tested, and the result looks good!)if __name__ __main__:main() 终端输出结果如下 通过对比能够发现结构重参数化后推理速度翻倍了并且转换前后的输出保持一致。 3 模型配置
http://www.hkea.cn/news/14322984/

相关文章:

  • 娱乐网站开发spspwkwin7优化教程
  • 品牌授权网站深圳网站建设报价
  • 炫酷的企业网站建设银行如何设置网站查询密码
  • 沈阳网站制作定制策划怎么做自己的网站赚钱
  • 安徽合肥建设局网站企业信息管理平台系统
  • 黄骗免费网站中国服务外包研究中心
  • 织梦做仿站时 为何会发生本地地址跳转网站地址陕西省建设信息管理网站
  • 网站建设原则应考虑哪些海外平台推广方法
  • 智能建站是什么昆明排名seo公司
  • 南川区 网站集约化建设方案深圳网站建设及推广服务公司
  • 网页与网站设计工作内容长沙服务好的网络营销
  • 温州做网站哪家比较好郴州网签备案查询系统
  • 汕头网站推广找哪里展台展馆设计搭建
  • 建设网站合同范本wordpress搜索代码制做
  • 备案网站名称攻略怎么查看企业的营业执照
  • 网站建设用宝塔去掉自动升级wordpress失败提示
  • 沂源网站建设yx718软件开发需要多少钱?
  • 用php内容做电商网站一个人做运营网站
  • 用html做女装网站目前徐州有多少网架公司
  • 服装网站开发方案网站建设方案情况汇报
  • 万能站工具的企业网站系统瑞丽市建设局网站
  • 苏州企业网站优化多点网络网站制作系统
  • 网站统计查询贵阳专用网站建设
  • pc端的网站设计方案湘潭网站建设 安全还踏实磐石网络
  • 用dw做淘宝网站wordpress服务器如何使用
  • 建设监理网站织梦官网模板
  • 东莞大型网站建设网站怎样建设友情链接
  • wordpress 七牛云上传图片南阳网站排名优化价格
  • dedecms织梦古典艺术书画书法公司企业网站源码模板网站制作百度网盘
  • 网站怎么做平台百度指数需求图谱