当前位置:网站首页>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
边栏推荐
- Ideal car × Oceanbase: when the new forces of car building meet the new forces of database
- Solution to boost library link error
- Writing of head and bottom components of non routing components
- 理想汽车×OceanBase:当造车新势力遇上数据库新势力
- Tiktok actual combat ~ number of likes pop-up box
- 4 special cases! Schools in area a adopt the re examination score line in area B!
- Potplayer set minimized shortcut keys
- Doorplate making C language
- 【STL源码剖析】仿函数(待补充)
- 实现BottomNavigationView和Navigation联动
猜你喜欢

基于Pyqt5工具栏按钮可实现界面切换-1

(stinger) use pystinger Socks4 to go online and not go out of the network host

Cryptography -- the mode of block cipher

Detailed explanation and application of merging and sorting

基于FPGA的VGA协议实现

BBR 遭遇 CUBIC

Getting started with golang: for Range an alternative method of modifying the values of elements in slices

Writing of head and bottom components of non routing components

Prometheus deployment

购买完域名之后能干什么事儿?
随机推荐
Application of containerization technology in embedded field
Numerical solution of partial differential equations with MATLAB
Realize the linkage between bottomnavigationview and navigation
Doorplate making C language
海思调用接口之Makefile配置
MySQL queries nearby data And sort by distance
公司里只有一个测试是什么体验?听听他们怎么说吧
Go basic anonymous variable
Value sequence < detailed explanation of daily question >
SQL进阶语法
Connexion à distance de la tarte aux framboises en mode visionneur VNC
I've been interviewed. The starting salary is 16K
What can I do after buying a domain name?
Temperature measurement and display of 51 single chip microcomputer [simulation]
設置單擊右鍵可以選擇用VS Code打開文件
Set right click to select vs code to open the file
Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
Print out mode of go
Detailed explanation of 'viewpager' in compose | developer said · dtalk
【STL源码剖析】仿函数(待补充)