Precomputed Real-Time Texture Synthesis with Markovian Generative Adversarial Networks

Related tags

Deep Learning MGANs
Overview

MGANs

Training & Testing code (torch), pre-trained models and supplementary materials for "Precomputed Real-Time Texture Synthesis with Markovian Generative Adversarial Networks".

See this video for a quick explaination for our method and results.

Setup

As building Torch with the latest CUDA is a troublesome work, we recommend following the following steps to people who want to reproduce the results: It has been tested on Ubuntu with CUDA 10.

Step One: Install CUDA 10 and CUDNN 7.6.2

If you have a fresh Ubuntu, we recommend Lambda Stack which helps you install the latest drivers, libraries, and frameworks for deep learning. Otherwise, you can install the CUDA toolkit and CUDNN from these links:

Step Two: Install Torch

git clone https://github.com/nagadomi/distro.git ~/torch --recursive
cd ~/torch
./install-deps
./clean.sh
./update.sh

. ~/torch/install/bin/torch-activate
sudo apt-get install libprotobuf-dev protobuf-compiler
luarocks install loadcaffe

Demo

cd code
th demo_MGAN.lua

Training

Simply cd into folder "code/" and run the training script.

th train.lua

The current script is an example of training a network from 100 ImageNet photos and a single painting from Van Gogh. The input data are organized in the following way:

  • "Dataset/VG_Alpilles_ImageNet100/ContentInitial": 5 training ImageNet photos to initialize the discriminator.
  • "Dataset/VG_Alpilles_ImageNet100/ContentTrain": 100 training ImageNet photos.
  • "Dataset/VG_Alpilles_ImageNet100/ContentTest": 10 testing ImageNet photos (for later inspection).
  • "Dataset/VG_Alpilles_ImageNet100/Style": Van Gogh's painting.

The training process has three main steps:

  • Use MDAN to generate training images (MDAN_wrapper.lua).
  • Data Augmentation (AG_wrapper.lua).
  • Train MGAN (MDAN_wrapper.lua).

Testing

The testing process has two steps:

  • Step 1: call "th release_MGAN.lua" to concatenate the VGG encoder with the generator.
  • Step 2: call "th demo_MGAN.lua" to test the network with new photos.

Display

You can use the browser based display package to display the training process for both MDANs and MGANs.

  • Install: luarocks install https://raw.githubusercontent.com/szym/display/master/display-scm-0.rockspec
  • Call: th -ldisplay.start
  • See results at this URL: http://localhost:8000

Example

We chose Van Gogh's "Olive Trees with the Alpilles in the Background" as the reference texture.

We then transfer 100 ImageNet photos into the same style with the proposed MDANs method. MDANs take an iterative deconvolutional approach, which is similar to "A Neural Algorithm of Artistic Style" by Leon A. Gatys et al. and our previous work "CNNMRF". Differently, it uses adversarial training instead of gaussian statistics ("A Neural Algorithm of Artistic Style) or nearest neighbour search "CNNMRF". Here are some transferred results from MDANs:

The results look nice, so we know adversarial training is able to produce results that are comparable to previous methods. In other experiments we observed that gaussian statistics work remarkable well for painterly textures, but can sometimes be too flexible for photorealistic textures; nearest-neighbor search preserve photorealistic details but can be too rigid for deformable textures. In some sense MDANs offers a relatively more balanced choice with advaserial training. See our paper for more discussoins.

Like previous deconvolutional methods, MDANs is VERY slow. A Nvidia Titan X takes about one minute to transfer a photo of 384 squared. To make it faster, we replace the deconvolutional process by a feed-forward network (MGANs). The feed-forward network takes long time to train (45 minutes for this example on a Titan X), but offers significant speed up in testing time. Here are some results from MGANs:

It is our expectation that MGANs will trade quality for speed. The question is: how much? Here are some comparisons between the result of MDANs and MGANs:

In general MDANs (middle) give more stylished results, and does a much better job at homegenous background areas (the last two cases). But sometimes MGANs (right) is able to produce comparable results (the first two).

And MGANs run at least two orders of magnitudes faster.

Final remark

There are concurrent works that try to make deep texture synthesis faster. For example, Ulyanov et al. and Johnson et al. also achieved significant speed up and very nice results with a feed-forward architecture. Both of these two methods used the gaussian statsitsics constraint proposed by Gatys et al.. We believe our method is a good complementary: by changing the gaussian statistics constraint to discrimnative networks trained with Markovian patches, it is possible to model more complex texture manifolds (see discussion in our paper).

Last, here are some prelimiary results of training a MGANs for photorealistic synthesis. It learns from 200k face images from CelebA. The network then transfers VGG_19 encoding (layer ReLU5_1) of new face images (left) into something interesting (right). The synthesized faces have the same poses/layouts as the input faces, but look like different persons :-)

