Skip to main content

Channel-Attention

A plug-and-play channel attention mechanism module implemented in PyTorch.

PyPI version License PyTorch Downloads codestyle

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

Metadata

Release files for channel-attention 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for channel-attention 0.0.1
File Size Uploaded
channel_attention-0.0.1.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for channel-attention 0.0.1
File Interpreter ABI Platform
channel_attention-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.4 kB

Release files / channel_attention-0.0.1.tar.gz

Download URL channel_attention-0.0.1.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c4e400ef3f70674d2b6209ad0720e20529f7d962250179c3d5836cc82ba9f0ac
BLAKE2b-256 checksum
How to use checksums
e50857dca5cfab3b83381dff84d35e22f51e2e79d194018d093269768defae85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.17

Release files / channel_attention-0.0.1-py3-none-any.whl

Download URL channel_attention-0.0.1-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
111586eaafe22bfdeb38b9f0c62a4d90780dd86c58ae352649b073307791e2ec
BLAKE2b-256 checksum
How to use checksums
f1a85462d80e0f699faba37e3fab134ef9ca7b42751eaf09e92a8a215f97695f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page