IP Adapter
1.0.0
我們提出IP-ADAPTER,這是一種有效且輕巧的適配器,可為預訓練的文本對圖像擴散模型實現圖像及時的能力。只有2200萬參數的IP-適配器可以與微調圖像提示模型實現可比甚至更好的性能。 IP-ADAPTER不僅可以從同一基本模型中進行微調的其他自定義模型進行概括,還可以使用現有可控工具來控制可控生成。此外,圖像提示也可以與文本提示符效果很好,以完成多模式圖像生成。
# install latest diffusers
pip install diffusers==0.22.1
# install ip-adapter
pip install git+https://github.com/tencent-ailab/IP-Adapter.git
# download the models
cd IP-Adapter
git lfs install
git clone https://huggingface.co/h94/IP-Adapter
mv IP-Adapter/models models
mv IP-Adapter/sdxl_models sdxl_models
# then you can use the notebook
您可以從這裡下載模型。要運行演示,您還應該下載以下模型:
最佳實踐
scale=1.0
和text_prompt=""
(或某些通用文本提示,例如“最佳質量”,也可以使用任何負面文本提示)。如果您降低了scale
,則可以生成更多樣化的圖像,但它們可能與圖像提示不像。scale
以獲得最佳結果。在大多數情況下,設置scale=0.5
可以獲得良好的結果。對於SD 1.5的版本,我們建議使用社區模型來生成良好的圖像。非平方圖像的IP-ADAPTER
由於圖像是在剪輯的默認圖像處理器中裁剪的中心,因此IP型適配器最適合平方圖像。對於非正方形圖像,它將錯過中心以外的信息。但是,對於非平方圖像,您只能調整大小為224x224,比較如下:
IP-ADAPTER_XL與Reimagine XL的比較如下:
改進新版本(2023.9.8) :
對於培訓,您應該安裝加速並將自己的數據集放入JSON文件中。
accelerate launch --num_processes 8 --multi_gpu --mixed_precision "fp16"
tutorial_train.py
--pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5/"
--image_encoder_path="{image_encoder_path}"
--data_json_file="{data.json}"
--data_root_path="{image_path}"
--mixed_precision="fp16"
--resolution=512
--train_batch_size=8
--dataloader_num_workers=4
--learning_rate=1e-04
--weight_decay=0.01
--output_dir="{output_dir}"
--save_steps=10000
培訓完成後,您可以使用以下代碼轉換權重:
import torch
ckpt = "checkpoint-50000/pytorch_model.bin"
sd = torch . load ( ckpt , map_location = "cpu" )
image_proj_sd = {}
ip_sd = {}
for k in sd :
if k . startswith ( "unet" ):
pass
elif k . startswith ( "image_proj_model" ):
image_proj_sd [ k . replace ( "image_proj_model." , "" )] = sd [ k ]
elif k . startswith ( "adapter_modules" ):
ip_sd [ k . replace ( "adapter_modules." , "" )] = sd [ k ]
torch . save ({ "image_proj" : image_proj_sd , "ip_adapter" : ip_sd }, "ip_adapter.bin" )
該項目致力於積極影響AI驅動圖像生成的領域。授予用戶使用此工具創建圖像的自由,但期望他們遵守本地法律並以負責任的方式使用它。開發人員對用戶的潛在濫用不承擔任何責任。
如果您發現IP-適配器對您的研究和應用程序有用,請使用此Bibtex引用:
@article { ye2023ip-adapter ,
title = { IP-Adapter: Text Compatible Image Prompt Adapter for Text-to-Image Diffusion Models } ,
author = { Ye, Hu and Zhang, Jun and Liu, Sibo and Han, Xiao and Yang, Wei } ,
booktitle = { arXiv preprint arxiv:2308.06721 } ,
year = { 2023 }
}