FcaNet: Frequency Channel Attention Networks 

paper:http://arxiv.org/abs/2012.11879

code:https://github.com/dcdcvgroup/FcaNet

这篇论文,将GAP推广到一种更为一般的2维的离散余弦变换(DCT)形式,通过引入更多的frequency analysis重新考虑通道的注意力。

摘要

注意机制,特别是通道注意,在计算机视觉领域取得了巨大的成功。许多工作集中在如何设计有效的通道注意机制,而忽略了一个基本问题,即通道注意机制使用标量来表示通道,这由于大量信息损失而困难。在这项工作中,从一个不同的观点开始,并将特征通道表示问题视为一个使用频率分析的压缩过程。在频率分析的基础上,用数学方法证明了传统的全局平均池化是频域特征分解的一种特例。在此基础上,自然地推广了频域通道注意机制的压缩问题,并提出了具有多频谱信道注意特性的方法,称为FcaNet。FcaNet很简单,但也很有效。可以在计算中的几行代码实现该方法。此外,与其他通道注意方法相比,该方法在图像分类、目标检测和实例se等方面都取得了最先进的效果。

论文主要思想

作者认为在通道注意力里的GAP抑制了通道之间的多样性,且GAP本质是离散余弦变换(DCT)的最低分频。若从频域角度分析,可以使用更多有用的其它分量,从而形成一个多谱通道注意力(Multi-Spectral Channel Attention)。重要的是文中设计了一种启发式的两步准则来选择多谱注意力模块的频率分量,其主要思想是先得到每个频率分量的重要性再确定不同数目频率分量的效果。具体而言,先分别计算通道注意力中采用各个频率分量的结果,然后,根据结果少选出topk个性能最好的分量。

Keras实现

以下是根据论文和pytorch源码实现的keras版本(支持Tensorflow1.x)。

