当前位置:   article > 正文

【注意力】ESE:Effective Squeeze-and-Excitation Block

effective squeeze-and-excitation block

原文:https://arxiv.org/pdf/1911.06667.pdf

 ESE(Effective Squeeze and Extraction) layer是模型中的一个block,基于SE(Squeeze and Extraction)而来。与SE的区别在于,ESE block只有一个fc层,《CenterMask : Real-Time Anchor-Free Instance Segmentation》的作者注意到SE模块有一个缺点:由于维度的减少导致的通道信息损失。为了避免这种大模型的计算负担,se的2个fc层需要减少通道维度。特别的,当第一个fc层使用r减少输入特征通道,将通道数从c变为c/r的时候,第二个fc层又需要扩张减少的通道数到原始的通道c.在这个过程中,通道维度的减少导致了通道信息的损失。因而,effective SE(eSE)仅仅使用一个通道数为c的fc层代替了两个fc层,避免了通道信息DE丢失;

代码:

  1. def get_act_fn(act=None, trt=False):
  2. assert act is None or isinstance(act, (
  3. str, dict)), 'name of activation should be str, dict or None'
  4. if not act:
  5. return identity
  6. if isinstance(act, dict):
  7. name = act['name']
  8. act.pop('name')
  9. kwargs = act
  10. else:
  11. name = act
  12. kwargs = dict()
  13. if trt and name in TRT_ACT_SPEC:
  14. fn = TRT_ACT_SPEC[name]
  15. elif name in ACT_SPEC:
  16. fn = ACT_SPEC[name]
  17. else:
  18. fn = getattr(F, name)
  19. return lambda x: fn(x, **kwargs)
  20. class EffectiveSELayer(nn.Layer):
  21. """ Effective Squeeze-Excitation
  22. From `CenterMask : Real-Time Anchor-Free Instance Segmentation` - https://arxiv.org/abs/1911.06667
  23. """
  24. def __init__(self, channels, act='hardsigmoid'):
  25. super(EffectiveSELayer, self).__init__()
  26. self.fc = nn.Conv2D(channels, channels, kernel_size=1, padding=0)
  27. self.act = get_act_fn(act) if act is None or isinstance(act, (
  28. str, dict)) else act
  29. def forward(self, x):
  30. x_se = x.mean((2, 3), keepdim=True)
  31. x_se = self.fc(x_se)
  32. return x * self.act(x_se)

代码摘自pp-yoloe(https://github.com/PaddlePaddle/PaddleDetection

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/580610
推荐阅读
相关标签
  

闽ICP备14008679号