当前位置:网站首页>pytorch实现 分组卷积 深度可分离卷积
pytorch实现 分组卷积 深度可分离卷积
2022-07-21 10:04:00 【wzw12315】
- 常规卷积:
常规卷积需要的参数量:Cin×K×K×Cout
- 分组卷积:
分组卷积需要的计算量 : Cin×K×K×Cout / g
深度可分离卷积(Depthwise Separable Convolution):
需要的计算量:Cin×K×K+Cout×1×1
实现:
import torch
from torchsummary import summary
import torch.nn as nn
'''
实现分组卷积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
'''
深度可分离卷积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
边栏推荐
- ASUS Adu 14 Pro is equipped with the new generation 12 core standard voltage processor
- Codeforces Round #578 (Div. 2) A - Hotelier 【水题】
- A year has passed, has livedata really been replaced by flow? Will livedata be discarded?
- MobileViT:挑战MobileNet端侧霸主
- 博士申请 | 香港城市大学刘晨老师组招收机器学习方向全奖博士/博后/硕士/RA...
- 小米12S Ultra产品力这么强老外却买不到 雷军:先专心做好中国市场
- IP subnet Division
- Implementing DDD based on ABP -- domain service, application service and dto practice
- SQL每日一练(牛客新题库)——第3天: 条件查询
- Kuberntes云原生实战一 高可用部署架构
猜你喜欢
Resolved (selenium operation Firefox browser error) typeerror:__ init__ () got an unexpected keyword argument ‘firefox_ options‘
卷积核扩大到51x51,新型CNN架构SLaK反击Transformer
2019杭电多校 第一场 6581-Vacation【思维】
OpenMMLAB系列框架解读(基于PyTorch)
Example of implementing web server with stm32+enc28j60+uip protocol stack
Two ways to implement topn with Flink application case statistics
07.01 Huffman tree
Leetcode 104. 二叉树的最大深度
FastDFS高可用使用介绍
quartz簡單用法及其es-job
随机推荐
MySQL进阶
已解决(selenium操作火狐浏览器报错)TypeError: __init__() got an unexpected keyword argument ‘firefox_options‘
MySQL performance optimization (II): select the optimized data type
虚拟机win7系统安装vmtool
leetcode:169. 多数元素
rust 文件读写操作
[Skynet] vs2019 debug Skynet (modify vs2013 project)
quartz簡單用法及其es-job
VMware Workstation Pro virtual machine network three types of network cards and their usage
Network wiring and number system conversion
thymeleaf应用笔记
数据治理过程中会遇到那些数据问题?
身份证号码中间位数隐藏
Utilisation simple de quartz et de ses emplois
duilib实战1-模仿百度网盘登录界面
Un7.20: how to display two attributes in an association table at the same time?
Redis基础知识、应用场景、集群安装
SQL每日一练(牛客新题库)——第3天: 条件查询
quartz简单用法及其es-job
IP子网划分