Home

Awesome

Anyres-GAN

Project Page | Paper | Bibtex

Any-resolution Training for High-resolution Image Synthesis.
ECCV 2022
Lucy Chai, Michaël Gharbi, Eli Shechtman, Phillip Isola, Richard Zhang

Prerequisites

Table of Contents:<br>

  1. Colab - run it in your browser without installing anything locally<br>
  2. Setup - download pretrained models and resources
  3. Pretrained Models - quickstart with pretrained models<br>
  4. Notebooks - jupyter notebooks for interactive composition<br>
  5. Training - pipeline for training encoders<br>
  6. Evaluation - evaluation script<br>
<img src='img/github_loop.gif'> <a name="colab"/>

Colab

Interactive Demo: Try our interactive demo here! Does not require local installations.

<a name="setup"/>

Setup

git clone https://github.com/chail/anyres-gan.git
conda env create -f environment.yml
bash download_resources.sh
<a name="pretrained"/>

Quickstart with pretrained models

Pretrained models are downloaded from the above download_resources.sh script. Any-resolution images can be constructed by specifying the appropriate transformation matrices. The following code snippet provides a basic example; additional examples can be found in the notebook.

import pickle
import torch
import numpy as np
from util import patch_util, renormalize
torch.set_grad_enabled(False)

PATH = 'pretrained/bird_pretrained_final.pkl'

with open(PATH, 'rb') as f:
    G_base = pickle.load(f)['G_ema'].cuda()  # torch.nn.Module
    
full_size = 500
seed = 0

rng = np.random.RandomState(seed)
z = torch.from_numpy(rng.standard_normal(G_base.z_dim)).float()
z = z[None].cuda()
c = None

ws = G_base.mapping(z, c, truncation_psi=0.5, truncation_cutoff=8)
full = torch.zeros([1, 3, full_size, full_size])
patches = patch_util.generate_full_from_patches(full_size, G_base.img_resolution)
for bbox, transform in patches:
    img = patch_util.scale_condition_wrapper(G_base, ws, transform[None].cuda(), noise_mode='const', force_fp32=True)
    full[:, :, bbox[0]:bbox[1], bbox[2]:bbox[3]] = img
renormalize.as_image(full[0])
<a name="notebooks"/>

Notebooks

Note: remember to add the conda environment to jupyter kernels:

python -m ipykernel install --user --name anyres-gan

We provide example notebook notebook-demo.ipynb for running inference on pretrained models.

<a name="training"/>

Training

See the script train.sh for training examples.

Training notes:

Training progress can be visualized using:

tensorboard --logdir training-runs/

Datasets

Beyond the standard FFHQ and LSUN Church datasets, we train on datasets scraped from flickr. Due to licensing we cannot release this images directly. Please see datasets/download/download_dataset.sh for examples on how to download the flickr datasets. You will need to fill in a flickr api key and secret and pip install flickr_api.

For the LSUN Church dataset, you can follow the standard stylegan data preparation and use the resulting archive for training.

<a name="evaluation"/>

Evaluations

See custom_metrics.sh for an example on running FID variations and pFID on the patch models.

Note: the released pretrained models are reimplementations of the models used in the current paper version, so the evaluation numbers are slightly different.

Acknowledgements

Our code is largely based on the Stylegan3 repository (license). Changes to the StyleGAN3 code are documented in diff. Some additional utilities are from David Bau and Taesung Park, and we thank Assaf Shocher for proofreading. Remaining changes are covered under Adobe Research License.

<a name="citation"/>

Citation

If you use this code for your research, please cite our paper:

@inproceedings{chai2022anyresolution,
    title={Any-resolution training for high-resolution image synthesis.},
    author={Chai, Lucy and Gharbi, Michael and Shechtman, Eli and Isola, Phillip and Zhang, Richard},
    booktitle={European Conference on Computer Vision},
    year={2022}
}
<p align="center"> <img src='img/pano010-2.gif' width=600px> <img src='img/pano010.png' width=600px> </p>