Acknowledgement

Comments
  • Out of memory

    Out of memory

    I'm getting out-of-memory errors whenever I try running demo_MGANs.lua with opt.max_length > 128, even though the Readme says it should work for much larger image sizes. I'm running on a machine with 4 Titan-X's with 12Gb each. Here's the error message with opt.maxlength=256:

    th demo_MGANs.lua 
    mkdir: cannot create directory ‘output/’: File exists
    *****************************************************   
    Testing:    
    *****************************************************   
    THCudaCheck FAIL file=/tmp/luarocks_cutorch-scm-1-4622/cutorch/lib/THC/generic/THCStorage.cu line=41 error=2 : out of memory
    /home/hertzman/torch/install/bin/luajit: /home/hertzman/torch/install/share/lua/5.1/nn/Container.lua:69: 
    In 25 module of nn.Sequential:
    /home/hertzman/torch/install/share/lua/5.1/nn/THNN.lua:109: cuda runtime error (2) : out of memory at /tmp/luarocks_cutorch-scm-1-4622/cutorch/lib/THC/generic/THCStorage.cu:41
    stack traceback:
        [C]: in function 'v'
        /home/hertzman/torch/install/share/lua/5.1/nn/THNN.lua:109: in function 'SpatialFullConvolution_updateOutput'
        ...orch/install/share/lua/5.1/nn/SpatialFullConvolution.lua:74: in function <...orch/install/share/lua/5.1/nn/SpatialFullConvolution.lua:68>
        [C]: in function 'xpcall'
        /home/hertzman/torch/install/share/lua/5.1/nn/Container.lua:65: in function 'rethrowErrors'
        ...e/hertzman/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
        demo_MGANs.lua:57: in main chunk
        [C]: in function 'dofile'
        ...zman/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
        [C]: at 0x00406670
    

    I'm new to Torch; sorry if this is a newbie question. Can you help?

    opened by hertzmann 5
  • Reproducing results

    Reproducing results

    The results I'm getting on the VG style aren't very good. I'd tried reproducing Figure 12, upper left, using this input image: Tubingen

    With max_length=1024, the result looks like tubingen_mgans

    Adjusting the image size and noise level parameters didn't improve things.

    opened by hertzmann 3
  • THCudaCheck FAIL : Out of memory

    THCudaCheck FAIL : Out of memory

    i just run train.lua on code/ with this spec

    i7-7700 GTX 1080 8GB Ram 16 GB DDR4 with storage 200gb

    is there a chance could be my gpu can't handle the size of image? anyone experienced this ? can you help me solve it ?

    opened by timotirta 0
  • Transfer of facial features

    Transfer of facial features

    Hi, thank you for such interesting project!

    In the paper you mentioned, that "current method failed to transfer facial features between two difference face photos" and as I understood, your advice in this case is "to couple model with the learning of object class from DCGAN so the local statistics is better conditioned". Can you please explain what does "learning of object class from DCGAN" mean? Thanks.

    opened by bitlater 0
  • not enough RAM

    not enough RAM

    Hello, first of all thank you for uploading your training code!

    Some issues I encountered:

    1. train.lua was missing lib/tv.lua and lib/tv2.lua. I used the tv.lua from your cnn-mrf repository and commented out the line for tv2.

    2. new users, don't forget to set flag_MDAN = true, flag_AG =true, flag_MGAN = true in train.lua if you actually want it to do the whole training process. Only the first step, flag_MDAN, is set true by default.

    3. I had to set opt.batchSize in MGAN_wrapper.lua from 64 to 32 since my 4 GB GPU ran out of memory at this step.

    4. In order to successfully run release_MGAN.lua, I had to manually move the file netS_1.t7 from Dataset/VG_Alpilles_ImageNet100/MDAN to Dataset/VG_Alpilles_ImageNet100/MGAN.

    5. Finally, when running demo_MGAN.lua, I am stuck with:

    `/home/atonn/torch/install/bin/luajit: /home/atonn/torch/install/share/lua/5.1/nn/Container.lua:67: In 23 module of nn.Sequential: /home/atonn/torch/install/share/lua/5.1/nn/THNN.lua:109: bad argument #2 to 'v' (input channels and nInputPlane dont match at /tmp/luarocks_cunn-scm-1-2642/cunn/lib/THCUNN/SpatialConvolutionMM.cu:29) stack traceback: [C]: in function 'v' /home/atonn/torch/install/share/lua/5.1/nn/THNN.lua:109: in function 'SpatialConvolutionMM_updateOutput' ...id/torch/install/share/lua/5.1/nn/SpatialConvolution.lua:111: in function <...id/torch/install/share/lua/5.1/nn/SpatialConvolution.lua:107> [C]: in function 'xpcall' /home/atonn/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors' /home/atonn/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward' demo_MGAN.lua:56: in main chunk [C]: in function 'dofile' ...poid/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk [C]: at 0x00406670

    WARNING: If you see a stack trace below, it doesn't point to the place where this error occured. Please use only the one above. stack traceback: [C]: in function 'error' /home/atonn/torch/install/share/lua/5.1/nn/Container.lua:67: in function 'rethrowErrors' /home/atonn/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward' demo_MGAN.lua:56: in main chunk [C]: in function 'dofile' ...poid/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk [C]: at 0x00406670`

    I suppose that's what I get for messing with the batch size? When substituting my MGAN file with the provided pretrained file it runs just fine. Any help would be appreciated. Cheers :D

    opened by atonn 3
