GithubHelp home page GithubHelp logo

inuryyev / composition-stable-diffusion Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reality-editor/composition-stable-diffusion

0.0 0.0 0.0 17.01 MB

Image Composition via Stable Diffusion

Home Page: https://realityeditor.com.cn/

License: MIT License

Shell 2.66% Python 97.34%

composition-stable-diffusion's Introduction

Image Composition via Stable Diffusion

We achieve image composition via Stable Diffusion Model. Application includes Virtual Clothes / Funiture Try-on.

Demo 1: Virtual Clothes Try-on


Demo 2: Virtual Furniture Try-on

Installation

  • Requirements
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch 
pip install -r requirements.txt
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION="python"
  • Initialize an 🤗Accelerate environment with

    accelerate config default
  • Run the following command to authenticate your token

    huggingface-cli login

0. Prepare Images

Please provide at least one images in .jpg format and instance prompt. For example, images in ./data/sofa

1. Set Environment

export MODEL_NAME="runwayml/stable-diffusion-inpainting"
export INSTANCE_DIR="data/sofa"
export TEST_DIR="data/sofa_test"
export MODEL_DIR="logs/sofa"
export OUT_DIR="out/sofa"
export INSTANCE_PROMPT="sofa"

2. Preprocess Images

Please provide at least one images in .jpg format and instance prompt. The preprocess.py script will generate captions and instance masks.

python preprocess.py --instance_data_dir $INSTANCE_DIR \
                     --instance_prompt $INSTANCE_PROMPT

3. Finetune

We then embed the instance images and prompt into stable diffusion model.

accelerate launch --num_processes 1 train.py \
  --pretrained_model_name_or_path=$MODEL_NAME  \
  --instance_data_dir=$INSTANCE_DIR \
  --output_dir=$MODEL_DIR \
  --instance_prompt=$INSTANCE_PROMPT \
  --resolution=512 \
  --train_batch_size=1 \
  --gradient_accumulation_steps=1 \
  --learning_rate=5e-6 \
  --lr_scheduler="constant" \
  --lr_warmup_steps=0 \
  --max_train_steps=1000

4. Image Composition

Finally, you can provide new images to achieve image composition.

python inference.py --image_path $TEST_DIR \
                    --model_path $MODEL_DIR \
                    --out_path $OUT_DIR \
                    --instance_prompt $INSTANCE_PROMPT

Or else

using end-to-end run_sd.sh.

bash run.sh

GPU Memory

We tested the code on RTX3090 GPU. If there is Out-of-Memory error, please refer to for low memory training:

Authors:

composition-stable-diffusion's People

Contributors

g3956 avatar inuryyev avatar realityeditors avatar tau-yihouxiang avatar xiaogang00 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.