码迷,mamicode.com
首页 > 其他好文 > 详细

Involution: Inverting the Inherence of Convolution for Visual Recognition

时间:2021-05-24 08:20:08      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:code   super   提取   __init__   color   中心   http   avg   seq   

https://arxiv.org/abs/2103.06255

------------------------------------------------------------------

2021-04-08

convolution

  平移不变性  权值共享

  每个通道提取不同的特征

Involution

  kernel在空间范围上是不同的,在通道上共享

卷积    组卷积   深度卷积

卷积核为奇数:

  1.padding是对称的    (k-1)//2

  2.有中心点

 

class Involution(nn.Module):
    def __init__(self,channel,kernel_size,stride):
        super(Involution,self).__init__()

        self.stride=stride
        self.kernel_size=kernel_size
        self.channel=channel
        self.reduction=4
        self.group_channel=16
        assert channel%self.group_channel==0
        self.groups=channel//self.group_channel

        self.conv1=nn.Sequential(
            nn.Conv2d(channel,channel//self.reduction,1,bias=False),
            nn.BatchNorm2d(channel//self.reduction),
            nn.ReLU(inplace=True)
        )

        self.conv2=nn.Sequential(
            nn.Conv2d(channel//self.reduction,kernel_size**2*self.groups,1,bias=False)
        )

        if stride>1:
            self.avg=nn.AvgPool2d(stride,stride)

        self.unf=nn.Unfold(kernel_size,1,(kernel_size-1)//2,stride)

    def forward(self,x):
        weight=self.conv2(self.conv1(x if self.stride==1 else self.avg(x)))
        N,C,H,W=weight.size()
        weight=weight.view(N,self.groups,self.kernel_size**2,H,W).unsqueeze(2)
        out=self.unf(x).view(N,self.groups,self.group_channel,self.kernel_size**2,H,W)
        out=(weight*out).sum(dim=3).view(N,self.channel,H,W)
        return out

 

 

  

  

Involution: Inverting the Inherence of Convolution for Visual Recognition

标签:code   super   提取   __init__   color   中心   http   avg   seq   

原文地址:https://www.cnblogs.com/shuimobanchengyan/p/14634820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!