9大主题卷积神经网络(CNN)的PyTorch实现
极市平台
共 4828字,需浏览 10分钟
·
2020-08-20 11:30
极市导读
从R-CNN到YOLO v3再到M2Det,近年来的目标检测新模型层出不穷,性能也越来越好。本文介绍了它们的PyTorch实现,目前Github已开源,非常实用。>>就在明天,极市直播:极市直播丨张志鹏:Ocean/Ocean+: 实时目标跟踪分割算法,小代价,大增益|ECCV2020
1 典型网络(Classical network)
import torch
import torch.nn as nn
def Conv3x3BNReLU(in_channels,out_channels,stride,padding=1):
return nn.Sequential(
nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=3, stride=stride, padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU6(inplace=True)
)
def Conv1x1BNReLU(in_channels,out_channels):
return nn.Sequential(
nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=1, padding=0),
nn.BatchNorm2d(out_channels),
nn.ReLU6(inplace=True)
)
def ConvBNReLU(in_channels,out_channels,kernel_size,stride,padding=1):
return nn.Sequential(
nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, padding=padding),
nn.BatchNorm2d(out_channels),
nn.ReLU6(inplace=True)
)
def ConvBN(in_channels,out_channels,kernel_size,stride,padding=1):
return nn.Sequential(
nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, padding=padding),
nn.BatchNorm2d(out_channels)
)
class ResidualBlock(nn.Module):
def __init__(self, in_channels, out_channels):
super(ResidualBlock, self).__init__()
mid_channels = out_channels//2
self.bottleneck = nn.Sequential(
ConvBNReLU(in_channels=in_channels, out_channels=mid_channels, kernel_size=1, stride=1),
ConvBNReLU(in_channels=mid_channels, out_channels=mid_channels, kernel_size=3, stride=1, padding=1),
ConvBNReLU(in_channels=mid_channels, out_channels=out_channels, kernel_size=1, stride=1),
)
self.shortcut = ConvBNReLU(in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=1)
def forward(self, x):
out = self.bottleneck(x)
return out+self.shortcut(x)
2 轻量级网络(Lightweight)
7 人体姿态识别网络(HumanPoseEstimation)
8 注意力机制网络
9 人像分割网络(PortraitSegmentation)
推荐阅读
通道注意力超强改进,轻量模块ECANet来了!即插即用,显著提高CNN性能|已开源 凭什么相信你,我的CNN模型?关于CNN模型可解释性的思考 深度学习准「研究僧」预习资料:图灵奖得主Yann LeCun《深度学习(Pytorch)》春季课程
评论