PhotoMaker README

The project's README from github.com/TencentARC/PhotoMaker. As one markdown file: README.md.

PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding Paper page

[Paper]   [Project Page]   [Model Card]

[💥New 🤗 Demo (PhotoMaker V2)]   [🤗 Demo (Realistic)]   [🤗 Demo (Stylization)]

[Replicate Demo (Realistic)]   [Replicate Demo (Stylization)]   [Jittor version]

PhotoMaker-V2 is supported by the HunyuanDiT team.

🥳 We release PhotoMaker V2. Please refer to comparisons between PhotoMaker V1, PhotoMaker V2, IP-Adapter-FaceID-plus-V2, and InstantID. Please watch this video for how to use our demo. For PhotoMaker V2 ComfyUI nodes, please refer to the Related Resources


🌠 Key Features:

  1. Rapid customization within seconds, with no additional LoRA training.
  2. Ensures impressive ID fidelity, offering diversity, promising text controllability, and high-quality generation.
  3. Can serve as an Adapter to collaborate with other Base Models alongside LoRA modules in community.

TencentARC%2FPhotoMaker | Trendshift

❗❗ Note: If there are any PhotoMaker based resources and applications, please leave them in the discussion and we will list them in the Related Resources section in README file. Now we know the implementation of Replicate, Windows, ComfyUI, and WebUI. Thank you all!

photomaker_demo_fast

🚩 New Features/Updates


🔥 Examples

Realistic generation

Stylization generation

Note: only change the base model and add the LoRA modules for better stylization

🔧 Dependencies and Installation

conda create --name photomaker python=3.10
conda activate photomaker
pip install -U pip

# Install requirements
pip install -r requirements.txt

# Install photomaker
pip install git+https://github.com/TencentARC/PhotoMaker.git

Then you can run the following command to use it

from photomaker import PhotoMakerStableDiffusionXLPipeline

⏬ Download Models

The model will be automatically downloaded through the following two lines:

from huggingface_hub import hf_hub_download
photomaker_path = hf_hub_download(repo_id="TencentARC/PhotoMaker", filename="photomaker-v1.bin", repo_type="model")

You can also choose to download manually from this url.

💻 How to Test

Use like diffusers

import torch
import os
from diffusers.utils import load_image
from diffusers import EulerDiscreteScheduler
from photomaker import PhotoMakerStableDiffusionXLPipeline

### Load base model
pipe = PhotoMakerStableDiffusionXLPipeline.from_pretrained(
    base_model_path,  # can change to any base model based on SDXL
    torch_dtype=torch.bfloat16, 
    use_safetensors=True, 
    variant="fp16"
).to(device)

### Load PhotoMaker checkpoint
pipe.load_photomaker_adapter(
    os.path.dirname(photomaker_path),
    subfolder="",
    weight_name=os.path.basename(photomaker_path),
    trigger_word="img"  # define the trigger word
)     

pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)

### Also can cooperate with other LoRA modules
# pipe.load_lora_weights(os.path.dirname(lora_path), weight_name=lora_model_name, adapter_name="xl_more_art-full")
# pipe.set_adapters(["photomaker", "xl_more_art-full"], adapter_weights=[1.0, 0.5])

pipe.fuse_lora()
### define the input ID images
input_folder_name = './examples/newton_man'
image_basename_list = os.listdir(input_folder_name)
image_path_list = sorted([os.path.join(input_folder_name, basename) for basename in image_basename_list])

input_id_images = []
for image_path in image_path_list:
    input_id_images.append(load_image(image_path))

# Note that the trigger word `img` must follow the class word for personalization
prompt = "a half-body portrait of a man img wearing the sunglasses in Iron man suit, best quality"
negative_prompt = "(asymmetry, worst quality, low quality, illustration, 3d, 2d, painting, cartoons, sketch), open mouth, grayscale"
generator = torch.Generator(device=device).manual_seed(42)
images = pipe(
    prompt=prompt,
    input_id_images=input_id_images,
    negative_prompt=negative_prompt,
    num_images_per_prompt=1,
    num_inference_steps=num_steps,
    start_merge_step=10,
    generator=generator,
).images[0]
gen_images.save('out_photomaker.png')

Start a local gradio demo

Run the following command:

python gradio_demo/app.py

You could customize this script in this file.

If you want to run it on MAC, you should follow this Instruction and then run the app.py.

Usage Tips:

Related Resources

Replicate demo of PhotoMaker:

  1. Demo link, run PhotoMaker on replicate, provided by @yorickvP and @jd7h.
  2. Demo link (style version).

WebUI version of PhotoMaker:

  1. stable-diffusion-webui-forge: https://github.com/lllyasviel/stable-diffusion-webui-forge provided by @Lvmin Zhang
  2. Fooocus App: Fooocus-inswapper provided by @machineminded

Windows version of PhotoMaker:

  1. bmaltais/PhotoMaker by @bmaltais, easy to deploy PhotoMaker on Windows. The description can be found in this link.
  2. sdbds/PhotoMaker-for-windows by @sdbds.