def fca(inputs, name, ratio=8):w, h, out_dim = [int(x) for x in inputs.shape[1:]]temp_dim = max(out_dim // ratio, ratio)pool = MultiSpectralAttentionLayer(out_dim, h, w)(inputs)excitation = Dense(temp_dim, activation='relu', use_bias=False, name=name + '_Dense_1')(pool)excitation = Dense(out_dim, activation='sigmoid', use_bias=False,name=name + '_Dense_2')(excitation)excitation = Reshape((1, 1, out_dim), name=name + '_Reshape')(excitation)excitation = Multiply(name=name + '_Multiply')([inputs, excitation])return excitation
import math
import tensorflow as tf
from keras.layers import Layer
import numpy as npdef get_freq_indices(method):assert method in ['top1', 'top2', 'top4', 'top8', 'top16', 'top32','bot1', 'bot2', 'bot4', 'bot8', 'bot16', 'bot32','low1', 'low2', 'low4', 'low8', 'low16', 'low32']num_freq = int(method[3:])if 'top' in method:all_top_indices_x = [0, 0, 6, 0, 0, 1, 1, 4, 5, 1, 3, 0, 0, 0, 3, 2, 4, 6, 3, 5, 5, 2, 6, 5, 5, 3, 3, 4, 2, 2,6, 1]all_top_indices_y = [0, 1, 0, 5, 2, 0, 2, 0, 0, 6, 0, 4, 6, 3, 5, 2, 6, 3, 3, 3, 5, 1, 1, 2, 4, 2, 1, 1, 3, 0,5, 3]mapper_x = all_top_indices_x[:num_freq]mapper_y = all_top_indices_y[:num_freq]elif 'low' in method:all_low_indices_x = [0, 0, 1, 1, 0, 2, 2, 1, 2, 0, 3, 4, 0, 1, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 1, 2,3, 4]all_low_indices_y = [0, 1, 0, 1, 2, 0, 1, 2, 2, 3, 0, 0, 4, 3, 1, 5, 4, 3, 2, 1, 0, 6, 5, 4, 3, 2, 1, 0, 6, 5,4, 3]mapper_x = all_low_indices_x[:num_freq]mapper_y = all_low_indices_y[:num_freq]elif 'bot' in method:all_bot_indices_x = [6, 1, 3, 3, 2, 4, 1, 2, 4, 4, 5, 1, 4, 6, 2, 5, 6, 1, 6, 2, 2, 4, 3, 3, 5, 5, 6, 2, 5, 5,3, 6]all_bot_indices_y = [6, 4, 4, 6, 6, 3, 1, 4, 4, 5, 6, 5, 2, 2, 5, 1, 4, 3, 5, 0, 3, 1, 1, 2, 4, 2, 1, 1, 5, 3,3, 3]mapper_x = all_bot_indices_x[:num_freq]mapper_y = all_bot_indices_y[:num_freq]else:raise NotImplementedErrorreturn mapper_x, mapper_yclass MultiSpectralAttentionLayer(Layer):def __init__(self, channel, dct_h, dct_w, reduction=16, freq_sel_method='top16'):super(MultiSpectralAttentionLayer, self).__init__()self.reduction = reductionself.dct_h = dct_hself.dct_w = dct_wmapper_x, mapper_y = get_freq_indices(freq_sel_method)self.num_split = len(mapper_x)mapper_x = [temp_x * (dct_h // 7) for temp_x in mapper_x]mapper_y = [temp_y * (dct_w // 7) for temp_y in mapper_y]# make the frequencies in different sizes are identical to a 7x7 frequency space# eg, (2,2) in 14x14 is identical to (1,1) in 7x7assert len(mapper_x) == len(mapper_y)assert channel % len(mapper_x) == 0self.num_freq = len(mapper_x)# fixed DCT initself.weight = self.get_dct_filter(dct_h, dct_w, mapper_x, mapper_y, channel).transpose([2, 1, 0])def call(self, x):x = x * self.weightresult = tf.reduce_sum(x, axis=[1, 2])return resultdef compute_output_shape(self, input_shape):return (input_shape[0], input_shape[-1])def build_filter(self, pos, freq, POS):result = math.cos(math.pi * freq * (pos + 0.5) / POS) / math.sqrt(POS)if freq == 0:return resultelse:return result * math.sqrt(2)def get_dct_filter(self, tile_size_x, tile_size_y, mapper_x, mapper_y, channel):dct_filter = np.zeros((channel, tile_size_x, tile_size_y))c_part = channel // len(mapper_x)for i, (u_x, v_y) in enumerate(zip(mapper_x, mapper_y)):for t_x in range(tile_size_x):for t_y in range(tile_size_y):dct_filter[i * c_part: (i + 1) * c_part, t_x, t_y] = self.build_filter(t_x, u_x,tile_size_x) * self.build_filter(t_y, v_y, tile_size_y)return dct_filter

声明:本内容来源网络,版权属于原作者,图片来源原论文。如有侵权,联系删除。

创作不易,欢迎大家点赞评论收藏关注!(想看更多最新的注意力机制文献欢迎关注浏览我的博客)

浙大 | FcaNet:频域通道注意力机制(keras实现)相关推荐

  1. 刚刚!频域通道注意力网络FcaNet开源了!

    去年12月底,来自浙江大学李玺老师组的一篇文章,从频域思考注意力机制,提出了频域注意力方法FcaNet. 该方法简单有效,在现有通道注意力机制中,只需改变计算中的一行代码即可实现. 所提出的方法在图像 ...

  2. 【深度学习】(8) CNN中的通道注意力机制(SEnet、ECAnet),附Tensorflow完整代码

    各位同学好,今天和大家分享一下attention注意力机制在CNN卷积神经网络中的应用,重点介绍三种注意力机制,及其代码复现. 在我之前的神经网络专栏的文章中也使用到过注意力机制,比如在MobileN ...

  3. 通道注意力机制 cnn keras_【CV中的Attention机制】简单而有效的CBAM模块

    前言: CBAM模块由于其使用的广泛性以及易于集成得到很多应用.目前cv领域中的attention机制也是在2019年论文中非常火.这篇cbam虽然是在2018年提出的,但是其影响力比较深远,在很多领 ...

  4. 空间注意力机制和通道注意力机制详解

    Attention机制在近几年来在图像,自然语言处理等领域中都取得了重要的突破,被证明有益于提高模型的性能. Attention机制本身也是符合人脑和人眼的感知机制,这次我们主要以计算机视觉领域为例, ...

  5. 通道注意力机制keras_在TensorFlow+Keras环境下使用RoI池化一步步实现注意力机制

    项目地址:https://gist.github.com/Jsevillamol/0daac5a6001843942f91f2a3daea27a7 理解 RoI 池化 RoI 池化的概念由 Ross ...

  6. 通道注意力机制_即插即用,Triplet Attention机制让Channel和Spatial交互更加丰富(附开源代码)...

    ↑ 点击蓝字 关注极市平台作者丨ChaucerG来源丨AI人工智能初学者编辑丨极市平台 极市导读 本文介绍了一种新的注意力机制--Triplet Attention,它通过使用Triplet Bran ...

  7. WACV 2020 | ULSAM: 超轻量级子空间注意力机制(keras实现)

    ULSAM: Ultra-Lightweight Subspace Attention Module for Compact Convolutional Neural Networks paper:h ...

  8. 《Squeeze-and-Excitation Networks》SE-Net通道注意力机制

    前言 在阅读了一系列Activation Funtion论文之后,其中Dynamic Relu的论文提到了基于注意力机制的网络,因此先来看看经典的SE-Net的原理 Introduction 对于CN ...

  9. SEnet 通道注意力机制

    SENet 在于通过网络根据loss去学习特征权重,获取到每个feature map的重要程度,然后用这个重要程度去给每一个特征通道赋予一个权重值,从而让神经网络去重点关注某些feature map ...

最新文章

  1. CVPR2020 | 商汤-港中文等提出PV-RCNN:3D目标检测新网络
  2. java框架_2020年9个最流行的Java框架
  3. 2009年SOA七大预测:SOA借力云计算
  4. 微信正则表达式 iOS
  5. windows 和linux 同步api对比
  6. 吴晓波之后,“罗辑思维”冲击科创板IPO!网友笑称单口相声也想上市?
  7. 5. 直接三角形分解法
  8. 案例实战:采用redis生成淘宝商品的全局id
  9. QT学习之自定义信号
  10. 【正点原子STM32连载】第三十七章 触摸屏实验 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
  11. 银河麒麟系统查看网络设置命令_银河麒麟配置说明
  12. socket服务器针对客户端ip变更的处理办法
  13. vs2017更新出错:The entire Box execution exiting with result code: 0x0
  14. 树莓派(Raspberry Pi)——为树莓派安装系统及常用工具下载地址
  15. 3 RRC 系统消息 SI
  16. 分享Silverlight/WPF/Windows Phone一周学习导读(11月22日-28日)
  17. STM32关于使用定时器来实现串口通信的整活实验
  18. SyntaxError: Unexpected token u in JSON at position 0
  19. 会导致肝损伤的保健品和中草药
  20. 微软首席执行官鲍尔默简历

热门文章

  1. 记-微服务CPU100%排查之windows版
  2. Exception locking surface SurfaceView报错解决
  3. 男生停止长高的迹象是真的吗?
  4. 数学基础科目经典教材
  5. Edgar--java中的delete小老弟的故事
  6. python的100道简单习题,祝你成为python大神的小老弟
  7. 无人机巡检,风力发电机组表面缺陷检测数据集(YOLO标签)
  8. 测试显卡显存以及tensorflowGPU
  9. fets去除回车符号
  10. 16路彩灯控制器 FPGA-Verilog