Tan_pytorch_segmentation/pytorch_segmentation/PV_Attention/ECA Attention.py

18 lines
923 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks---CVPR2020
论文地址https://arxiv.org/pdf/1910.03151.pdf
这是CVPR2020的一篇文章。
如上图所示SE实现通道注意力是使用两个全连接层而ECA是需要一个的卷积。作者这么做的原因一方面是认为计算所有通道两两之间的注意力是没有必要的另一方面是用两个全连接层确实引入了太多的参数和计算量。
因此作者进行了AvgPool之后只是使用了一个感受野为k的一维卷积相当于只计算与相邻k个通道的注意力这样做就大大的减少的参数和计算量。(i.e.相当于SE是一个global的注意力而ECA是一个local的注意力)。
"""
from attention.ECAAttention import ECAAttention
import torch
input = torch.randn(50, 512, 7, 7)
eca = ECAAttention(kernel_size=3)
output = eca(input)
print(output.shape)