diff --git a/projects/powerpaint/README.md b/projects/powerpaint/README.md new file mode 100644 index 000000000..f122e47d2 --- /dev/null +++ b/projects/powerpaint/README.md @@ -0,0 +1,60 @@ +# A Task is Worth One Word: Learning with Task Prompts for High-Quality Versatile Image Inpainting + +### [Project Page](https://powerpaint.github.io/) | [Paper](https://arxiv.org/abs/2312.03594) + +This README provides a step-by-step guide to download the repository, set up the required virtual environment named "PowerPaint" using conda, and run PowerPaint with or without ControlNet. + +**Stronger Model Weights and Online Demo Coming Soon!** + + + +## Getting Started + +```bash +# Clone the Repository +git clone https://github.com/open-mmlab/mmagic.git + +# Navigate to the Repository +cd projects/powerpaint + +# Create Virtual Environment with Conda +conda create --name PowerPaint python=3.9 +conda activate PowerPaint + +# Install Dependencies +pip install -r requirements.txt + +# Create Models Folder +mkdir models + +# Set up Git LFS +git lfs install + +# Clone PowerPaint Model +git lfs clone https://huggingface.co/JunhaoZhuang/PowerPaint-v1/ ./models +``` + +## Run PowerPaint + +To run PowerPaint, execute the following command: + +```bash +python gradio_PowerPaint.py +``` + +This command will launch the Gradio interface for PowerPaint. + +Feel free to explore and create stunning images with PowerPaint! + +## BibTeX + +``` +@misc{zhuang2023task, + title={A Task is Worth One Word: Learning with Task Prompts for High-Quality Versatile Image Inpainting}, + author={Junhao Zhuang and Yanhong Zeng and Wenran Liu and Chun Yuan and Kai Chen}, + year={2023}, + eprint={2312.03594}, + archivePrefix={arXiv}, + primaryClass={cs.CV} +} +``` diff --git a/projects/powerpaint/gradio_PowerPaint.py b/projects/powerpaint/gradio_PowerPaint.py index 2d41a3a60..86bf3f7fe 100644 --- a/projects/powerpaint/gradio_PowerPaint.py +++ b/projects/powerpaint/gradio_PowerPaint.py @@ -34,9 +34,9 @@ initialize_tokens=['a', 'a', 'a'], num_vectors_per_token=10) pipe.unet.load_state_dict( - torch.load('./models/unet/diffusion_pytorch_model.bin'), strict=False) + torch.load('./models/diffusion_pytorch_model.bin'), strict=False) pipe.text_encoder.load_state_dict( - torch.load('./models/text_encoder/pytorch_model.bin'), strict=False) + torch.load('./models/pytorch_model.bin'), strict=False) pipe = pipe.to('cuda') depth_estimator = DPTForDepthEstimation.from_pretrained( diff --git a/projects/powerpaint/requirements.txt b/projects/powerpaint/requirements.txt new file mode 100644 index 000000000..14755c0ff --- /dev/null +++ b/projects/powerpaint/requirements.txt @@ -0,0 +1,8 @@ +controlnet-aux==0.0.3 +diffusers==0.23.1 +gradio==3.23.0 +mmengine +opencv-python +torch +torchvision +transformers diff --git a/projects/powerpaint/utils/utils.py b/projects/powerpaint/utils/utils.py index 5dec6f604..2a8b2195f 100644 --- a/projects/powerpaint/utils/utils.py +++ b/projects/powerpaint/utils/utils.py @@ -1,4 +1,5 @@ import copy +import importlib import os import random from logging import WARNING @@ -8,7 +9,21 @@ import torch.nn as nn from mmengine import print_log -from mmagic.utils import try_import + +def try_import(name: str): + """Try to import a module. + + Args: + name (str): Specifies what module to import in absolute or relative + terms (e.g. either pkg.mod or ..mod). + Returns: + ModuleType or None: If importing successfully, returns the imported + module, otherwise returns None. + """ + try: + return importlib.import_module(name) + except ImportError: + return None class TokenizerWrapper: