MIT License

项目介绍

PeterWang512/GANWarping 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 174 个 Star、9 次 Fork。

仓库全名
PeterWang512/GANWarping
开源许可证
MIT License
Star 数
174
Fork 数
9
未关闭 Issue
3

README 摘要

Rewriting Geometric Rules of a GAN Project | Paper | Youtube | Slides 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,…

完整内容见 GitHub 原始 README 或本页 。

常见问题

GANWarping 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 174 个 Star。

GANWarping 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 GANWarping 的源码?

可以直接克隆仓库:git clone https://github.com/PeterWang512/GANWarping.git,默认分支为 main;安装与运行步骤见仓库 README。

GANWarping 最近还在维护吗?

仓库最近一次更新为 2022年12月2日,当前有 3 个未关闭 Issue;Star 数为 174,可作为社区活跃度的参考。

关于

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

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
196
价值分
107
活跃状态
活跃

README

Rewriting Geometric Rules of a GAN

Project | Paper | Youtube | Slides

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

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.

评论

暂无评论