当前位置:网站首页>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)
边栏推荐
- Can you get a raise? Analysis on gold content of PMP certificate
- In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
- 【日常训练】326. 3 的幂
- QT 使用FFmpeg4将argb的Qimage转换成YUV422P
- 3DE resources have nothing or nothing wrong
- Pytorch sharpening chapter | argmax and argmin functions
- 三翼鸟两周年:羽翼渐丰,腾飞指日可待
- Measurement of reference loop gain and phase margin
- The leader of the cloud native theme group of beacon Committee has a long way to go!
- flink sql 命令行 连接 yarn
猜你喜欢
随机推荐
3DE resources have nothing or nothing wrong
Mask wearing detection method based on yolov5
PyTorch磨刀篇|argmax和argmin函数
MySQL中对于索引的理解
Recent public ancestor (LCA) online practices
Delete AWS bound credit card account
隐藏用户的创建和使用
How to write a performance test plan
2020-ViT ICLR
Appium自动化测试基础 — APPium安装(一)
性能测试计划怎么编写
20220701
nn.Parameter】Pytorch特征融合自适应权重设置(可学习权重使用)
黑马程序员-软件测试--06阶段2-linux和数据库-01-08第一章-linux操作系统阶段内容说明,linux命令基本格式以及常见形式的说明,操作系统的常见的分类,查看命令帮助信息方法,
flink sql 命令行 连接 yarn
【juc学习之路第9天】屏障衍生工具
The fixed assets management subsystem reports are divided into what categories and which accounts are included
【扫盲】机器学习图像处理中的深层/浅层、局部/全局特征
Why must digital transformation strategies include continuous testing?
Easyexcel complex data export