Giter VIP home page Giter VIP logo

furniture_diffusion's Introduction

Image Composition via Stable Diffusion

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

Demo: 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
  • Initialize an 🤗Accelerate environment with
    accelerate config default

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="dataset/sofa"
export Test_DIR="test/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 finetune_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_lora.py --image_path $Test_DIR \
                    --model_path $MODEL_DIR \
                    --out_path $OUT_DIR \
                    --instance_prompt $INSTANCE_PROMPT

Or else

using end-to-end run.sh.

bash run_lora.sh

Demo with gradio UI

bash run_gradio.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:

furniture_diffusion's People

Contributors

phutd03 avatar

Watchers

 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.