[TOG 2021] PyTorch implementation for the paper: SofGAN: A Portrait Image Generator with Dynamic Styling.

Overview

SofGAN (TOG 2021)

Project page | Paper

This repository contains the official PyTorch implementation for the paper: SofGAN: A Portrait Image Generator with Dynamic Styling. We propose a SofGAN image generator to decouple the latent space of portraits into two subspaces: a geometry space and a texture space. Experiments on SofGAN show that our system can generate high quality portrait images with independently controllable geometry and texture attributes.

Teaser

Installation

version version version

Install environment:

git clone https://github.com/apchenstu/sofgan.git --recursive
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.2 -c pytorch
pip install tqdm argparse scikit-image lmdb config-argparse dlib

Training

Please see each subsection for training on different datasets. Available training datasets:

We also provide our pre-process ffhq and celeba segmaps (in our classes labels). You may also want to re-train the SOF model base on your own multi-view segmaps.

Run

CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 --master_port=9999 train.py \
    --num_worker 4  --resolution 1024
   --name $exp_name
   --iter 10000000
   --batch 1 --mixing 0.9 \
   path/to/your/image/folders \
   --condition_path path/to/your/segmap/folders

In our experiments, 4x Nividia 2080Ti GPU would take around 20 days to reach 10000k iterations. Adjusting the image resolution and max iterations to suit your own dataset. Emperically, for datasets like FFHQ and CelebA(resolution 1024x1024) the network would converge after 1000k iterations and achieve fancy results.

Notice: training on none pair-wise data (image/segmap) is encouraged. Since it's one of the key features of our SofGAN.

Rendering

We provide a rendering script in renderer.ipynb, where you can restyle your own photos, videos and generate free-viewpoint portrait images while maintaining the geometry consistency. Just to download our checkpoints and unzip to the root folder.

UI Illustration

The Painter is included in Painter, you can pull down and drawing on-the-fly. Before that, you need to install the enviroment with pip install -r ./Painter/requirements.txt

UI

IOS App

You could download and try the Wand, an IOS App developed by Deemos.

two-dimensions

Online Demo

New Folder

Relevant Works

StyleFlow: Attribute-conditioned Exploration of StyleGAN-Generated Images using Conditional Continuous Normalizing Flows (TOG 2021)
Rameen Abdal, Peihao Zhu, Niloy Mitra, Peter Wonka

SEAN: Image Synthesis With Semantic Region-Adaptive Normalization (CVPR 2020)
Peihao Zhu, Rameen Abdal, Yipeng Qin, Peter Wonka

StyleRig: Rigging StyleGAN for 3D Control over Portrait Images (CVPR 2020)
A. Tewari, M. Elgharib, G. Bharaj, F. Bernard, H.P. Seidel, P. Pérez, M. Zollhöfer, Ch. Theobalt

StyleGAN2: Analyzing and Improving the Image Quality of {StyleGAN} (CVPR 2020)
Tero Karras, Samuli Laine, Miika Aittala, Janne Hellsten, Jaakko Lehtinen, Timo Aila

SPADE: Semantic Image Synthesis with Spatially-Adaptive Normalization (CVPR 2019)
Taesung Park, Ming-Yu Liu, Ting-Chun Wang, Jun-Yan Zhu

Citation

If you find our code or paper helps, please consider citing:

