Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks
Paper • 1703.10593 • Published • 2
将可见光(RGB)图像转换为红外(Infrared)风格的 CycleGAN 模型。
##模型描述
本模型基于CycleGAN 架构训练,可以将普通的 RGB 图像转换为伪红外风格图像。适用于数据集扩充、跨模态训练、风格迁移等场景。
##使用方法
pip install torch torchvision pillow
import torch
from PIL import Image
from torchvision import transforms
# 加载模型(需要先定义 Generator 类,见 inference.py)
from inference import Generator
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = Generator(n_residual=9).to(device)
model.load_state_dict(torch.load("G_AB_final.pth", map_location=device))
model.eval()
# 图像预处理
transform = transforms.Compose([
transforms.Resize(256),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
# 加载并转换图像
img = Image.open("input.jpg").convert("RGB")
input_tensor = transform(img).unsqueeze(0).to(device)
# 推理
with torch.no_grad():
output_tensor = model(input_tensor)
# 保存结果
output_img = output_tensor[0] * 0.5 + 0.5
transforms.ToPILImage()(output_img).save("output_ir.jpg")
from inference import batch_convert
batch_convert(
input_dir="path/to/rgb/images",
output_dir="path/to/output",
model_path="G_AB_final.pth"
)
| 参数 | 值 |
|---|---|
| 训练轮数 | 100 epochs |
| 图像尺寸 | 256x256 |
| 批大小 | 2 |
| 学习率 | 0.0002 |
| 损失函数 | LSGAN + L1 Cycle Loss |
| 输入(RGB) | 输出(伪红外) |
|---|---|
| RGB图像 | 红外风格图像 |
##局限性
如果使用本模型,请引用:
@misc{rgb2infrared-cyclegan,
title={RGB to Infrared CycleGAN},
author={Your Name},
year={2026},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/chunxue-dev2026/rgb2infrared}}
}
本模型采用 MIT 许可证发布。