模块更新于 2026-11-20· 浏览 1· 下载 0
FCENet FDSM/FEFM 频率动态选择与增强
频域动态选频:依据频率相关性先验,用动态滤波在频域分别筛选两路特征,RGB 留低频颜色、NIR 留中高频纹理
结构图

频域动态选频:依据频率相关性先验,用动态滤波在频域分别筛选两路特征,RGB 留低频颜色、NIR 留中高频纹理
论文信息
- 论文:Complementary Advantages: Exploiting Cross-Field Frequency Correlation for NIR-Assisted Image Denoising
- 出处:arXiv 2024
核心痛点
NIR 辅助 RGB 去噪中,NIR 图像信噪比高、能补细节,但与 RGB 在颜色、亮度和结构上明显不一致:直接融合会混入不一致信息,只保共同特征又会丢掉 NIR 的锐利纹理和 RGB 的真实颜色;传统卷积核全图共享权重,分不清该信哪一路。
模块亮点
- 频域动态选频:依据频率相关性先验,用动态滤波在频域分别筛选两路特征,RGB 留低频颜色、NIR 留中高频纹理
- 消融涨点明确:DVD 数据集(σ=4)上,两阶段 U-Net 基线 29.13 dB,加入 FDSM 提升 0.51 dB 至 29.64 dB;频域比空域动态选择再高 0.26 dB;整体模型 FCENet 达 30.37 dB,超过 DVN、NIR-Restormer 等方法
- 轻量好接入:不生成逐像素动态核,仅由聚合特征经 MLP+Softmax 加权组合 k 个可学习频域滤波基;整体模型仅 4.32 M 参数、19.52 G FLOPs
适用场景
领域为 NIR 辅助 RGB 图像去噪,模拟噪声和真实低光场景均有效;可迁移到引导深度图超分、RGB-NIR 融合、引导去模糊等跨模态引导任务。
插入位置建议
- 双分支引导网络编码器的每个尺度,让 NIR 与 RGB 特征先过 FDSM 筛选再融合
- 替换直接相加或拼接的融合前端,接在交叉注意力、门控融合等模块之前
- 单分支网络可拆用内部 DynamicFilter 当频域动态卷积,替换普通卷积块
适用任务
- NIR 辅助 RGB 图像去噪
- 模拟噪声和真实低光场景均有效
完整代码
fcenet_fdsm.py
import torch
import torch.nn as nn
import torch.nn.functional as F
import numbers
from einops import rearrange
from timm.models.layers import to_2tuple
# Complementary Advantages: Exploiting Cross-Field Frequency Correlation for NIR-Assisted Image Denoising
# 论文:https://arxiv.org/pdf/2412.16645v1
# Github:https://github.com/11679-hub/11679
def to_3d(x):
return rearrange(x, 'b c h w -> b (h w) c')
def to_4d(x, h, w):
return rearrange(x, 'b (h w) c -> b c h w', h=h, w=w)
class BiasFree_LayerNorm(nn.Module):
def __init__(self, normalized_shape):
super(BiasFree_LayerNorm, self).__init__()
if isinstance(normalized_shape, numbers.Integral):
normalized_shape = (normalized_shape,)
normalized_shape = torch.Size(normalized_shape)
assert len(normalized_shape) == 1
self.weight = nn.Parameter(torch.ones(normalized_shape))
self.normalized_shape = normalized_shape
def forward(self, x):
sigma = x.var(-1, keepdim=True, unbiased=False)
return x / torch.sqrt(sigma + 1e-5) * self.weight
class WithBias_LayerNorm(nn.Module):
def __init__(self, normalized_shape):
super(WithBias_LayerNorm, self).__init__()
if isinstance(normalized_shape, numbers.Integral):
normalized_shape = (normalized_shape,)
normalized_shape = torch.Size(normalized_shape)
assert len(normalized_shape) == 1
self.weight = nn.Parameter(torch.ones(normalized_shape))
self.bias = nn.Parameter(torch.zeros(normalized_shape))
self.normalized_shape = normalized_shape
def forward(self, x):
mu = x.mean(-1, keepdim=True)
sigma = x.var(-1, keepdim=True, unbiased=False)
return (x - mu) / torch.sqrt(sigma + 1e-5) * self.weight + self.bias
class LayerNorm(nn.Module):
def __init__(self, dim, LayerNorm_type):
super(LayerNorm, self).__init__()
if LayerNorm_type == 'BiasFree':
self.body = BiasFree_LayerNorm(dim)
else:
self.body = WithBias_LayerNorm(dim)
def forward(self, x):
h, w = x.shape[-2:]
return to_4d(self.body(to_3d(x)), h, w)
class StarReLU(nn.Module):
"""
StarReLU: s * relu(x) ** 2 + b
"""
def __init__(self, scale_value=1.0, bias_value=0.0,
scale_learnable=True, bias_learnable=True,
mode=None, inplace=False):
super().__init__()
self.inplace = inplace
self.relu = nn.ReLU(inplace=inplace)
self.scale = nn.Parameter(scale_value * torch.ones(1),
requires_grad=scale_learnable)
self.bias = nn.Parameter(bias_value * torch.ones(1),
requires_grad=bias_learnable)
def forward(self, x):
return self.scale * self.relu(x) ** 2 + self.bias
def resize_complex_weight(origin_weight, new_h, new_w):
h, w, num_heads = origin_weight.shape[0:3] # size, w, c, 2
origin_weight = origin_weight.reshape(1, h, w, num_heads * 2).permute(0, 3, 1, 2)
new_weight = torch.nn.functional.interpolate(
origin_weight,
size=(new_h, new_w),
mode='bicubic',
align_corners=True
).permute(0, 2, 3, 1).reshape(new_h, new_w, num_heads, 2)
return new_weight
class Mlp(nn.Module):
""" MLP as used in MetaFormer models, eg Transformer, MLP-Mixer, PoolFormer, MetaFormer baslines and related networks.
Mostly copied from timm.
"""
def __init__(self, dim, mlp_ratio=4, out_features=None, act_layer=StarReLU, drop=0.,
bias=False, **kwargs):
super().__init__()
in_features = dim
out_features = out_features or in_features
hidden_features = int(mlp_ratio * in_features)
drop_probs = to_2tuple(drop)
self.fc1 = nn.Linear(in_features, hidden_features, bias=bias)
self.act = act_layer()
self.drop1 = nn.Dropout(drop_probs[0])
self.fc2 = nn.Linear(hidden_features, out_features, bias=bias)
self.drop2 = nn.Dropout(drop_probs[1])
def forward(self, x):
x = self.fc1(x)
x = self.act(x)
x = self.drop1(x)
x = self.fc2(x)
x = self.drop2(x)
return x
class DynamicFilter(nn.Module):
def __init__(self, dim, expansion_ratio=1, reweight_expansion_ratio=.25,
act1_layer=StarReLU, act2_layer=nn.Identity,
bias=False, num_filters=4, size=30, weight_resize=True,
**kwargs):
super().__init__()
size = to_2tuple(size)
# print(size)
self.size = size[0]
self.filter_size = size[1] // 2 + 1
self.num_filters = num_filters
self.dim = dim
self.med_channels = int(expansion_ratio * dim)
self.weight_resize = weight_resize
self.pwconv1 = nn.Linear(dim, self.med_channels, bias=bias)
self.act1 = act1_layer()
self.reweight = Mlp(dim, reweight_expansion_ratio, num_filters * self.med_channels)
self.complex_weights = nn.Parameter(
torch.randn(self.size, self.filter_size, num_filters, 2,
dtype=torch.float32) * 0.02)
self.act2 = act2_layer()
self.pwconv2 = nn.Linear(self.med_channels, dim, bias=bias)
def forward(self, x, y):
B, H, W, _ = x.shape
# print(x.shape,y.shape)
routeing = self.reweight(y.mean(dim=(1, 2))).view(B, self.num_filters,
-1).softmax(dim=1)
x = self.pwconv1(x)
# print(x.shape)
x = self.act1(x)
x = x.to(torch.float32)
# print(x.shape)
x = torch.fft.rfft2(x, dim=(1, 2), norm='ortho')
if self.weight_resize:
complex_weights = resize_complex_weight(self.complex_weights, x.shape[1],
x.shape[2])
complex_weights = torch.view_as_complex(complex_weights.contiguous())
else:
complex_weights = torch.view_as_complex(self.complex_weights)
routeing = routeing.to(torch.complex64)
weight = torch.einsum('bfc,hwf->bhwc', routeing, complex_weights)
if self.weight_resize:
weight = weight.view(-1, x.shape[1], x.shape[2], self.med_channels)
else:
weight = weight.view(-1, self.size, self.filter_size, self.med_channels)
# print(complex_weights.shape,weight.shape)
x = x * weight
x = torch.fft.irfft2(x, s=(H, W), dim=(1, 2), norm='ortho')
x = self.act2(x)
x = self.pwconv2(x)
# plt.close(fig)
return x
class FDSM(nn.Module):
def __init__(self, c):
super().__init__()
self.conv_rgb = nn.Conv2d(c, c, 1, 1, 0, groups=c, bias=False)
self.conv_nir = nn.Conv2d(c, c, 1, 1, 0, groups=c, bias=False)
self.softmax = nn.SiLU()
self.pool = nn.Sequential(nn.Conv2d(c, c, 1, 1, 0, bias=False),
nn.Conv2d(c, c, kernel_size=3, stride=1, padding=1, groups=c, bias=False),
LayerNorm(c, LayerNorm_type='WithBias'),
nn.PReLU())
self.fc_ab = nn.Sequential(
nn.Conv2d(c, c * 2, 1, 1, 0, bias=False))
self.dynamic_rgb = DynamicFilter(c)
self.dynamic_nir = DynamicFilter(c)
def forward(self, rgb, nir):
feat_1 = self.conv_rgb(rgb)
feat_2 = self.conv_nir(nir)
feat_sum = feat_1 + feat_2
s = self.pool(feat_sum)
z = s
ab = self.fc_ab(z)
B, C, H, W = ab.shape
ab = ab.view(B, 2, C // 2, H, W)
ab = self.softmax(ab)
a = ab[:, 0, ...]
b = ab[:, 1, ...]
feat_1 = self.dynamic_rgb(feat_1.permute(0, 2, 3, 1), a.permute(0, 2, 3, 1))
feat_2 = self.dynamic_nir(feat_2.permute(0, 2, 3, 1), b.permute(0, 2, 3, 1))
return feat_1.permute(0, 3, 1, 2), feat_2.permute(0, 3, 1, 2)
# 输入 B C H W, 输出B C H W
if __name__ == '__main__':
block = FDSM(c=64).cuda()
x_0 = torch.randn((3, 64, 128, 128)).cuda()
x_1 = torch.randn((3, 64, 128, 128)).cuda()
output_0, output_1 = block(x_0, x_1)
print(x_0.size(), x_1.size(), output_0.size(), output_1.size())
fcenet_fefm.py
import torch
import torch.nn as nn
import torch.nn.functional as F
import numbers
import torch_dct as dct
from einops import rearrange
import math
# Complementary Advantages: Exploiting Cross-Field Frequency Correlation for NIR-Assisted Image Denoising
# 论文:https://arxiv.org/pdf/2412.16645v1
# Github:https://github.com/11679-hub/11679
def to_3d(x):
return rearrange(x, 'b c h w -> b (h w) c')
def to_4d(x, h, w):
return rearrange(x, 'b (h w) c -> b c h w', h=h, w=w)
class BiasFree_LayerNorm(nn.Module):
def __init__(self, normalized_shape):
super(BiasFree_LayerNorm, self).__init__()
if isinstance(normalized_shape, numbers.Integral):
normalized_shape = (normalized_shape,)
normalized_shape = torch.Size(normalized_shape)
assert len(normalized_shape) == 1
self.weight = nn.Parameter(torch.ones(normalized_shape))
self.normalized_shape = normalized_shape
def forward(self, x):
sigma = x.var(-1, keepdim=True, unbiased=False)
return x / torch.sqrt(sigma + 1e-5) * self.weight
class WithBias_LayerNorm(nn.Module):
def __init__(self, normalized_shape):
super(WithBias_LayerNorm, self).__init__()
if isinstance(normalized_shape, numbers.Integral):
normalized_shape = (normalized_shape,)
normalized_shape = torch.Size(normalized_shape)
assert len(normalized_shape) == 1
self.weight = nn.Parameter(torch.ones(normalized_shape))
self.bias = nn.Parameter(torch.zeros(normalized_shape))
self.normalized_shape = normalized_shape
def forward(self, x):
mu = x.mean(-1, keepdim=True)
sigma = x.var(-1, keepdim=True, unbiased=False)
return (x - mu) / torch.sqrt(sigma + 1e-5) * self.weight + self.bias
class LayerNorm(nn.Module):
def __init__(self, dim, LayerNorm_type):
super(LayerNorm, self).__init__()
if LayerNorm_type == 'BiasFree':
self.body = BiasFree_LayerNorm(dim)
else:
self.body = WithBias_LayerNorm(dim)
def forward(self, x):
h, w = x.shape[-2:]
return to_4d(self.body(to_3d(x)), h, w)
def lambda_init_fn(depth):
return 0.8 - 0.6 * math.exp(-0.3 * depth)
class FEFM(nn.Module):
def __init__(self, dim, bias, depth):
super(FEFM, self).__init__()
self.num_heads = dim // 16
# print(depth)
self.lambda_init = lambda_init_fn(depth)
self.lambda_q1 = nn.Parameter(torch.zeros(dim, dtype=torch.float32).normal_(mean=0, std=0.1))
self.lambda_k1 = nn.Parameter(torch.zeros(dim, dtype=torch.float32).normal_(mean=0, std=0.1))
self.lambda_q2 = nn.Parameter(torch.zeros(dim, dtype=torch.float32).normal_(mean=0, std=0.1))
self.lambda_k2 = nn.Parameter(torch.zeros(dim, dtype=torch.float32).normal_(mean=0, std=0.1))
self.to_hidden = nn.Conv2d(dim, dim, kernel_size=1, bias=bias)
self.to_hidden_nir = nn.Conv2d(dim, dim * 2, kernel_size=1, bias=bias)
self.to_hidden_dw_nir = nn.Conv2d(dim * 2, dim * 2, kernel_size=3, stride=1, padding=1, groups=dim * 2,
bias=bias)
self.to_hidden_dw = nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1, groups=dim, bias=bias)
self.special = nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1, groups=dim, bias=bias)
self.temperature = nn.Parameter(torch.ones(self.num_heads, 1, 1))
self.project_out = nn.Conv2d(dim, dim, kernel_size=1, bias=bias)
self.project_middle = nn.Conv2d(dim, dim, kernel_size=1, bias=bias)
self.pool1 = nn.Sequential(
nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1, groups=dim, bias=False),
nn.PReLU(),
nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1, groups=dim, bias=False))
self.pool2 = nn.Sequential(
nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1, groups=dim, bias=False),
nn.PReLU(),
nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=1, groups=dim, bias=False))
self.norm = LayerNorm(dim, LayerNorm_type='WithBias')
self.patch_size = 8
def forward(self, x, nir):
b, c, h, w = x.shape
hidden = self.to_hidden(x)
nir_hidden = self.to_hidden_nir(nir)
q = self.to_hidden_dw(hidden)
k, v = self.to_hidden_dw_nir(nir_hidden).chunk(2, dim=1)
# print(q.shape,k.shape)
q_patch = rearrange(q, 'b c (h patch1) (w patch2) -> b c h w patch1 patch2', patch1=self.patch_size,
patch2=self.patch_size)
k_patch = rearrange(k, 'b c (h patch1) (w patch2) -> b c h w patch1 patch2', patch1=self.patch_size,
patch2=self.patch_size)
q_fft = dct.dct_2d(q_patch.float())
k_fft = dct.dct_2d(k_patch.float())
# print(q_fft.shape)
out1 = q_fft * k_fft
# print(out1.shape)
q_fft = rearrange(q_fft, 'b (head c) h w patch1 patch2-> b head c (h w patch1 patch2)', head=self.num_heads)
k_fft = rearrange(k_fft, 'b (head c) h w patch1 patch2-> b head c (h w patch1 patch2)', head=self.num_heads)
out1 = rearrange(out1, 'b (head c) h w patch1 patch2-> b head c (h w patch1 patch2)', head=self.num_heads)
q_fft = torch.nn.functional.normalize(q_fft, dim=-1)
k_fft = torch.nn.functional.normalize(k_fft, dim=-1)
attn = (q_fft @ k_fft.transpose(-2, -1)) * self.temperature
# print(attn.shape)
# attn=attn.real
# print(attn.shape)
attn = attn.softmax(dim=-1)
out = (attn @ out1)
# print(out.shape)
out = rearrange(out, 'b head c (h w patch1 patch2) -> b (head c) h w patch1 patch2', head=self.num_heads,
h=h // self.patch_size, w=w // self.patch_size, patch1=self.patch_size,
patch2=self.patch_size)
out = dct.idct_2d(out)
out = rearrange(out, 'b c h w patch1 patch2 -> b c (h patch1) (w patch2)', patch1=self.patch_size,
patch2=self.patch_size)
out = self.project_middle(out)
# out = self.norm(out)
lambda_1 = torch.exp(torch.sum(self.lambda_q1 * self.lambda_k1, dim=-1).float()).type_as(q)
lambda_2 = torch.exp(torch.sum(self.lambda_q2 * self.lambda_k2, dim=-1).float()).type_as(q)
lambda_full = lambda_1 - lambda_2 + self.lambda_init
# print(lambda_full)
output = self.pool1(q * out) + self.pool2(v - lambda_full * (v * out))
output = self.project_out(output)
return output
# 输入 B C H W, 输出B C H W
if __name__ == '__main__':
block = FEFM(dim=64, bias=False, depth=1).cuda()
x_0 = torch.randn((3, 64, 128, 128)).cuda()
x_1 = torch.randn((3, 64, 128, 128)).cuda()
output = block(x_0, x_1)
print(x_0.size(), x_1.size(), output.size())
环境与依赖
Python 3.9+
继续浏览
下一篇FCR 频域对比正则化把对比搬进频域:不用 VGG,锚点(网络输出)、正样本(GT)、负样本(雨图)统一做二维 DFT,在频域量 L1 距离、取"锚-正 / 锚-负"的比值当损失;雨纹在频域与内容解耦,正负样本天然分开相关资源
模块2026-11-20
FFCM 融合傅里叶卷积混合器
空频双域融合:基于快速傅里叶卷积(FFC)改造,用 3×3 / 5×5 深度卷积提局部特征,再经 DFT 拆实部虚部、1×1 卷积在频谱上可学习调制,IDFT 回空间域残差融合,一个混合器同时拿到局部 + 全局特征
计算机视觉图像复原FFCM
计算机视觉MIT
模块2026-11-20
UFFC 无偏快速傅里叶卷积
矫正频域操作:用可学习的 3×3 范围变换/逆变换包住激活函数,缓解频谱偏移;拼接绝对位置嵌入区分频段、扩大频率感受野;动态跳跃连接以 λ∈(0,1) 保底
计算机视觉图像修复UFFC
计算机视觉MIT
模块2026-11-20
WConv 加权卷积
位置感知加权:把空间密度函数 Φ 逐元素乘进卷积核(WΦ = Φ ∘ W),按相对位置差异化缩放邻居像素的贡献;Φ 取全 1 时严格退化为标准卷积
计算机视觉WConv加权卷积
计算机视觉MIT