当前位置:网站首页>Pytorch implementation of packet convolution depth separable convolution
Pytorch implementation of packet convolution depth separable convolution
2022-07-22 02:54:00 【wzw12315】
- Conventional convolution :
The parameter quantity required for conventional convolution :Cin×K×K×Cout
- Grouping convolution :
The amount of computation required for grouping convolution : Cin×K×K×Cout / g
Depth separates the convolution (Depthwise Separable Convolution):
Calculation amount required :Cin×K×K+Cout×1×1
Realization :
import torch
from torchsummary import summary
import torch.nn as nn
'''
Realize packet convolution demo
'''
class CRNN(nn.Module):
def __init__(self,in_channel,out_channel,group):
super(CRNN,self).__init__()
self.conv = nn.Conv2d(in_channels=in_channel,
out_channels=out_channel,
kernel_size=3,
stride=1,
padding=1,
groups=group,
bias=False)
def forward(self,input):
out = self.conv(input)
return out
'''
Depth separates the convolution demo
'''
class DEPTHWISECONV(nn.Module):
def __init__(self,in_ch,out_ch):
super(DEPTHWISECONV, self).__init__()
self.depth_conv = nn.Conv2d(in_channels=in_ch,
out_channels=in_ch,
kernel_size=3,
stride=1,
padding=1,
groups=in_ch)
self.point_conv = nn.Conv2d(in_channels=in_ch,
out_channels=out_ch,
kernel_size=1,
stride=1,
padding=0,
groups=1)
def forward(self,input):
out = self.depth_conv(input)
out = self.point_conv(out)
return out
if __name__=='__main__':
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
conv = CRNN(3,6,1).to(device)
print(summary(conv,input_size=(3,32,32)))
dp = DEPTHWISECONV(3,6).to(device)
print(summary(dp,input_size=(3,32,32)))
reference:https://blog.csdn.net/weixin_30793735/article/details/88915612
边栏推荐
- tslib-1.4移植到mini2440开发板
- MySQL performance optimization (II): select the optimized data type
- Qt|控制QScrollBar显示位置
- Leetcode 104. 二叉树的最大深度
- Force buckle 1260 2D mesh migration
- 接口测试经典面试题:Session、cookie、token有什么区别?
- Educational Codeforces Round 70 A题 You Are Given Two Binary Strings...
- 简单总结一下图像处理中概念
- Construction practice of pipeline engine of engineering efficiency ci/cd
- MySQL performance optimization (I): MySQL architecture and core issues
猜你喜欢
Teach you to upload NCBI data hand in hand, and you can learn it in the free course package!
Flink应用案例统计实现TopN的两种方式
Clear DNS cache on local computer + clear DNS cache on Browser
2019杭电多校 第一场 6581-Vacation【思维】
不懂点儿统计学,《星球大战》白看了
quartz簡單用法及其es-job
阿里云技术专家杨泽强:弹性计算云上可观测能力构建
bootloader系列三——核心初始化
荐号 | 真正的卓越者,都在践行“人生最优策略”,推荐这几个优质号
生成数字图像基本过程
随机推荐
tslib-1.4移植到mini2440开发板
卷积核扩大到51x51,新型CNN架构SLaK反击Transformer
虚拟机win7系统安装vmtool
Transplant tslib-1.4 to mini2440 development board
SVD singular value decomposition matrix compression
45W performance release +2.8k OLED full screen ASUS lingyao x 142022 elite temperament efficient weapon
弹性体模拟(弹性力学)
pytorch实现 分组卷积 深度可分离卷积
The convolution kernel is expanded to 51x51, and the new CNN architecture slak counterattacks the transformer
树莓派3B搭建Flink集群
Codeforces Round #579 (Div. 3) A 、B、E
[wechat applet] camera system camera (79/100)
872. 最大公约数
Airbnb 如何实现 Kubernetes 集群动态扩展
870. 约数个数
Codeforces Round #579 (Div. 3) C - Common Divisors 【数论】
图像矫正 + 文本矫正 技术深入探讨
MySQL performance optimization (I): MySQL architecture and core issues
文字检测篇-传统篇
力扣 1260. 二维网格迁移