@article{sofgan,
author = {Chen, Anpei and Liu, Ruiyang and Xie, Ling and Chen, Zhang and Su, Hao and Yu Jingyi},
title = {SofGAN: A Portrait Image Generator with Dynamic Styling},
year = {2021},
issue_date = {Jul 2021},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
volume = {41},
number = {1},
url = {https://doi.org/10.1145/3470848},
doi = {10.1145/3470848},
journal = {ACM Trans. Graph.},
month = July,
articleno = {1},
numpages = {26},
keywords = {image editing, Generative adversarial networks}
}
Comments
  • My train speed is much slower than yours

    My train speed is much slower than yours

    How can I improve the train speed?

    It takes 2 hours to make a train with 1000 iterations on 2x GeForce RTX 3090, and 10000k will need 833 days but your train only 20 days.

    my train command is as follows : python -m torch.distributed.launch --nproc_per_node=2 --master_port=9999 train.py --num_worker 4 --resolution 1024 --name Jeric --iter 1000 --batch 1 --mixing 0.9 path-to-your-image-folders --condition_path path-to-your-segmap-folders

    • path-to-your-image-folders, set to the CelebA-HQ-img folder of Celeb dataset.

    • path-to-your-segmap-folders , set to the CelebAMask-HQ folder downloaded from your pre-process ffhq and celeba segmaps.

    • trained on Windows 10

    Thanks.

    opened by kinglon 4
  • Checkpoint file in colab doesn't exist

    Checkpoint file in colab doesn't exist

    Trying the colab version, but:

    !gdown https://drive.google.com/uc?id=1LPKU3AJVlhnyXBGzLS0UrOEhIT1gcFpD Gives error, manually checking the link finds that the file is missing.

    opened by Mayorc1978 3
  • Can you release the code of the tool of generate segmap

    Can you release the code of the tool of generate segmap

    I can download your pre-process ffhq and celeba segmaps, but can't find the tool's code, can you release its code or the tool? Now , I want to train the model for anime, and need to generate anime's segmap for train.

    opened by kinglon 3
  • Your pre-process ffhq and celeba segmaps zip file contain duplicate files

    Your pre-process ffhq and celeba segmaps zip file contain duplicate files

    Hi, thank you for your amazing work! I found an error in the zip file you provided : "segmaps.zip" from https://drive.google.com/file/d/1_gSENMI5hYj-JTjqtn14PkoLLnEp94oY/view?usp=sharing This zip file contains two directories : "FFHQ" and "CelebAMask-HQ". However, these two directories contain totally duplicate files. It seems that the directory "CelebAMask-HQ" contains wrong content. Could you please provide the pre-processed segmaps for CelebAMask-HQ?

    opened by Jianhua-Cui 2
  • Why do the Generator not use the real images in train.py

    Why do the Generator not use the real images in train.py

    I looked through the train.py, and didn't find the Generator use the real image. I doubt if the Generator load a pre-train model that have learned from a lot of real images. Now, I want to use sofgan to generate an anime photo, can I achieve it after a model train only using the real anime pictures and its segmaps.

    opened by kinglon 2
  • Update run_UI.py

    Update run_UI.py

    During training, there is a loss of precision when floating-point numbers are converted from numpy.ndarray to torch.Tensor, so the calculated results may have RGB values out of bounds

    opened by idsj 1
  • Can you add ./ckpts/* files?

    Can you add ./ckpts/* files?

    I haven't found the follow 2 files when running renderer.ipynb.

    • ./ckpts/generator.pt
    • ./ckpts/segNet-20Class.pth

    I have one GTX1660 super having 1408 stream processors. So, it takes too long to train this model. Can you help me?

    opened by tuxxon 1
  • About the anime face parsing.

    About the anime face parsing.

    Hello! Thanks for you amazing work. I am very interesting about your job. I am studying on some anime projects, on the project homepage(https://apchenstu.github.io/sofgan/), I saw that you show the editing effect of an animation (Video 5b: Generation from drawing). Where did the animation parsing data you use come from? Can you share the anime data link?

    opened by kingofprank 1
  • Irises repeat themselves to fill out eyes

    Irises repeat themselves to fill out eyes

    When drawing admittedly unrealistic eye sizes sofgan will repeat an iris and corners inside of the eye instead of making a larger iris to fill the eye shape. This is a problem when trying to draw stylized faces or caricatures.

    Perhaps warping the photos and segmaps with PyTorch's grid sampler to bend, twist, shrink, expand, fisheye, etc will encourage the model to fill eyes with a single iris that fits the eye shape and size.

    opened by torridgristle 0
  • How to project the real-captured photos into your texture space?

    How to project the real-captured photos into your texture space?

    Hi,

    I am trying to use this model to edit real-captured photos but I think the exsisting renderer.ipynb file only using the random style. In the paper, there are visualization results for regionally real photo editing(Fig. 27). So I would like to ask how to project the real-captured photos into your texture space? And after that, is it right that scatter_to_mask function should be used and then use the generated style_masks to control the editing region?

    opened by picksh 0
  • what's the meaning of classwiseStyle parameter?

    what's the meaning of classwiseStyle parameter?

    Hi, and thank you for your amazing work!

    In SIW-StyleGAN architecture, the classwiseStyle parameter is always set to False, but what is it for? In which cases should it be used?

    opened by gitsand996 0
Owner
Anpei Chen
Anpei Chen
The source code of the ICCV2021 paper "PIRenderer: Controllable Portrait Image Generation via Semantic Neural Rendering"

The source code of the ICCV2021 paper "PIRenderer: Controllable Portrait Image Generation via Semantic Neural Rendering"

Ren Yurui 261 Jan 9, 2023
The source code of the ICCV2021 paper "PIRenderer: Controllable Portrait Image Generation via Semantic Neural Rendering"

Website | ArXiv | Get Start | Video PIRenderer The source code of the ICCV2021 paper "PIRenderer: Controllable Portrait Image Generation via Semantic

Ren Yurui 81 Sep 25, 2021
Official Implementation and Dataset of "PPR10K: A Large-Scale Portrait Photo Retouching Dataset with Human-Region Mask and Group-Level Consistency", CVPR 2021

Portrait Photo Retouching with PPR10K Paper | Supplementary Material PPR10K: A Large-Scale Portrait Photo Retouching Dataset with Human-Region Mask an

null 184 Dec 11, 2022
《Deep Single Portrait Image Relighting》(ICCV 2019)

Ratio Image Based Rendering for Deep Single-Image Portrait Relighting [Project Page] This is part of the Deep Portrait Relighting project. If you find

null 62 Dec 21, 2022
Official code for paper Exemplar Based 3D Portrait Stylization.

3D-Portrait-Stylization This is the official code for the paper "Exemplar Based 3D Portrait Stylization". You can check the paper on our project websi

null 60 Dec 7, 2022
Unofficial pytorch implementation of the paper "Dynamic High-Pass Filtering and Multi-Spectral Attention for Image Super-Resolution"

DFSA Unofficial pytorch implementation of the ICCV 2021 paper "Dynamic High-Pass Filtering and Multi-Spectral Attention for Image Super-Resolution" (p

null 2 Nov 15, 2021
PyTorch implementation of paper "Neural Scene Flow Fields for Space-Time View Synthesis of Dynamic Scenes", CVPR 2021

Neural Scene Flow Fields PyTorch implementation of paper "Neural Scene Flow Fields for Space-Time View Synthesis of Dynamic Scenes", CVPR 20

Zhengqi Li 585 Jan 4, 2023
Official PyTorch Implementation of paper "Deep 3D Mask Volume for View Synthesis of Dynamic Scenes", ICCV 2021.

Deep 3D Mask Volume for View Synthesis of Dynamic Scenes Official PyTorch Implementation of paper "Deep 3D Mask Volume for View Synthesis of Dynamic S

Ken Lin 17 Oct 12, 2022
dualFace: Two-Stage Drawing Guidance for Freehand Portrait Sketching (CVMJ)

dualFace dualFace: Two-Stage Drawing Guidance for Freehand Portrait Sketching (CVMJ) We provide python implementations for our CVM 2021 paper "dualFac

Haoran XIE 46 Nov 10, 2022
MODNet: Trimap-Free Portrait Matting in Real Time

MODNet is a model for real-time portrait matting with only RGB image input.

Zhanghan Ke 2.8k Dec 30, 2022
Rethinking Portrait Matting with Privacy Preserving

Rethinking Portrait Matting with Privacy Preserving This is the official repository of the paper Rethinking Portrait Matting with Privacy Preserving.

null 184 Jan 3, 2023
Dynamic View Synthesis from Dynamic Monocular Video

Towards Robust Monocular Depth Estimation: Mixing Datasets for Zero-shot Cross-dataset Transfer This repository contains code to compute depth from a

Intelligent Systems Lab Org 2.3k Jan 1, 2023
Dynamic View Synthesis from Dynamic Monocular Video

Dynamic View Synthesis from Dynamic Monocular Video Project Website | Video | Paper Dynamic View Synthesis from Dynamic Monocular Video Chen Gao, Ayus

Chen Gao 139 Dec 28, 2022
Dynamic vae - Dynamic VAE algorithm is used for anomaly detection of battery data

Dynamic VAE frame Automatic feature extraction can be achieved by probability di

null 10 Oct 7, 2022
Implementation for the EMNLP 2021 paper "Interactive Machine Comprehension with Dynamic Knowledge Graphs".

Interactive Machine Comprehension with Dynamic Knowledge Graphs Implementation for the EMNLP 2021 paper. Dependencies apt-get -y update apt-get instal

Xingdi (Eric) Yuan 19 Aug 23, 2022
This repo contains the pytorch implementation for Dynamic Concept Learner (accepted by ICLR 2021).

DCL-PyTorch Pytorch implementation for the Dynamic Concept Learner (DCL). More details can be found at the project page. Framework Grounding Physical

Zhenfang Chen 31 Jan 6, 2023
PyTorch implementation of NIPS 2017 paper Dynamic Routing Between Capsules

Dynamic Routing Between Capsules - PyTorch implementation PyTorch implementation of NIPS 2017 paper Dynamic Routing Between Capsules from Sara Sabour,

Adam Bielski 475 Dec 24, 2022
Dynamic wallpaper generator.

Wiki • About • Installation About This project is a dynamic wallpaper changer. It waits untill you turn on the music, downloads album cover if it's po

null 3 Sep 18, 2021
A face dataset generator with out-of-focus blur detection and dynamic interval adjustment.

A face dataset generator with out-of-focus blur detection and dynamic interval adjustment.

Yutian Liu 2 Jan 29, 2022