🚀 OmniGen2
OmniGen2 是一个强大且高效的统一多模态模型。它由 3B 视觉语言模型(VLM)和 4B 扩散模型两大关键组件构成,能在视觉理解、文本到图像生成、指令引导的图像编辑和上下文生成等四个主要能力上展现出色性能,为探索可控和个性化生成式 AI 的研究人员和开发者提供了强大且资源高效的基础。
✨ 主要特性
- 视觉理解:继承了 Qwen-VL-2.5 强大的图像内容解释和分析能力。
- 文本到图像生成:根据文本提示创建高保真且美观的图像。
- 指令引导的图像编辑:高精度执行基于指令的复杂图像修改,在开源模型中达到了最先进的性能。
- 上下文生成:能够处理和灵活组合各种输入,包括任务、参考对象和场景,以生成新颖且连贯的视觉输出。
📦 安装指南
环境搭建
推荐设置
git clone git@github.com:VectorSpaceLab/OmniGen2.git
cd OmniGen2
conda create -n omnigen2 python=3.11
conda activate omnigen2
pip install torch==2.6.0 torchvision --extra-index-url https://download.pytorch.org/whl/cu124
pip install -r requirements.txt
pip install flash-attn --no-build-isolation
中国大陆用户
pip install torch==2.6.0 torchvision --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu124
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install flash-attn --no-build-isolation -i https://pypi.tuna.tsinghua.edu.cn/simple
运行示例
bash example_understanding.sh
bash example_t2i.sh
bash example_edit.sh
bash example_subject_driven_edit.sh
Gradio 演示
pip install gradio
python app.py
python app.py --share
💻 使用示例
基础用法
要在不同场景下使用 OmniGen2 达到最佳效果,可根据具体用例调整以下关键超参数:
num_inference_step = 30
text_guidance_scale = 5
image_guidance_scale = 1.8
max_input_image_pixels = 1000000
negative_prompt = "blurry, low quality, text, watermark"
高级用法
在实际应用中,根据不同的任务需求,可以更灵活地组合和调整这些超参数:
num_inference_step = 40
text_guidance_scale = 4
image_guidance_scale = 1.6
negative_prompt = "ugly, distorted"
num_inference_step = 35
text_guidance_scale = 4.5
image_guidance_scale = 1.5
negative_prompt = "noise, artifacts"
num_inference_step = 45
text_guidance_scale = 5
image_guidance_scale = 2.8
negative_prompt = "missing details"
📚 详细文档
新闻
TODO
- [ ] 技术报告。
- [ ] 上下文生成基准测试:OmniContext。
- [ ] 支持 CPU 卸载并提高推理效率。
- [ ] 训练数据和脚本。
- [ ] 数据构建管道。
- [ ] ComfyUI 演示(非常感谢社区支持!)
使用提示
为了使用 OmniGen2 获得最佳效果,您可以根据具体用例调整以下关键超参数:
num_inference_step
:每次生成的采样步数。值越高,通常质量越好,但生成时间会增加。
text_guidance_scale
:控制输出与文本提示的匹配程度(无分类器引导)。
- 对于文本到图像:简单或细节较少的提示使用较高值(如 6 - 7),复杂且细节丰富的提示使用较低值(如 4)。
- 对于编辑/合成:建议使用 4 - 5 左右的适中值。
image_guidance_scale
:控制最终图像与输入参考图像的相似程度。
- 权衡:较高的值(~2.0)使输出更忠实于参考图像的结构和风格,但可能会忽略部分文本提示;较低的值(~1.5)使文本提示更具影响力。
- 提示:从 1.5 开始,如果需要与参考图像更一致,可增加该值。对于图像编辑任务,建议设置在 1.3 到 2.0 之间;对于上下文生成任务,较高的
image_guidance_scale
会保留输入图像的更多细节,建议设置在 2.5 到 3.0 之间。
max_input_image_pixels
:为了管理处理速度和内存消耗,超过此总像素数的参考图像将自动调整大小。
negative_prompt
:告诉模型您不想在图像中看到的内容。
- 示例:模糊、低质量、文本、水印
- 提示:为了获得最佳效果,尝试不同的负提示。如果不确定,留空即可。
📄 许可证
本项目采用 Apache 2.0 许可证。
:heart: 引用我们
如果您发现这个仓库或我们的工作很有用,请考虑给个星星 :star: 并引用我们,非常感谢(OmniGen2 报告将尽快发布):
@article{xiao2024omnigen,
title={Omnigen: Unified image generation},
author={Xiao, Shitao and Wang, Yueze and Zhou, Junjie and Yuan, Huaying and Xing, Xingrun and Yan, Ruiran and Wang, Shuting and Huang, Tiejun and Liu, Zheng},
journal={arXiv preprint arXiv:2409.11340},
year={2024}
}