当前位置:网站首页>Fusion de la conversion et de la normalisation des lots
Fusion de la conversion et de la normalisation des lots
2022-07-02 23:25:00 【Point Py】
Calcul théorique
En coursCNNConfiguration standard des éléments de base de la couche de convolution:Conv + BN +ReLU Trois sous - modules.Mais en fait, dans la phase de raisonnement du réseau,Vous pouvezBNLes opérations de la couche sont fusionnées enConvEn couches,Réduire la quantité de calcul,Accélérer le raisonnement.Essentiellement, les paramètres du noyau de convolution ont été modifiés,Sans augmentationConvEn même temps que le calcul de la couche,J'ai oublié.BNCalcul de la couche.La formule est dérivée comme suit:.
convParamètres de la couche
BNParamètres de la couche
Supposons que l'entrée soitx,Etx->Conv->BNLa sortie de:
Faire une simple déformation de formule:
Mise en œuvre du Code
Dans la pratique, Il faut d'abord localiser. convEtbnEmplacement, Remplacer ou supprimer selon le cas BNCouche. Dans ce mode de réalisation , Diviser la Bibliothèque de modèles en Open Source https://github.com/qubvel/segmentation_models.pytorch Expériences de fusion pour des cas ,C'est exact.BN Les couches ont été remplacées .
class Conv2dReLU(nn.Sequential):
def __init__(
self,
in_channels,
out_channels,
kernel_size,
padding=0,
stride=1,
use_batchnorm=True,
):
if use_batchnorm == "inplace" and InPlaceABN is None:
raise RuntimeError(
"In order to use `use_batchnorm='inplace'` inplace_abn package must be installed. "
+ "To install see: https://github.com/mapillary/inplace_abn"
)
conv = nn.Conv2d(
in_channels,
out_channels,
kernel_size,
stride=stride,
padding=padding,
bias=not (use_batchnorm),
)
relu = nn.ReLU(inplace=True)
if use_batchnorm == "inplace":
bn = InPlaceABN(out_channels, activation="leaky_relu", activation_param=0.0)
relu = nn.Identity()
elif use_batchnorm and use_batchnorm != "inplace":
bn = nn.BatchNorm2d(out_channels)
else:
bn = nn.Identity()
super(Conv2dReLU, self).__init__(conv, bn, relu)
from turtle import forward
from torch.fx.experimental.optimization import fuse
import torch
import torch.nn as nn
import time
import segmentation_models_pytorch.base.modules as md
from utils.torchUtils import fuse_conv_and_bn
def fuseModel(model): # fuse model Conv2d() + BatchNorm2d() layers
for m in model.modules():
if isinstance(m, (md.Conv2dReLU)) and isinstance(m[1], (nn.BatchNorm2d)):
m[0] = fuse_conv_and_bn(m[0], m[1]) # update conv
m[1] = nn.Identity()
count += 1
return model
边栏推荐
- Quantitative analysis of PSNR, SSIM and RMSE
- [npuctf2020]ezlogin XPath injection
- What if win11 can't turn off the sticky key? The sticky key is cancelled but it doesn't work. How to solve it
- 提交代码流程
- 万物并作,吾以观复|OceanBase 政企行业实践
- Explain promise usage in detail
- 第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】
- LINQ usage collection in C #
- Use the scroll bar of souI when using the real window in souI
- Writing of head and bottom components of non routing components
猜你喜欢
Interface switching based on pyqt5 toolbar button -1
基于Pyqt5工具栏按钮可实现界面切换-2
基于Pyqt5工具栏按钮可实现界面切换-1
公司里只有一个测试是什么体验?听听他们怎么说吧
Connexion à distance de la tarte aux framboises en mode visionneur VNC
Talk about memory model and memory order
Go project operation method
采用VNC Viewer方式遠程連接樹莓派
BBR 遭遇 CUBIC
Implementation of VGA protocol based on FPGA
随机推荐
VIM interval deletion note
Win11系统explorer频繁卡死无响应的三种解决方法
ping域名报错unknown host,nslookup/systemd-resolve可以正常解析,ping公网地址通怎么解决?
[analysis of STL source code] imitation function (to be supplemented)
Cryptography -- the mode of block cipher
RuntimeError: no valid convolution algorithms available in CuDNN
密码技术---密钥和SSL/TLS
FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
面试过了,起薪16k
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
Call vs2015 with MATLAB to compile vs Project
What can I do after buying a domain name?
SQL进阶语法
C MVC creates a view to get rid of the influence of layout
聊聊内存模型与内存序
2022年最新最全软件测试面试题大全
Go project operation method
Win11自动关机设置在哪?Win11设置自动关机的两种方法
20220524_数据库过程_语句留档
[live broadcast appointment] database obcp certification comprehensive upgrade open class