当前位置:网站首页>Understanding of inverted residuals
Understanding of inverted residuals
2022-07-01 22:41:00 【zouxiaolv】
First of all, to understand the inverted residual, we must first understand the form of residual
Residual structure :
1. use 1*1 Convolution dimensionality reduction , For example, the input is 256, Dimensionality reduction 64
2. Using convolution kernel as 3*3 form
3. use 1*1 Convolution dimension ., such as 64 become 256
After understanding the residual structure , Now start to learn the inverted residual structure
1. use 1*1 Convolution dimension , For example, the input is 64, Dimensionality reduction 256
2. The convolution kernel is deeply separable 3*3 form
3. use 1*1 Convolution Dimension reduction . such as 256, Dimensionality reduction 64
The activation function here adopts 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)
边栏推荐
- spark analyze命令使用及其作用 map join broadcast join 广播join
- 高攀不起的希尔排序,直接插入排序
- YOLOv5.5 调用本地摄像头
- [intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
- 配置筛选机
- Recent public ancestor (LCA) online practices
- 深度学习--数据操作
- 人体姿态估计的热图变成坐标点的两种方案
- Appium automated testing foundation - Supplement: introduction to desired capabilities parameters
- MySQL中对于事务的理解
猜你喜欢

2020-ViT ICLR

陈天奇的机器学习编译课(免费)
![[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial](/img/ac/655fd534ef7ab9d991d8fe1c884853.png)
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial

【图像分割】2021-SegFormer NeurIPS

配置筛选机
![[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial](/img/b0/029cdea72483ed9bc8a0d66908983a.png)
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial

The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner

# CutefishOS系统~
![快乐数[环类问题之快慢指针]](/img/37/5c94b9b062a54067a50918f94e61ea.png)
快乐数[环类问题之快慢指针]

Spark interview questions
随机推荐
牛客月赛-分组求对数和
详解ThreadLocal
【MySQL】索引的创建、查看和删除
IDA动态调试apk
多种智能指针
【扫盲】机器学习图像处理中的深层/浅层、局部/全局特征
对象内存布局
LC501. 二叉搜索树中的众数
Slope compensation
【QT小作】封装一个简单的线程管理类
小红书Scheme跳转到指定页面
三翼鸟两周年:羽翼渐丰,腾飞指日可待
互联网的智算架构设计
【MySQL】explain的基本使用以及各列的作用
There is no signal in HDMI in computer games caused by memory, so it crashes
Operation category read is not supported in state standby
The leader of the cloud native theme group of beacon Committee has a long way to go!
2020-ViT ICLR
详解Kubernetes网络模型
Recent public ancestor (LCA) online practices