🚀 OmniGen:統一圖像生成
OmniGen是一個統一的圖像生成模型,可根據多模態提示生成各種圖像。它設計簡單、靈活且易用,能直接通過任意多模態指令生成圖像,無需額外插件和操作。
🚀 快速開始
使用OmniGen
通過Github安裝:
git clone https://github.com/staoxiao/OmniGen.git
cd OmniGen
pip install -e .
你也可以創建一個新環境以避免衝突:
conda create -n omnigen python=3.10.12
conda activate omnigen
pip install torch==2.3.1+cu118 torchvision --extra-index-url https://download.pytorch.org/whl/cu118
git clone https://github.com/staoxiao/OmniGen.git
cd OmniGen
pip install -e .
以下是一些使用示例:
from OmniGen import OmniGenPipeline
pipe = OmniGenPipeline.from_pretrained("Shitao/OmniGen-v1")
images = pipe(
prompt="A curly-haired man in a red shirt is drinking tea.",
height=1024,
width=1024,
guidance_scale=2.5,
seed=0,
)
images[0].save("example_t2i.png")
images = pipe(
prompt="A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
input_images=["./imgs/test_cases/two_man.jpg"],
height=1024,
width=1024,
guidance_scale=2.5,
img_guidance_scale=1.6,
seed=0
)
images[0].save("example_ti2i.png")
使用Diffusers
即將推出。
Gradio演示
我們在 Huggingface 上構建了一個在線演示。
對於本地Gradio演示,你需要安裝 pip install gradio spaces
,然後可以運行:
pip install gradio spaces
python app.py
使用Google Colab
要在Google Colab中使用,請使用以下命令:
!git clone https://github.com/staoxiao/OmniGen.git
%cd OmniGen
!pip install -e .
!pip install gradio spaces
!python app.py --share
✨ 主要特性
- 統一生成:能夠根據多模態提示生成各種圖像,涵蓋文本到圖像、主題驅動生成、身份保留生成、圖像編輯和圖像條件生成等多種任務。
- 無需額外插件:可自動根據文本提示識別輸入圖像中的特徵,無需額外的插件或操作。
- 靈活可控:用戶可以通過調整參數靈活控制圖像生成過程。
- 易於微調:提供訓練腳本,方便用戶根據自己的需求對模型進行微調。
📦 安裝指南
通過Github安裝
git clone https://github.com/staoxiao/OmniGen.git
cd OmniGen
pip install -e .
創建新環境安裝
conda create -n omnigen python=3.10.12
conda activate omnigen
pip install torch==2.3.1+cu118 torchvision --extra-index-url https://download.pytorch.org/whl/cu118
git clone https://github.com/staoxiao/OmniGen.git
cd OmniGen
pip install -e .
💻 使用示例
基礎用法
from OmniGen import OmniGenPipeline
pipe = OmniGenPipeline.from_pretrained("Shitao/OmniGen-v1")
images = pipe(
prompt="A curly-haired man in a red shirt is drinking tea.",
height=1024,
width=1024,
guidance_scale=2.5,
seed=0,
)
images[0].save("example_t2i.png")
高級用法
images = pipe(
prompt="A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
input_images=["./imgs/test_cases/two_man.jpg"],
height=1024,
width=1024,
guidance_scale=2.5,
img_guidance_scale=1.6,
seed=0
)
images[0].save("example_ti2i.png")
📚 詳細文檔
推理代碼
模型功能
OmniGen是一個統一的圖像生成模型,可用於執行各種任務,包括但不限於文本到圖像生成、主題驅動生成、身份保留生成、圖像編輯和圖像條件生成。我們在 inference.ipynb 中展示了一些示例,並在 inference_demo.ipynb 中展示了一個有趣的圖像生成和修改流程。
微調
我們提供了一個訓練腳本 train.py
來對OmniGen進行微調。以下是一個LoRA微調的示例:
accelerate launch --num_processes=1 train.py \
--model_name_or_path Shitao/OmniGen-v1 \
--batch_size_per_device 2 \
--condition_dropout_prob 0.01 \
--lr 1e-3 \
--use_lora \
--lora_rank 8 \
--json_file ./toy_data/toy_subject_data.jsonl \
--image_path ./toy_data/images \
--max_input_length_limit 18000 \
--keep_raw_resolution \
--max_image_size 1024 \
--gradient_accumulation_steps 1 \
--ckpt_every 10 \
--epochs 200 \
--log_every 1 \
--results_dir ./results/toy_finetune_lora
請參考 docs/fine-tuning.md 瞭解更多詳細信息(例如全量微調)。
🔧 技術細節
你可以在我們的 論文 中查看詳細信息。
📄 許可證
本倉庫遵循 MIT許可證。
引用
如果你發現這個倉庫有用,請考慮給它一個星 ⭐ 並引用:
@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}
}
貢獻者
感謝所有貢獻者的努力,熱烈歡迎新成員加入!
更多信息請參考我們的倉庫:https://github.com/VectorSpaceLab/OmniGen
新聞 |
方法論 |
功能 |
快速開始 |
微調 |
許可證 |
引用