模块更新于 2026-11-20· 浏览 0· 下载 0
PWD 参数化小波下采样模块
双分支互补下采样:上分支固定 Haar 小波做频率分解,下分支分组卷积(步长 2、核 2)提取局部对比,通道严格对齐,下采样不丢小目标细节
结构图

双分支互补下采样:上分支固定 Haar 小波做频率分解,下分支分组卷积(步长 2、核 2)提取局部对比,通道严格对齐,下采样不丢小目标细节
论文信息
- 论文:GSFANet: Global Spatial–Frequency Attention Network for Infrared Small Target Detection
- 出处:IEEE TGRS 2025
核心痛点
红外小目标又小又暗、尺寸 1~100+ 像素,下采样稍不留神就把目标“采没了”:最大池化把非极大值的目标边缘当背景吞掉,步长卷积只能学到碎片化表征;Haar 小波基函数写死,Cut-slice 又不感知目标的频率与对比度。而噪声多在高频、目标偏低频,频域分析能把两者的分布差异平均放大 4.63 倍,常规下采样用不上。
模块亮点
- 双分支互补下采样:上分支固定 Haar 小波做频率分解,下分支分组卷积(步长 2、核 2)提取局部对比,通道严格对齐,下采样不丢小目标细节
- 可学习频率选择:全局上下文池化加共享全连接生成通道注意力,自适应加权两路输出,自己学哪种频率最能区分目标与噪声
- 整体模型涨点明确:GSFANet 在 SIRST、NUDT-SIRST 上优于 SOTA,IRSTD-1k 上 IoU 与 F1 显著领先,参数量与 FLOPs 更小,实时(≥30 FPS)
适用场景
领域为红外小目标检测(IRSTD),覆盖海事监控、遥感、精确制导;原文在三个公开数据集上验证;可迁移到语义分割、遥感 / SAR 小目标检测等密集预测任务。
插入位置建议
- 直接替换 U-Net 类编码器的最大池化或步长卷积,原文编码器就是 PWD + ResBlock 堆出多尺度特征
- 替换 Swin 类骨干的 Patch Merging / Cut-slice,通道扩张与 16-32-64-128 逐级翻倍天然对齐
- 放在跳跃连接前与上采样解码配套,逐级保细节;原文三级共 8× 下采样,超过 8× 会显著损失信息
适用任务
- 红外小目标检测
完整代码
pwd.py
import torch.nn as nn
import pywt
import pywt.data
import torch
import torch.nn.functional as F
def create_wavelet_filter(wave, in_size, out_size, type=torch.float):
w = pywt.Wavelet(wave)
dec_hi = torch.tensor(w.dec_hi[::-1], dtype=type)
dec_lo = torch.tensor(w.dec_lo[::-1], dtype=type)
dec_filters = torch.stack([dec_lo.unsqueeze(0) * dec_lo.unsqueeze(1),
dec_lo.unsqueeze(0) * dec_hi.unsqueeze(1),
dec_hi.unsqueeze(0) * dec_lo.unsqueeze(1),
dec_hi.unsqueeze(0) * dec_hi.unsqueeze(1)], dim=0)
dec_filters = dec_filters[:, None].repeat(in_size, 1, 1, 1)
rec_hi = torch.tensor(w.rec_hi[::-1], dtype=type).flip(dims=[0])
rec_lo = torch.tensor(w.rec_lo[::-1], dtype=type).flip(dims=[0])
rec_filters = torch.stack([rec_lo.unsqueeze(0) * rec_lo.unsqueeze(1),
rec_lo.unsqueeze(0) * rec_hi.unsqueeze(1),
rec_hi.unsqueeze(0) * rec_lo.unsqueeze(1),
rec_hi.unsqueeze(0) * rec_hi.unsqueeze(1)], dim=0)
rec_filters = rec_filters[:, None].repeat(out_size, 1, 1, 1)
return dec_filters, rec_filters
def wavelet_transform(x, filters):
b, c, h, w = x.shape
pad = (filters.shape[2] // 2 - 1, filters.shape[3] // 2 - 1)
x = F.conv2d(x, filters, stride=2, groups=c, padding=pad)
x = x.reshape(b, c, 4, h // 2, w // 2)
return x
def inverse_wavelet_transform(x, filters):
b, c, _, _ = x.shape
pad = (filters.shape[2] // 2 - 1, filters.shape[3] // 2 - 1)
# x = x.reshape(b, c * 4, h_half, w_half)
x = F.conv_transpose2d(x, filters, stride=2, groups=c // 4, padding=pad)
return x
class _ScaleModule(nn.Module):
def __init__(self, dims, init_scale=1.0, init_bias=0):
super(_ScaleModule, self).__init__()
self.dims = dims
self.weight = nn.Parameter(torch.ones(*dims) * init_scale, requires_grad=True)
self.bias = None
def forward(self, x):
return torch.mul(self.weight, x)
class ChannelAttention(nn.Module):
def __init__(self, in_planes, ratio=16):
super(ChannelAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, in_planes // 16, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(in_planes // 16, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = avg_out + max_out
return self.sigmoid(out)
class SpatialAttention(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttention, self).__init__()
assert kernel_size in (3, 7), 'kernel size must be 3 or 7'
padding = 3 if kernel_size == 7 else 1
self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
x = torch.cat([avg_out, max_out], dim=1)
x = self.conv1(x)
return self.sigmoid(x)
class PWD2d(nn.Module): # 小波+卷积下采样核
def __init__(self, in_channels, out_channels, wt_type='db1'):
super(PWD2d, self).__init__()
assert in_channels * 4 == out_channels
self.in_channels = in_channels
self.wt_filter, self.iwt_filter = create_wavelet_filter(wt_type, in_channels, in_channels, torch.float)
self.wt_filter = nn.Parameter(self.wt_filter, requires_grad=False)
self.para_conv = nn.Sequential(
nn.Conv2d(in_channels, in_channels * 4, kernel_size=2, stride=2, groups=in_channels),
nn.BatchNorm2d(in_channels * 4),
nn.ReLU()) # 分组2*2卷积
self.ca = ChannelAttention(out_channels)
self.wavelet_scale = _ScaleModule([1, in_channels * 4, 1, 1], init_scale=0.1)
self.conv1x1 = nn.Conv2d(out_channels, in_channels * 2, kernel_size=1, stride=1)
self.bnorm = nn.BatchNorm2d(in_channels * 2)
self.act = nn.ReLU()
def forward(self, x):
curr_x_ll = x
x = self.para_conv(x)
ca = self.ca(x)
x = x * ca
curr_shape = curr_x_ll.shape
if (curr_shape[2] % 2 > 0) or (curr_shape[3] % 2 > 0):
curr_pads = (0, curr_shape[3] % 2, 0, curr_shape[2] % 2)
curr_x_ll = F.pad(curr_x_ll, curr_pads)
curr_x = wavelet_transform(curr_x_ll, self.wt_filter)
shape_x = curr_x.shape
curr_x_wt = curr_x.reshape(shape_x[0], shape_x[1] * 4, shape_x[3], shape_x[4])
curr_x_wt = curr_x_wt * ca
curr_x_wt = self.wavelet_scale(curr_x_wt)
out = x + curr_x_wt
out = self.act(self.bnorm(self.conv1x1(out)))
return out
if __name__ == '__main__':
batch_size = 2
in_channels = 16
out_channels = in_channels * 4
height = 128
width = 128
block = PWD2d(
in_channels=in_channels,
out_channels=out_channels,
wt_type='db1'
).to('cuda')
x = torch.randn(batch_size, in_channels, height, width).to('cuda')
with torch.no_grad():
y = block(x)
print(f"Input shape : {x.shape}")
print(f"Output shape: {y.shape}")环境与依赖
Python 3.9+
继续浏览
下一篇RCF 残差周期预测显式建模周期:为每个通道维护一组长度为 W 的可学习循环周期,按时间索引对齐后从输入中减去,骨干只预测残差,输出端再把周期分量加回来相关资源
模块2026-11-20
FSConv 频率空间卷积
小波分频双路并行:Haar 小波变换把特征拆成低频近似 + 三个高频子带,高频支路用分组卷积和 SE 通道注意力凸显细节,低频支路保全局结构,最后相乘再拼接融合
目标检测红外小目标FSConv
计算机视觉MIT
模块2026-11-20
ARConv 自适应矩形卷积
核形状可学习:把卷积核的高和宽当作可学习参数,每个位置都能长出 5×3 这样的自适应矩形核,随物体大小伸缩,计算开销还不随核增大而上升
计算机视觉遥感全色锐化
计算机视觉MIT
模块2026-11-20
CAFM 交叉注意力融合模块
通道交叉注意力:两路特征分别做全局平均池化和最大池化,过共享两层 MLP(降到 C/r 再升回 C)得通道权重,相乘得 C×C 交叉矩阵,经 Softmax 互相加权,建模两分支通道相关性
遥感高光谱图像CAFM
计算机视觉MIT