Owner
null
Pytorch implementation for reproducing StackGAN_v2 results in the paper StackGAN++: Realistic Image Synthesis with Stacked Generative Adversarial Networks

StackGAN-v2 StackGAN-v1: Tensorflow implementation StackGAN-v1: Pytorch implementation Inception score evaluation Pytorch implementation for reproduci

Han Zhang 809 Dec 16, 2022
Multi-View Consistent Generative Adversarial Networks for 3D-aware Image Synthesis (CVPR2022)

Multi-View Consistent Generative Adversarial Networks for 3D-aware Image Synthesis Multi-View Consistent Generative Adversarial Networks for 3D-aware

Xuanmeng Zhang 78 Dec 10, 2022
An implementation of "Optimal Textures: Fast and Robust Texture Synthesis and Style Transfer through Optimal Transport"

Optex An implementation of Optimal Textures: Fast and Robust Texture Synthesis and Style Transfer through Optimal Transport for TU Delft CS4240. You c

Hans Brouwer 33 Jan 5, 2023
Code for the paper "TadGAN: Time Series Anomaly Detection Using Generative Adversarial Networks"

TadGAN: Time Series Anomaly Detection Using Generative Adversarial Networks This is a Python3 / Pytorch implementation of TadGAN paper. The associated

Arun 92 Dec 3, 2022
Real-Time-Student-Attendence-System - Real Time Student Attendence System

