当前位置:网站首页>倒置残差的理解
倒置残差的理解
2022-07-01 21:47:00 【zouxiaolv】
倒残差与线性瓶颈浅析 - MobileNetV2_晓野豬的博客-CSDN博客_倒残差结构
首先理解倒置残差要先了解残差形式
残差结构:
1.采用1*1卷积降维,比如输入是256,降维到64
2.采用卷积核为3*3形式
3.采用1*1卷积升维。,比如64变成256
了解完残差结构后,现在开始学习倒置残差结构
1.采用1*1卷积升维,比如输入是64,降维到256
2.采用卷积核为深度可分离的3*3形式
3.采用1*1卷积 降维。比如256,降维到64
这里的激活函数采用的是relu6
# _*_coding:utf-8_*_
import torch
import torch.nn as nn
class InvertedResidualsBlock(nn.Module):
def __init__(self, in_channels, out_channels, expansion, stride):
super(InvertedResidualsBlock, self).__init__()
channels = expansion * in_channels
self.stride = stride
self.basic_block = nn.Sequential(
nn.Conv2d(in_channels, channels, kernel_size=1, stride=1, bias=False),
nn.BatchNorm2d(channels),
nn.ReLU6(inplace=True),
nn.Conv2d(channels, channels, kernel_size=3, stride=stride, padding=1, groups=channels, bias=False),
nn.BatchNorm2d(channels),
nn.ReLU6(inplace=True),
nn.Conv2d(channels, out_channels, kernel_size=1, stride=1, bias=False),
nn.BatchNorm2d(out_channels)
)
# The shortcut operation does not affect the number of channels
self.shortcut = nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, bias=False),
nn.BatchNorm2d(out_channels)
)
def forward(self, x):
out = self.basic_block(x)
if self.stride == 1:
print("With shortcut!")
out = out + self.shortcut(x)
else:
print("No shortcut!")
print(out.size())
return out
if __name__ == "__main__":
x = torch.randn(16, 3, 32, 32)
# no shortcut
net1 = InvertedResidualsBlock(3, 6, 6, 2)
# with shortcut
net2 = InvertedResidualsBlock(3, 6, 6, 1)
y1, y2 = net1(x), net2(x)
边栏推荐
- Compensation des créneaux horaires
- CIO's discussion and Analysis on the definition of high-performance it team
- What is the difference between PMP and NPDP?
- spark analyze命令使用及其作用 map join broadcast join 广播join
- 【MySQL】索引的创建、查看和删除
- 【JetCache】JetCache的使用方法与步骤
- MySQL中对于事务的理解
- Learning notes on futuretask source code of concurrent programming series
- 为什么数字化转型战略必须包括持续测试?
- Slope compensation
猜你喜欢
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
Mysql——》MyISAM存储引擎的索引
MySQL中对于索引的理解
Relationship and difference between enterprise architecture and project management
Redis configuration and optimization
切面条 C语言
In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
C#/VB. Net to add text / image watermarks to PDF documents
Learning notes on futuretask source code of concurrent programming series
随机推荐
【JetCache】JetCache的使用方法与步骤
91.(cesium篇)cesium火箭发射模拟
EasyExcel 复杂数据导出
【日常训练】326. 3 的幂
Object memory layout
GenICam GenTL 标准 ver1.5(4)第五章 采集引擎
Compensation des créneaux horaires
Four methods of JS array splicing [easy to understand]
plantuml介绍与使用
功能测试报告的编写
Yolov5.5 call local camera
配置筛选机
Copy ‘XXXX‘ to effectively final temp variable
PyTorch磨刀篇|argmax和argmin函数
Why must digital transformation strategies include continuous testing?
Fully annotated SSM framework construction
【目标跟踪】|单目标跟踪指标
完全注解的ssm框架搭建
牛客月赛-分组求对数和
Basic knowledge of ngnix