RGB to Infrared CycleGAN

将可见光(RGB)图像转换为红外(Infrared)风格的 CycleGAN 模型。

##模型描述

本模型基于CycleGAN 架构训练,可以将普通的 RGB 图像转换为伪红外风格图像。适用于数据集扩充、跨模态训练、风格迁移等场景。

栀本

  • 开发者: chunxue-dev2026
  • 模型类型: 图像风格迁移(CycleGAN)
  • 框架: PyTorch
  • 许可证: MIT

##使用方法

安装依赖

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"
)

模型结构

  • 架构: ResNet-based Generator with 9 residual blocks
  • 输入: 3通道 RGB 图像
  • 输出: 3通道伪红外图像
  • 参数量: ~11M

训练详情

参数
训练轮数 100 epochs
图像尺寸 256x256
批大小 2
学习率 0.0002
损失函数 LSGAN + L1 Cycle Loss

效果展示

输入(RGB) 输出(伪红外)
RGB图像 红外风格图像

##局限性

  • 转换后的图像是"伪红外",并非真实的红外成像
  • 对于训练数据中未出现的场景,效果可能不佳
  • 图像尺寸建议使用 256x256,其他尺寸需要调整

引用

如果使用本模型,请引用:

@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 许可证发布。

致谢

Downloads last month
232
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Paper for chunxue-dev2026/rgb2infrared