当前位置:网站首页>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
边栏推荐
- Interface switching based on pyqt5 toolbar button -1
- Three solutions to frequent sticking and no response of explorer in win11 system
- FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
- ADC of stm32
- 跨境电商如何通过打好数据底座,实现低成本稳步增长
- Go basic anonymous variable
- Detailed explanation and application of merging and sorting
- SharedPreferences save list < bean > to local and solve com google. gson. internal. Linkedtreemap cannot be cast to exception
- [analysis of STL source code] imitation function (to be supplemented)
- Static file display problem
猜你喜欢
![[redis notes] compressed list (ziplist)](/img/83/ff38fabb1baebc5fa4d3d72da315dc.png)
[redis notes] compressed list (ziplist)

RuntimeError: no valid convolution algorithms available in CuDNN
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[live broadcast appointment] database obcp certification comprehensive upgrade open class
![Temperature measurement and display of 51 single chip microcomputer [simulation]](/img/83/73ee7f87787690aef7f0a9dab2c192.jpg)
Temperature measurement and display of 51 single chip microcomputer [simulation]

聊聊内存模型与内存序

LINQ usage collection in C #

潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)

Use of recyclerview with viewbinding

Catalogue of digital image processing experiments

Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
随机推荐
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
What experience is there only one test in the company? Listen to what they say
解决:exceptiole ‘xxxxx.QRTZ_LOCKS‘ doesn‘t exist以及mysql的my.cnf文件追加lower_case_table_names后启动报错
Win11系统explorer频繁卡死无响应的三种解决方法
YOLOX加强特征提取网络Panet分析
golang入门:for...range修改切片中元素的值的另类方法
Compose 中的 'ViewPager' 详解 | 开发者说·DTalk
Loss function~
Print out mode of go
力扣刷题(2022-6-28)
“一个优秀程序员可抵五个普通程序员!”
采用VNC Viewer方式远程连接树莓派
Doorplate making C language
基于Pyqt5工具栏按钮可实现界面切换-1
Brief introduction of emotional dialogue recognition and generation
Three solutions to frequent sticking and no response of explorer in win11 system
設置單擊右鍵可以選擇用VS Code打開文件
Go basic constant definition and use
基于Pyqt5工具栏按钮可实现界面切换-2
Submit code process