当前位置:网站首页>倒置残差的理解
倒置残差的理解
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)
边栏推荐
- 【MySQL】索引的分类
- 微信开放平台扫码登录[通俗易懂]
- Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
- keras训练的H5模型转tflite
- Copy ‘XXXX‘ to effectively final temp variable
- Redis configuration and optimization
- QT 使用FFmpeg4将argb的Qimage转换成YUV422P
- Slope compensation
- Slope compensation
- QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
猜你喜欢
随机推荐
高攀不起的希尔排序,直接插入排序
快乐数[环类问题之快慢指针]
2020-ViT ICLR
MySQL之MHA高可用配置及故障切换
搜狗微信APP逆向(二)so层
固定资产管理子系统报表分为什么大类,包括哪些科目
[ecological partner] Kunpeng system engineer training
详解JMM
JVM有哪些类加载机制?
【juc学习之路第9天】屏障衍生工具
性能测试计划怎么编写
比较版本号[双指针截取自己想要的字串]
MySQL的视图练习题
20220701
plantuml介绍与使用
IDA动态调试apk
Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
地图其他篇总目录
【日常训练】326. 3 的幂
MySQL MHA high availability configuration and failover