Giter Site home page Giter Site logo

cleancoindev / ganwarping Goto Github PK

View Code? Open in Web Editor NEW

This project forked from peterwang512/ganwarping

0.0 1.0 0.0 57.08 MB

Rewriting Geometric Rules of a GAN: Warp a GAN model to customized, out-of-domain shapes.

Home Page: https://peterwang512.github.io/GANWarping

License: MIT License

Shell 3.01% Python 93.35% Jupyter Notebook 3.64%

ganwarping's Introduction

Rewriting Geometric Rules of a GAN

Project | Paper | Youtube

With our method, a user can edit a GAN model to synthesize many unseen objects with the desired shape. The user is asked to warp just a handful of generated images by defining several control points to obtain the customized models. While the edited models change an object’s shape, other visual cues, such as pose, color, texture, and background, are faithfully preserved after the modification.


Sheng-Yu Wang1, David Bau2, Jun-Yan Zhu1.
CMU1, Northeastern University2
In SIGGRAPH, 2022.

Results

Warp edits. Below we show warped models with different object categories.

Color edits. Our method can also be applied to color edits. The colored strokes specify the locations to perform coloring changes, while the darker region defines the region to be preserved. The edited models produce precise coloring changes in the specified parts.

Latent space edits. Our edited models can generate smooth transitions between two random samples by interpolating the latent space. We can also apply GANSpace edits to our models to change the object attributes such as poses or colors.

Compose edited models. We can compose the edited models into a new model with aggregated geometric changes, by simpling blending the model weights linearly.

Getting Started

Clone our repo

git clone [email protected]:PeterWang512/GANWarping.git
cd GANWarping
git submodule update --init --recursive

Set up conda environment

conda env create -f environment.yaml
conda activate ganwarp

Download model weights and data

# Download training data
bash data/download_data.sh

# Download pretrained models
bash pretrained/download_pretrained_models.sh

# Download edited models
bash weights/download_weights.sh

Local jupyter notebooks

3 local jupyter notebooks are provided in notebooks.

  • compose_models.ipynb composes multiple models that are edited beforehand.
  • generate_warp_data.ipynb is the notebook to generate training data to warp a GAN.
  • generate_color_data.ipynb is the notebook to generate training data to change the color of a GAN.

Generate samples from a customized model

This command runs the customized model specified by -m, and generates samples to -o.

# generates samples from the "alien-eyed cat" model
python sample.py -o results/samples -m weights/sg3r_cat/cat_alien_eye.pth --pretrained cat

# generates a video of samples from the "alien-eyed cat" model
python sample.py -o results/video.mp4 -m weights/sg3r_cat/cat_alien_eye.pth  --pretrained cat --tile --video

Latent space edits by GANSpace

Our model preserves the latent space editability of the original model. Our models can apply the same edits using the latents reported in Härkönen et.al. (GANSpace).

# change poses of the cats
python ganspace_edit.py --ganspace ganspace/cat_ganspace.npz --base_model_path pretrained/stylegan3-r-afhqv2cat-512x512.pkl --edited_model_path weights/sg3r_cat/cat_alien_eye.pth --comp_idx 7 --strength '-10' --layers 1,3 --save_dir results/ganspace/cat_pose

# make the cats more flurry
python ganspace_edit.py --ganspace ganspace/cat_ganspace.npz --base_model_path pretrained/stylegan3-r-afhqv2cat-512x512.pkl --edited_model_path weights/sg3r_cat/cat_alien_eye.pth --comp_idx 13 --strength 10 --layers 4,8 --save_dir results/ganspace/cat_furry

# change colors of the horses
python ganspace_edit.py --ganspace ganspace/horse_ganspace.npz --base_model_path pretrained/stylegan3-r-horse-256x256.pkl --edited_model_path weights/sg3r_horse/horse_lift_leg.pth --comp_idx 3 --strength 8 --layers 9,11 --save_dir results/ganspace/horse_color --trunc 0.5

Model Training

Training Scripts

The example training configurations for each dataset are specified using the scripts in scripts folder. Use the following commands to launch trainings.

# Train the "alien-eyed cat" model
bash scripts/sg3r_cat/cat_alien_eye.sh

# Train the "red-eyed cat" model
bash scripts/sg3r_cat/cat_red_eye.sh

The training progress is tracked using wandb by default. To disable wandb logging, please add the --no_wandb tag to the training script.

Evaluations

Use the following script to evaluate the models, the results will be saved in a csv file in results/metrics/table.csv by default. -t should contain a list of tuple of model weight paths and evaluation data. Please see weights/eval_task for example.

python test.py -t weights/eval_task

Related Works

Acknowledgments

This repository borrows partially from rewriting, stylegan3, swapping-autoencoder-pytorch, ganspace.

Reference

If you find this useful for your research, please cite the following work.

@article{wang2022rewriting,
author = {Wang, Sheng-Yu and Bau, David and Zhu, Jun-Yan},
title = {Rewriting Geometric Rules of a GAN},
year = {2022},
journal = {ACM Transactions on Graphics (TOG)}
}

Feel free to contact us with any comments or feedback.

ganwarping's People

Contributors

junyanz avatar peterwang512 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.