Skip to content

Commit

Permalink
Fix: solve some environment and demo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Paper99 committed Jan 17, 2024
1 parent f959a0e commit 00ab9fe
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 11 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Official implementation of **[PhotoMaker: Customizing Realistic Human Photos via
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.


---

<div align="center">
Expand Down Expand Up @@ -75,7 +74,19 @@ Note: only change the base model and add the LoRA modules for better stylization
- Python >= 3.8 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
- [PyTorch >= 2.0.0](https://pytorch.org/)
```bash
conda create --name photomaker python=3.10
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
```python
from photomaker import PhotoMakerStableDiffusionXLPipeline
```

# ⏬ Download Models
Expand All @@ -98,7 +109,7 @@ import torch
import os
from diffusers.utils import load_image
from diffusers import EulerDiscreteScheduler
from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline
from photomaker import PhotoMakerStableDiffusionXLPipeline

### Load base model
pipe = PhotoMakerStableDiffusionXLPipeline.from_pretrained(
Expand Down Expand Up @@ -181,7 +192,7 @@ You could customize this script in [this file](gradio_demo/app.py).
- For faster speed, reduce the number of generated images and sampling steps. However, please note that reducing the sampling steps may compromise the ID fidelity.

# 🤗 Acknowledgements
- T2I-Adapter is co-hosted by Tencent ARC Lab and Nankai University [MCG-NKU](https://mmcheng.net/cmm/).
- PhotoMaker is co-hosted by Tencent ARC Lab and Nankai University [MCG-NKU](https://mmcheng.net/cmm/).
- Inspired from many excellent demos and repos, including [IP-Adapter](https://github.com/tencent-ailab/IP-Adapter), [multimodalart/Ip-Adapter-FaceID](https://huggingface.co/spaces/multimodalart/Ip-Adapter-FaceID), [FastComposer](https://github.com/mit-han-lab/fastcomposer), and [T2I-Adapter](https://github.com/TencentARC/T2I-Adapter). Thanks for their great works!
- Thanks for Venus team in Tencent PCG for their feedback and suggestions.

Expand Down
8 changes: 5 additions & 3 deletions gradio_demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import spaces
import gradio as gr

from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline
from photomaker import PhotoMakerStableDiffusionXLPipeline
from style_template import styles

# global variable
Expand All @@ -28,14 +28,16 @@
torch_dtype=torch.bfloat16,
use_safetensors=True,
variant="fp16",
# local_files_only=True,
).to(device)

pipe.load_photomaker_adapter(
os.path.dirname(photomaker_ckpt),
subfolder="",
weight_name=os.path.basename(photomaker_ckpt),
trigger_word="img"
)
)
pipe.id_encoder.to(device)

pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
# pipe.set_adapters(["photomaker"], adapter_weights=[1.0])
Expand Down Expand Up @@ -282,4 +284,4 @@ def get_example():

gr.Markdown(article)

demo.launch()
demo.launch(share=False)
7 changes: 7 additions & 0 deletions photomaker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .model import PhotoMakerIDEncoder
from .pipeline import PhotoMakerStableDiffusionXLPipeline

__all__ = [
"PhotoMakerIDEncoder",
"PhotoMakerStableDiffusionXLPipeline",
]
2 changes: 1 addition & 1 deletion photomaker/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logging,
)

from photomaker.model import PhotoMakerIDEncoder
from . import PhotoMakerIDEncoder

PipelineImageInput = Union[
PIL.Image.Image,
Expand Down
4 changes: 2 additions & 2 deletions photomaker_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"from diffusers import EulerDiscreteScheduler\n",
"from huggingface_hub import hf_hub_download\n",
"\n",
"from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline"
"from photomaker import PhotoMakerStableDiffusionXLPipeline"
]
},
{
Expand Down Expand Up @@ -256,4 +256,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion photomaker_style_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"from diffusers import DDIMScheduler\n",
"from huggingface_hub import hf_hub_download\n",
"\n",
"from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline"
"from photomaker import PhotoMakerStableDiffusionXLPipeline"
]
},
{
Expand Down
43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tool.poetry]
name = "photomaker"
version = "0.1.0"
description = "PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding"
authors = ["Li, Zhen", "Cao, Mingdeng", "Wang, Xintao", "Qi, Zhongang", "Cheng, Ming-Ming", "Shan, Ying"]
license = "Apache-2.0"
readme = "README.md"
packages = [{ include = "photomaker" }]

[tool.poetry.dependencies]
python = ">=3.7"

[tool.ruff]
line-length = 119
# Deprecation of Cuda 11.6, Python 3.7 support for PyTorch 2.0
target-version = "py38"

# A list of file patterns to omit from linting, in addition to those specified by exclude.
extend-exclude = ["__pycache__", "*.pyc", "*.egg-info", ".cache"]

select = ["E", "F", "W", "C90", "I", "UP", "B", "C4", "RET", "RUF", "SIM"]


ignore = [
"UP006", # UP006: Use list instead of typing.List for type annotations
"UP007", # UP007: Use X | Y for type annotations
"UP009",
"UP035",
"UP038",
"E402",
"RET504",
]

[tool.isort]
profile = "black"

[tool.black]
line-length = 119
skip-string-normalization = 1

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
torch==2.0.1
torchvision==0.15.2
pytorch-cuda==11.8
diffusers==0.25.0
transformers==4.36.2
huggingface-hub==0.20.2
Expand Down

0 comments on commit 00ab9fe

Please sign in to comment.