Giter Club home page Giter Club logo

dghe's Introduction

Dual-Space Guided High-Fidelity Image Attribute Editing with Diffusion Models

Description

This repo includes the official Pytorch implementation of our DGHE.

image-20240518191548796

Getting Started

We recommend running our code using NVIDIA GPU + CUDA, CuDNN.

Pretrained Models for DGHE

DGHE works on the checkpoints of pretrained diffusion models.

Image Type to Edit Size Pretrained Model Dataset Reference Repo.
Human face 256×256 Diffusion (Auto) CelebA-HQ SDEdit
Human face 256×256 Diffusion CelebA-HQ P2 weighting
Church 256×256 Diffusion (Auto) Church SDEdit
Dog face 256×256 Diffusion AFHQ-Dog ILVR
  • The pretrained Diffuson models on 256x256 images in CelebA-HQ, LSUN-Church, and AFHQ-Dog are automatically downloaded in the code. (codes from DiffusionCLIP)
  • You can manually revise the checkpoint paths and names in the ./configs/paths_config.py file.

Pretrained Checkpoints

Path Description
Human face DGHE trained on the CelebA-HQ dataset.
Church DGHE trained on the Church dataset.
Dog face DGHE trained on the Afhq-Dog dataset.

Training Model

To train the DGHE, run the following commands using script_train.sh

  • python main.py --run_train                              \
        --config $config                                    \
        --exp ./runs/train/$guid                            \
        --edit_attr $guid                                   \
        --do_train 1                                        \
        --do_test 1                                         \
        --n_train_img 80                                    \
        --n_test_img 100                                    \
        --n_iter 1                                          \
        --bs_train 1                                        \
        --t_0 999                                           \
        --n_inv_step 40                                     \
        --n_train_step 40                                   \
        --n_test_step 40                                    \
        --get_h_num 1                                       \
        --train_delta_block                                 \
        --sh_file_name $sh_file_name                        \
        --save_x0                                           \
        --use_x0_tensor                                     \
        --hs_coeff_delta_h 1.0                              \
        --lr_training 0.5                                   \
        --clip_loss_w 0.8                                   \
        --l1_loss_w 2.658                                   \
        --retrain 1                                         \
        --add_noise_from_xt                                 \
        --lpips_addnoise_th 1.2                             \
        --lpips_edit_th 0.33                                \
        --model_path "diffusion model path"                 \
        --gan_model_path "gan inversion model path"         \
        --save_precomputed_images                           \
        --save_x_origin                                     \
        --mysig 0.5                                         \
        --gan_edit                                          \
        --save_src_and_gen                                  \
    

Inference

After training, you can inference using script_inference.sh. We provide some of it in the Pretrained Checkpoints.

  • python main.py --run_test                               \
        --config $config                                    \
        --exp ./runs/test/gan_edit/$guid                    \
        --edit_attr $guid                                   \
        --do_train 0                                        \
        --do_test 1                                         \
        --n_train_img 0                                     \
        --n_test_img 300                                    \
        --n_iter 1                                          \
        --bs_train 1                                        \
        --t_0 999                                           \
        --n_inv_step 40                                     \
        --n_train_step 40                                   \
        --n_test_step $test_step                            \
        --get_h_num 1                                       \
        --train_delta_block                                 \
        --sh_file_name $sh_file_name                        \
        --save_x0                                           \
        --use_x0_tensor                                     \
        --hs_coeff_delta_h 1.0                              \
        --manual_checkpoint_name "pretrained ckpt"          \
        --add_noise_from_xt                                 \
        --lpips_addnoise_th 1.2                             \
        --lpips_edit_th 0.33                                \
        --model_path "diffusion model path"                 \
        --gan_model_path "gan inversion model path"         \
        --save_x_origin                                     \
        --save_src_and_gen                                  \
        --mysig 0.5                                         \
        --save_inv                                          \
        --gan_edit                                          \
    

Additional Results

image-20240518191548796

image-20240518191548796

Acknowledge

We would like to thank the authors of previous related projects for generously sharing their code, especially the DiffusionCLIP and Asyrp.

dghe's People

Contributors

harmonic-lqw 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.