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

Conv1dSame

1D convolution with padding="same" semantics (output length == input length).

ConcatBlockConv5

Inception-style multi-scale 1D convolution block with five parallel paths.

ChannelAttention1D

1D CBAM channel-attention gate.

TemporalAttention1D

1D CBAM temporal (spatial) attention gate.

ConvBlock

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.Conv1d

1D convolution with padding="same" semantics (output length == input length).

Thin subclass of torch.nn.Conv1d that hard-codes padding="same" so callers do not need to compute padding manually. Accepts all standard nn.Conv1d arguments except padding.

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.Module

Inception-style multi-scale 1D convolution block with five parallel paths.

Runs five Conv1dSame branches at kernel sizes k, 2k, k/2, k/4, and 4k in 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 use k, 2k, k//2, k//4, 4k.

  • stride (int) – Convolution stride (default 1).

  • padding (int) – Ignored — Conv1dSame handles 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)

c1[source]
c2[source]
c3[source]
c4[source]
c5[source]
c6[source]
forward(x)[source]
class ChannelAttention1D(in_channels, reduction=16)[source]

Bases: torch.nn.Module

1D 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:
  • in_channels (int) – Number of input channels.

  • reduction (int) – Bottleneck reduction ratio for the FC layers (default 16).

  • state (Initialize internal Module)

  • ScriptModule. (shared by both nn.Module and)

avg_pool[source]
max_pool[source]
fc[source]
sigmoid[source]
forward(x)[source]
class TemporalAttention1D(in_channels, kernel_size=7)[source]

Bases: torch.nn.Module

1D 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:
  • in_channels (int) – Number of input channels (used for context; the conv operates on 2 channels after the channel-wise reduction).

  • kernel_size (int) – Temporal kernel size for the attention convolution (default 7).

  • state (Initialize internal Module)

  • ScriptModule. (shared by both nn.Module and)

conv[source]
sigmoid[source]
forward(x)[source]
class ConvBlock(filters_start=32, kernel_start=64, in_channels=1, dropout=0.0)[source]

Bases: torch.nn.Module

Three-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 ConcatBlockConv5 blocks followed by a ChannelAttention1D and TemporalAttention1D gate. 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 ConcatBlockConv5 block (halved per stage, default 64).

  • in_channels (int) – Number of input channels (default 1 for a single detector).

  • state (Initialize internal Module)

  • ScriptModule. (shared by both nn.Module and)

drop1[source]
drop2[source]
drop3[source]
conv1[source]
ca1[source]
ta1[source]
conv2[source]
ca2[source]
ta2[source]
conv3[source]
ca3[source]
ta3[source]
forward(x)[source]