/BDInvert_Release

Primary LanguagePythonGNU Affero General Public License v3.0AGPL-3.0

BDInvert: GAN Inversion for Out-of-Range Images with Geometric Transformations

This repository contains the accompanying code for GAN Inversion for Out-of-Range Images with Geometric Transformations, ICCV 2021

Prerequisites

  • Ubuntu 18.04 or higher
  • CUDA 10.0 or higher
  • pytorch 1.6 or higher
  • python 3.7 or higher

Installation

pip install -r requirements.txt

Usage

Train

  1. Change directory into BDInvert.
cd BDInvert
  1. Train base code encoder.
python train_basecode_encoder.py
  • --model_name : You can change backbone StyleGAN model, which located at model zoo.
  • --basecode_spatial_size : You can change spatial resolution of basecode.
  1. Find pnorm parameters.
python pca_p_space.py

Download pretrained base code encoder.

Download and unzip under BDInvert/pretrained_models/.

Encoder Pretrained Models Basc Code Spatial Size
StyleGAN2 pretrained on FFHQ 1024, 16x16 16x16

Test

  • Default test setting use StyleGAN2 pretrained on FFHQ1024 and use basecode spatial size as 16x16.
  1. Change directory into BDInvert.
cd BDInvert
  1. Make image list.
python make_list.py --image_folder ./test_img
  1. Embed images into StyleGAN's latent codes.
python invert.py --encoder_pt_path {encoder_pt_path}
  • --image_list : Inversion target image list generated from above step 2. Default is ./test_img/test.list
  • --weight_pnorm_term : As recently well known, there is a trade-off between editing quality and reconstruction quality. This argument controls this trade-off.
  1. Edit embedded results.
python edit.py {inversion directory}
  • --edit_direction : You can change edit direction, which located at BDInvert/editings/interfacegan_directions

Small changes

  • We changed the detail code regularization method from hard clipping in P-norm+ space to L2 norm regularization, following the update of the original paper.
  • Due to this change, new hyperparameter, weight_pnorm_term, has been added.

License

This software is being made available under the terms in the LICENSE file.

Any exemptions to these terms requires a license from the Pohang University of Science and Technology.

Useful Links

Acknowledgments

NOTE