Concurrent Spatial and Channel Squeeze & Excitation in Fullly Convolutional Networks 代码复现

2019年4月18日17:22:48 评论 37

三种SENet Pytorch代码如下:

  1. class CSEModule(nn.Module):
  2.     def __init__(self, ch, re=16):
  3.         super().__init__()
  4.         self.cSE = nn.Sequential(nn.AdaptiveAvgPool2d(1),
  5.                                  nn.Conv2d(ch,ch//re,1),
  6.                                  nn.ReLU(inplace=True),
  7.                                  nn.Conv2d(ch//re,ch,1),
  8.                                  nn.Sigmoid())
  9.     def forward(self, x):
  10.         return x * self.cSE(x) #cSE
  11. class SSEModule(nn.Module):
  12.     def __init__(self, ch, re=16):
  13.         super().__init__()
  14.         self.sSE = nn.Sequential(nn.Conv2d(ch,ch,1),
  15.                                  nn.Sigmoid())
  16.     def forward(self, x):
  17.         return x * self.sSE(x)  #sSE
  18. class SCSEModule(nn.Module):
  19.     def __init__(self, ch, re=16):
  20.         super().__init__()
  21.         self.cSE = nn.Sequential(nn.AdaptiveAvgPool2d(1),
  22.                                  nn.Conv2d(ch,ch//re,1),
  23.                                  nn.ReLU(inplace=True),
  24.                                  nn.Conv2d(ch//re,ch,1),
  25.                                  nn.Sigmoid())
  26.         self.sSE = nn.Sequential(nn.Conv2d(ch,ch,1),
  27.                                  nn.Sigmoid())
  28.     def forward(self, x):
  29.         return x * self.cSE(x) + x * self.sSE(x)  #scSE

论文原文:Concurrent Spatial and Channel Squeeze & Excitation in Fullly Convolutional Networks

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: