Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,20 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
data/
datasets/
__pycache__/
*.pth
*.jpg
*.png

ckpt/
checkpoints/
*.pth
*.pt
*.ckpt
*.safetensors

/AdaIR
/AdaIR_results

103 changes: 0 additions & 103 deletions README.md

This file was deleted.

107 changes: 107 additions & 0 deletions et --hard
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
commit fc652196fb3870738bcae1a9214d09190f934e2a (HEAD -> cursor-adir, origin/cursor-adir)
Author: Harry-yyq <1724017964@qq.com>
Date: Fri Feb 20 15:49:43 2026 +0800

0202备份 准备重构adair代码

commit ccb8b98e49614e07badd0641e5163fa7635c2f02 (origin/main, origin/HEAD, main, adair-uie)
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Wed Dec 24 16:40:53 2025 +0800

Update README

commit 211cd11813e0513b951f4860ec0e21220319c1d3
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Tue Dec 23 23:03:43 2025 +0800

Add hyperlink to BioIR project in README

commit 23725b7b50106cd7a08b7dc6371992e992c6fa45
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Tue Dec 23 23:02:57 2025 +0800

Update README

commit ab14c4b960e3fa7000eabd6ec102eee49fd24488
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Wed May 7 21:58:36 2025 +0200

Update README.md

commit 7edc41b768c1a8df3567ae9f9e8948293fc23f48
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Sun Mar 2 09:33:35 2025 +0100

Update README.md

commit 50a85577452bd5ef461bdf2da44b61b034ffd45f
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Sun Mar 2 09:32:30 2025 +0100

Update README.md

commit 67cdc58e29f9a59064fe32132363cdff016b69c1
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Wed Jan 22 19:04:24 2025 +0100

Update README.md

commit d46fb475af26b6eb8177079a458c1cb9c67dbbaa
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Thu Apr 25 13:56:16 2024 +0400

Update README.md

commit 69e13fbdaa6dc5312c084adbca97a92caa6efc0f
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Fri Mar 22 17:34:35 2024 +0400

Update README.md

commit c7b3ff2d701295bc591ff5351567a7c3b9d5e9a3
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Fri Mar 22 14:31:08 2024 +0400

Update README.md

commit 6986022a6b2c18c49e216253c87de70e1437c249
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Fri Mar 22 11:52:54 2024 +0400

Update model.py

commit 50f8cafe8841915ccbf23bdae6bf90e14b1b92d4
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Fri Mar 22 08:40:15 2024 +0400

Update README.md

commit 4dd73536168f0b90142d5fd0c2081e4aa9fa3d0c
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Fri Mar 22 08:32:41 2024 +0400

Update README.md

commit dab504eec37fc609fda8a2f8ed7d2714e14f2dcb
Author: Yuning Cui <cuiyuning16@gmail.com>
Date: Wed Mar 20 14:17:41 2024 +0400

Code Release

commit c9e7c96e7d8c880237b4c3e4da1bb78ef650dce8
Author: Yuning Cui <cuiyuning16@gmail.com>
Date: Wed Mar 20 03:23:15 2024 +0400

Update README.md

commit 9c86ec24bafb9948089c30d0cc9c324903f029fe
Author: Yuning Cui <cuiyuning16@gmail.com>
Date: Wed Mar 20 03:18:24 2024 +0400

Code Release

commit ab6eca623351e0dbe334feb3603944d2114d7d88
Author: Yuning Cui <94985227+c-yn@users.noreply.github.com>
Date: Tue Mar 19 22:11:52 2024 +0400

Initial commit
67 changes: 63 additions & 4 deletions net/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,55 @@ def fft(self, x, n=128):
return high, low


##########################################################################
## 频域色彩提亮模块 (FFT-based Color Block) — DarkIR 风格:仅修振幅、相位不变
## 插入 Encoder 最深层(Bottleneck),用于水下等场景的全局亮度/色彩校正
class FrequencyColorEnhanceBlock(nn.Module):
"""在频域内仅对振幅进行缩放与特征变换,相位绝对保持不变,再逆变换回空域。"""

