A plug-and-play channel attention mechanism module implemented in PyTorch.
Project description
Channel-Attention 
A plug-and-play channel attention mechanism module implemented in PyTorch.
Installation | Usage | Modules | Blog | Experiments
Installation
You can install the package via pip:
pip install channel-attention
We only develop and test with PyTorch. Please make sure to install it from PyTorch official website based on your system configuration.
Usage
The core of the channel attention mechanism lies in its invariance between input and output. Therefore, we can easily embed this module into a certain location in a neural network to further improve the model's performance.
import torch
from channel_attention import SEAttention
# 1D Time Series Data with (batch_size, channels, seq_len)
inputs = torch.rand(8, 16, 128)
attn = SEAttention(n_dims=1, n_channels=16, reduction=4)
print(attn(inputs).shape)
# 2D Image Data with (batch_size, channels, height, width)
inputs_2d = torch.rand(8, 16, 64, 64)
attn_2d = SEAttention(n_dims=2, n_channels=16, reduction=4)
print(attn_2d(inputs_2d).shape)
When the number of input channels is small, the channel attention mechanism is very lightweight and does not significantly increase computational complexity.
Modules
1. SEAttention: [paper] The Squeeze-and-Excitation Attention with Global Average Pooling and Feed Forward Network.
2. ChannelAttention: [paper] The Channel Attention with Global Average Pooling and Global Max Pooling.
3. SpatialAttention: [paper] The Spatial Attention with Global Average Pooling and Global Max Pooling.
4. ConvBlockAttention: [paper] The Convolutional Block Attention Module (CBAM) combining Channel Attention and Spatial Attention.
Experiments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file channel_attention-0.0.1.tar.gz.
File metadata
- Download URL: channel_attention-0.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4e400ef3f70674d2b6209ad0720e20529f7d962250179c3d5836cc82ba9f0ac
|
|
| MD5 |
576c53db57dfc0d0815bef9e954e84fc
|
|
| BLAKE2b-256 |
e50857dca5cfab3b83381dff84d35e22f51e2e79d194018d093269768defae85
|
File details
Details for the file channel_attention-0.0.1-py3-none-any.whl.
File metadata
- Download URL: channel_attention-0.0.1-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
111586eaafe22bfdeb38b9f0c62a4d90780dd86c58ae352649b073307791e2ec
|
|
| MD5 |
4e152e0bc3ce195a691890d8d84371ba
|
|
| BLAKE2b-256 |
f1a85462d80e0f699faba37e3fab134ef9ca7b42751eaf09e92a8a215f97695f
|