当前位置:网站首页>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)
边栏推荐
- 3DE resources have nothing or nothing wrong
- 旅游管理系统
- 高攀不起的希尔排序,直接插入排序
- Show member variables and methods in classes in idea
- In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
- Easyexcel complex data export
- QT 使用FFmpeg4将argb的Qimage转换成YUV422P
- Why must digital transformation strategies include continuous testing?
- 地图其他篇总目录
- cvpr2022 human pose estiamtion
猜你喜欢
MySQL5.7 设置密码策略(等保三级密码改造)
2020-ViT ICLR
快乐数[环类问题之快慢指针]
keras训练的H5模型转tflite
Recent public ancestor (LCA) online practices
Mysql——》MyISAM存储引擎的索引
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
黑马程序员-软件测试--06阶段2-linux和数据库-01-08第一章-linux操作系统阶段内容说明,linux命令基本格式以及常见形式的说明,操作系统的常见的分类,查看命令帮助信息方法,
Redis configuration and optimization
Appium自动化测试基础 — 补充:Desired Capabilities参数介绍
随机推荐
Niuke monthly race - logarithmic sum in groups
快乐数[环类问题之快慢指针]
Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
MySQL的存储过程
Kubernetes创建Service访问Pod
QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
友善串口助手使用教程_友善串口调试助手怎么进行配置-友善串口调试助手使用教程…
2020-ViT ICLR
#yyds干货盘点# 解决名企真题:扭蛋机
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
MySQL5.7 设置密码策略(等保三级密码改造)
Show member variables and methods in classes in idea
Configure filter
MySQL MHA high availability configuration and failover
详解Volatile关键字
Matlab traverses images, string arrays and other basic operations
【juc学习之路第9天】屏障衍生工具
互联网的智算架构设计
Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
447-哔哩哔哩面经1