当前位置:网站首页>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
边栏推荐
- vim区间删行注释
- @BindsInstance在Dagger2中怎么使用
- 深度剖析数据在内存中的存储----C语言篇
- [redis notes] compressed list (ziplist)
- Warning: implicitly declaring library function 'printf' with type 'int (const char *,...)‘
- Talk about memory model and memory order
- Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
- Set right click to select vs code to open the file
- Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
- Doorplate making C language
猜你喜欢
程序员版本的八荣八耻~
BBR 遭遇 CUBIC
C#中Linq用法汇集
Redis 过期策略+conf 记录
BBR encounters cubic
Simple square wave generating circuit [51 single chip microcomputer and 8253a]
Hisilicon VI access video process
详解Promise使用
RecyclerView结合ViewBinding的使用
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
随机推荐
YOLOX加强特征提取网络Panet分析
Eight honors and eight disgraces of the programmer version~
How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!
MarkDown基本语法
20220524_数据库过程_语句留档
Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
Brief introduction of emotional dialogue recognition and generation
Submit code process
潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
跨境电商如何通过打好数据底座,实现低成本稳步增长
[proteus simulation] 51 MCU +lcd12864 push box game
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
php 获取真实ip
[redis notes] compressed list (ziplist)
【STL源码剖析】仿函数(待补充)
Catalogue of digital image processing experiments
Redis 过期策略+conf 记录
Go basic data type