基于深度学习的图像增强-zeros-DCE模型源码分享
·
Zeros-DCE模型概述
Zero-Reference Deep Curve Estimation (Zero-DCE) 是一种基于深度学习的低光图像增强方法,无需配对训练数据。该模型通过学习一系列像素级曲线调整图像,适用于动态范围调整、噪声抑制等任务。核心思想是利用轻量级网络生成图像对应的增强曲线,通过无参考损失函数优化。
源码获取方式
-
官方GitHub仓库
原始论文作者团队在GitHub开源了代码,地址通常为:https://github.com/Li-Chongyi/Zero-DCE
包含PyTorch实现、预训练模型及测试脚本。 -
第三方复现版本
搜索关键词Zero-DCE TensorFlow/Keras可找到其他框架实现,例如:- TensorFlow版本:
https://github.com/tensorflow/models(社区贡献) - Keras版本:部分开发者会提供简化实现。
- TensorFlow版本:
关键代码解析
以下为PyTorch实现的核心代码片段:
网络结构定义
class DCE_net(nn.Module):
def __init__(self):
super(DCE_net, self).__init__()
self.conv1 = nn.Conv2d(3, 32, 3, padding=1)
self.conv2 = nn.Conv2d(32, 64, 3, padding=1)
self.conv3 = nn.Conv2d(64, 128, 3, padding=1)
self.conv4 = nn.Conv2d(128, 3, 3, padding=1, activation_fn=None)
self.relu = nn.ReLU()
def forward(self, x):
x = self.relu(self.conv1(x))
x = self.relu(self.conv2(x))
x = self.relu(self.conv3(x))
x = self.conv4(x)
return x
曲线调整公式
模型输出为调整曲线的参数,图像增强通过公式实现:
$$ I_{enhanced} = I_{input} + \alpha \cdot I_{input} \cdot (1 - I_{input}) $$
其中 $\alpha$ 为网络预测的像素级参数。
训练与部署
-
数据准备
使用无配对低光图像数据集(如LOL、SICE),或自定义数据。 -
损失函数
包含空间一致性损失、曝光控制损失等:def spatial_constraint_loss(enhanced, original): return torch.mean(torch.abs(enhanced - original)) -
部署示例
加载预训练模型进行推理:model = DCE_net() model.load_state_dict(torch.load('zero_dce.pth')) enhanced_image = model(low_light_image)
常见问题
- 训练不收敛:调整学习率或增加损失函数的权重平衡。
- 过增强现象:限制曲线参数的取值范围(如0到1)。
- 硬件要求:模型轻量,可在消费级GPU(如GTX 1060)上运行。
扩展阅读
- 论文:《Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement》
- 改进模型:Zero-DCE++(优化计算效率)或UDC(联合去噪与增强)。
注:实际使用时建议参考官方仓库的最新代码和文档。
更多推荐
所有评论(0)