Real-Time-Student-Attendence-System The Student Attendance Management System Pro

Rounak Das 1 Feb 15, 2022
Code release for NeX: Real-time View Synthesis with Neural Basis Expansion

NeX: Real-time View Synthesis with Neural Basis Expansion Project Page | Video | Paper | COLAB | Shiny Dataset We present NeX, a new approach to novel

null 536 Dec 20, 2022
MatryODShka: Real-time 6DoF Video View Synthesis using Multi-Sphere Images

Main repo for ECCV 2020 paper MatryODShka: Real-time 6DoF Video View Synthesis using Multi-Sphere Images. visual.cs.brown.edu/matryodshka

Brown University Visual Computing Group 75 Dec 13, 2022
Code release for NeX: Real-time View Synthesis with Neural Basis Expansion

NeX: Real-time View Synthesis with Neural Basis Expansion Project Page | Video | Paper | COLAB | Shiny Dataset We present NeX, a new approach to novel

null 538 Jan 9, 2023
Minimal PyTorch implementation of Generative Latent Optimization from the paper "Optimizing the Latent Space of Generative Networks"

Minimal PyTorch implementation of Generative Latent Optimization This is a reimplementation of the paper Piotr Bojanowski, Armand Joulin, David Lopez-

Thomas Neumann 117 Nov 27, 2022
StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

null 3k Jan 8, 2023
[ICLR 2021, Spotlight] Large Scale Image Completion via Co-Modulated Generative Adversarial Networks

Large Scale Image Completion via Co-Modulated Generative Adversarial Networks, ICLR 2021 (Spotlight) Demo | Paper [NEW!] Time to play with our interac

Shengyu Zhao 373 Jan 2, 2023
Regularizing Generative Adversarial Networks under Limited Data (CVPR 2021)

Regularizing Generative Adversarial Networks under Limited Data [Project Page][Paper] Implementation for our GAN regularization method. The proposed r

Google 148 Nov 18, 2022
NR-GAN: Noise Robust Generative Adversarial Networks

NR-GAN: Noise Robust Generative Adversarial Networks (CVPR 2020) This repository provides PyTorch implementation for noise robust GAN (NR-GAN). NR-GAN

Takuhiro Kaneko 59 Dec 11, 2022
Generating Anime Images by Implementing Deep Convolutional Generative Adversarial Networks paper

AnimeGAN - Deep Convolutional Generative Adverserial Network PyTorch implementation of DCGAN introduced in the paper: Unsupervised Representation Lear

Rohit Kukreja 23 Jul 21, 2022
Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) in PyTorch

alias-free-gan-pytorch Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) This implementation

Kim Seonghyeon 502 Jan 3, 2023
PyTorch implementations of Generative Adversarial Networks.

This repository has gone stale as I unfortunately do not have the time to maintain it anymore. If you would like to continue the development of it as

Erik Linder-Norén 13.4k Jan 8, 2023
Image Deblurring using Generative Adversarial Networks

DeblurGAN arXiv Paper Version Pytorch implementation of the paper DeblurGAN: Blind Motion Deblurring Using Conditional Adversarial Networks. Our netwo

Orest Kupyn 2.2k Jan 1, 2023
Partial implementation of ODE-GAN technique from the paper Training Generative Adversarial Networks by Solving Ordinary Differential Equations

ODE GAN (Prototype) in PyTorch Partial implementation of ODE-GAN technique from the paper Training Generative Adversarial Networks by Solving Ordinary

Somshubra Majumdar 15 Feb 10, 2022
Code for "On the Effects of Batch and Weight Normalization in Generative Adversarial Networks"

Note: this repo has been discontinued, please check code for newer version of the paper here Weight Normalized GAN Code for the paper "On the Effects

Sitao Xiang 182 Sep 6, 2021