ComfyUI:

  1. 🔥 Official Implementation by ComfyUI: https://github.com/comfyanonymous/ComfyUI/commit/d1533d9c0f1dde192f738ef1b745b15f49f41e02
  2. https://github.com/ZHO-ZHO-ZHO/ComfyUI-PhotoMaker
  3. https://github.com/StartHua/Comfyui-Mine-PhotoMaker
  4. https://github.com/shiimizu/ComfyUI-PhotoMaker

ComfyUI (for PhotoMaker V2):

  1. https://github.com/shiimizu/ComfyUI-PhotoMaker-Plus
  2. https://github.com/edwios/ComfyUI-PhotoMakerV2-ZHO/tree/main
  3. https://openart.ai/workflows/shalacai/photomakerv2/fttT4ztRM85JxBJ2eUyr
  4. https://github.com/zhangp365/ComfyUI_photomakerV2_native

Purely C/C++/CUDA version of PhotoMaker:

  1. stable-diffusion.cpp by @bssrdf.

Other Applications / Web Demos

  1. Wisemodel 始智 (Easy to use in China) https://wisemodel.cn/space/gradio/photomaker
  2. OpenXLab (Easy to use in China): https://openxlab.org.cn/apps/detail/camenduru/PhotoMaker Open in OpenXLab by @camenduru.
  3. Colab: https://github.com/camenduru/PhotoMaker-colab by @camenduru
  4. Monster API: https://monsterapi.ai/playground?model=photo-maker
  5. Pinokio: https://pinokio.computer/item?uri=https://github.com/cocktailpeanutlabs/photomaker

Graido demo in 45 lines

Provided by @Gradio

🤗 Acknowledgements

Disclaimer

This project strives to impact the domain of AI-driven image generation positively. Users are granted the freedom to create images using this tool, but they are expected to comply with local laws and utilize it responsibly. The developers do not assume any responsibility for potential misuse by users.

BibTeX

If you find PhotoMaker useful for your research and applications, please cite using this BibTeX:

@inproceedings{li2023photomaker,
  title={PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding},
  author={Li, Zhen and Cao, Mingdeng and Wang, Xintao and Qi, Zhongang and Cheng, Ming-Ming and Shan, Ying},
  booktitle={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2024}
}

PhotoMaker (TencentARC/PhotoMaker)

Searching Database…

这是什么东西?PhotoMaker 是腾讯 ARC 推出的一款 AI 工具(CVPR 2024),可以生成某个特定人物的新图像:你提供几张该人脸的参考照片,再加一段文字提示词,它就能把这个人的形象渲染到新的场景、姿势或风格中。
这是需要安装的应用,还是在代码里调用的模型?它是一套研究代码加模型,而不是打包好的应用:你可以在 Python 中把它当作 diffusers 管线来用,或者在浏览器里启动本地 gradio 演示。此外还有托管在 HuggingFace 和 Replicate 上的在线演示。
我在本地怎么把它跑起来?安装 Python 3.8 或更新版本(推荐 Anaconda 或 Miniconda)和 PyTorch 2.0 或更新版本,然后运行自带的 notebook 或 app.py——模型权重会在首次使用时自动下载。
有什么技巧能让生成的像本人更像?多上传几张这个人的照片可以提高 ID 相似度;对于亚洲面孔,在类别词前加上 'Asian'(例如 'Asian woman img')。减少采样步数能加快速度,但会降低相似度。
我需要什么显卡,生成速度有多快?至少需要 11GB 显存。如果显卡不支持 bfloat16,就改用 float16——在 V100 上这一调整把每张图的生成时间从 1 分钟缩短到了 14 秒。
PhotoMaker V2 有什么新变化?V2(2024 年 7 月)在保持 V1 生成质量、可编辑性以及与现有插件兼容性的同时,提升了 ID 相似度。技术报告也在计划中。
完全不会写代码也能用吗?可以——HuggingFace 和 Replicate 上有托管演示(写实版和风格化版),还有 Colab notebook、V2 的官方 ComfyUI 节点、通过 stable-diffusion-webui-forge 和 Fooocus 的 WebUI 版本,以及现成的 Windows 安装包。
它只能生成写实照片,还是也能做风格化的脸?两者都行:做风格化时,更换基础模型并加上 LoRA 模块即可。如果脸太写实,可以把 Style strength 调到 30-50——数值越高,风格化效果越好,但 ID 相似度越低。
它和其他基础模型以及社区 LoRA 兼容吗?兼容——PhotoMaker 可以作为适配器,与其他基础模型和社区 LoRA 模块配合使用。V2 还附带了 ControlNet、T2I-Adapter 和 IP-Adapter 的集成脚本,并可与 LCM 结合以加快采样速度。
Creator
TencentARC
Size
10.2 MB
Stars
10.1K
Updated
CommitOct 31
Age
2y
Commits · 90 Days