🚀 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}
}