当前位置:网站首页>倒置残差的理解
倒置残差的理解
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 MHA high availability configuration and failover

删除AWS绑定的信用卡账户
![[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

【juc学习之路第9天】屏障衍生工具

Learning notes on futuretask source code of concurrent programming series

【图像分割】2021-SegFormer NeurIPS
![快乐数[环类问题之快慢指针]](/img/37/5c94b9b062a54067a50918f94e61ea.png)
快乐数[环类问题之快慢指针]

Recent public ancestor offline practice (tarjan)

IDA动态调试apk

Recent public ancestor (LCA) online practices
随机推荐
记录一次spark on yarn 任务报错 Operation category READ is not supported in state standby
JVM有哪些类加载机制?
Redis配置与优化
3DE resources have nothing or nothing wrong
配置筛选机
【JetCache】JetCache的使用方法与步骤
【MySQL】explain的基本使用以及各列的作用
Matlab traverses images, string arrays and other basic operations
效率提升 - 鼓捣个性化容器开发环境
地图其他篇总目录
固定资产管理子系统报表分为什么大类,包括哪些科目
【c语言】malloc函数详解[通俗易懂]
Indicator trap: seven KPI mistakes that it leaders are prone to make
指标陷阱:IT领导者易犯的七个KPI错误
详解JMM
YOLOv5.5 调用本地摄像头
为什么数字化转型战略必须包括持续测试?
flink sql-client 使用 对照并熟悉官方文档
基准环路增益与相位裕度的测量
Yyds dry goods inventory # solve the real problem of famous enterprises: egg twisting machine