sage.architecture.frontend.mscnn1d_cbam
Filename : mscnn1d_cbam.py Description : Short description of the file
Created on 2026-03-10 02:01:49
__author__ = Narenraju Nagarajan __copyright__ = Copyright 2026, ProjectName __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __affiliation__ = N/A __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]
GitHub Repository: NULL
Documentation: NULL
Classes
1D convolution with |
|
Inception-style multi-scale 1D convolution block with five parallel paths. |
|
1D CBAM channel-attention gate. |
|
1D CBAM temporal (spatial) attention gate. |
|
Three-stage multi-scale 1D CNN frontend with per-stage CBAM attention. |
Module Contents
- class Conv1dSame(in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True)[source]
Bases:
torch.nn.Conv1d1D convolution with
padding="same"semantics (output length == input length).Thin subclass of
torch.nn.Conv1dthat hard-codespadding="same"so callers do not need to compute padding manually. Accepts all standardnn.Conv1darguments exceptpadding.Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class ConcatBlockConv5(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, act=nn.SiLU)[source]
Bases:
torch.nn.ModuleInception-style multi-scale 1D convolution block with five parallel paths.
Runs five Conv1dSame branches at kernel sizes
k,2k,k/2,k/4, and4kin parallel, concatenates all outputs with the identity skip, then fuses with a pointwise (1×1) convolution. The wide range of receptive fields lets a single block capture both fine-grained features and long-range chirp structure simultaneously.- Parameters:
in_channels (int) – Number of input channels.
out_channels (int) – Number of output channels produced by each branch and the fused output.
kernel_size (int) – Base kernel size
k; the five branches usek, 2k, k//2, k//4, 4k.stride (int) – Convolution stride (default
1).padding (int) – Ignored —
Conv1dSamehandles padding automatically.dilation (int) – Dilation factor for all branches (default
1).groups (int) – Grouped convolution groups (default
1).bias (bool) – Whether to add a bias term (default
True).act (nn.Module) – Activation class applied after each BN (default
SiLU).state (Initialize internal Module)
ScriptModule. (shared by both nn.Module and)
- class ChannelAttention1D(in_channels, reduction=16)[source]
Bases:
torch.nn.Module1D CBAM channel-attention gate.
Applies both average and max global temporal pooling, passes each through a shared two-layer FC (with bottleneck ratio
reduction), sums, applies sigmoid, and rescales the input channel-wise.- Parameters:
- class TemporalAttention1D(in_channels, kernel_size=7)[source]
Bases:
torch.nn.Module1D CBAM temporal (spatial) attention gate.
Concatenates channel-wise average and max features along the time axis, applies a single 1D convolution + sigmoid to produce a time-step attention map, and rescales the input point-wise. This highlights signal-rich time regions (e.g. the merger) and suppresses flat noise segments.
- Parameters:
- class ConvBlock(filters_start=32, kernel_start=64, in_channels=1, dropout=0.0)[source]
Bases:
torch.nn.ModuleThree-stage multi-scale 1D CNN frontend with per-stage CBAM attention.
Processes a single detector strain time-series through three cascaded stages, each containing two
ConcatBlockConv5blocks followed by aChannelAttention1DandTemporalAttention1Dgate. Max-pooling between stages achieves dyadic downsampling (÷8, ÷4) before the final stage. The output is unsqueezed to add a channel dimension for downstream 2D or 3D processing.- Parameters:
filters_start (int) – Base number of feature maps in stage 1 (doubled per stage, default
32).kernel_start (int) – Base kernel size for the first
ConcatBlockConv5block (halved per stage, default64).in_channels (int) – Number of input channels (default
1for a single detector).state (Initialize internal Module)
ScriptModule. (shared by both nn.Module and)