def __init__(self, dim, use_instruction=False, instruction_dim=None):
super().__init__()
self.dim = dim
self.use_instruction = use_instruction
# 仅对振幅做缩放的小型卷积网络(代表亮度和全局色彩调整)
self.amp_net = nn.Sequential(
nn.Conv2d(dim, max(dim // 4, 1), kernel_size=1),
nn.GELU(),
nn.Conv2d(max(dim // 4, 1), dim, kernel_size=1),
nn.Sigmoid(),
)
# 缩放因子范围 [0.5, 1.5],避免振幅爆炸
self.amp_scale_bias = 0.5
self.amp_scale_range = 1.0

def forward(self, x, instruction=None):
"""
x: (B, C, H, W) 编码器 Bottleneck 特征
instruction: 可选,与 AdaIR Instruction 结合时传入
"""
# ---------- 防 NaN:AMP 混合精度下 FFT/IFFT 强制 float32 ----------
orig_dtype = x.dtype
x = x.float()

# 实部 FFT,输出形状 (B, C, H, W//2+1) 复数
fft = torch.fft.rfft2(x, norm="ortho")
# 振幅与相位解耦
amplitude = torch.abs(fft)
phase = torch.angle(fft)
# 防止振幅为 0 时梯度异常,做数值稳定
amplitude = amplitude.clamp(min=1e-8)

# 仅修振幅:小型网络输出 [0,1],映射到缩放因子
scale = self.amp_net(amplitude) * self.amp_scale_range + self.amp_scale_bias
amplitude_new = amplitude * scale

# 绝对保护相位:用新振幅 + 原相位重构复数
fft_new = amplitude_new * torch.exp(1j * phase)
out = torch.fft.irfft2(fft_new, s=(x.size(-2), x.size(-1)), norm="ortho")

return out.to(orig_dtype)


##########################################################################
##---------- AdaIR -----------------------

Expand Down Expand Up @@ -405,7 +454,10 @@ def __init__(self,

self.down3_4 = Downsample(int(dim*2**2)) ## From Level 3 to Level 4
self.latent = nn.Sequential(*[TransformerBlock(dim=int(dim*2**3), num_heads=heads[3], ffn_expansion_factor=ffn_expansion_factor, bias=bias, LayerNorm_type=LayerNorm_type) for i in range(num_blocks[3])])

# Encoder 最深层:频域色彩提亮 + 辅助色彩输出(DarkIR 解耦:频域修色)
self.freq_color_block = FrequencyColorEnhanceBlock(int(dim*2**3))
self.color_head = nn.Conv2d(int(dim*2**3), 3, kernel_size=1, bias=bias)

self.up4_3 = Upsample(int(dim*2**3)) ## From Level 4 to Level 3
self.reduce_chan_level3 = nn.Conv2d(int(dim*2**3), int(dim*2**2), kernel_size=1, bias=bias)

Expand Down Expand Up @@ -437,8 +489,13 @@ def forward(self, inp_img,noise_emb = None):

out_enc_level3 = self.encoder_level3(inp_enc_level3)

inp_enc_level4 = self.down3_4(out_enc_level3)
latent = self.latent(inp_enc_level4)
inp_enc_level4 = self.down3_4(out_enc_level3)
latent = self.latent(inp_enc_level4)
# 频域色彩提亮(仅改振幅、相位不变)
latent = self.freq_color_block(latent)
# 辅助色彩输出:低分辨率 RGB,用于非对称监督 loss_color
I_low_res = self.color_head(latent)
I_low_res = torch.sigmoid(I_low_res)

if self.decoder:
latent = self.fre1(inp_img, latent)
Expand Down Expand Up @@ -470,6 +527,8 @@ def forward(self, inp_img,noise_emb = None):
out_dec_level1 = self.refinement(out_dec_level1)

out_dec_level1 = self.output(out_dec_level1) + inp_img
I_restored = out_dec_level1

return out_dec_level1
# latent 用于训练时记录 instruction_std,防止模式崩溃
return I_restored, I_low_res, latent

Loading