Git Product home page Git Product logo

warpgan's Introduction

WarpGAN: Automatic Caricature Generation

By Yichun Shi, Debayan Deb and Anil K. Jain

A tensorflow implementation of WarpGAN, a fully automatic network that can generate caricatures given an input face photo. Besides transferring rich texture styles, WarpGAN learns to automatically predict a set of control points that can warp the photo into a caricature, while preserving identity. We introduce an identity-preserving adversarial loss that aids the discriminator to distinguish between different subjects. Moreover, WarpGAN allows customization of the generated caricatures by controlling the exaggeration extent and the visual styles.

Tensorflow release

Currently this repo is compatible with Tensorflow r1.9.

News

Date Update
2019-04-10 Testing Code
2019-04-07 Training Code
2019-04-05 Initial Code Upload

Citation

@article{warpgan,
  title = {WarpGAN: Automatic Caricature Generation},
  author = {Shi, Yichun, Deb, Debayan and Jain, Anil K.},
  booktitle = {CVPR},
  year = {2019}
}

Usage

Note: In this section, we assume that you are always in the directory $WARPGAN_ROOT/

Preprocessing

  1. Download the original images of WebCaricature dataset and unzip them into data/WebCaricature/OriginalImages. Rename the images by running
    python data/rename.py
  2. Then, normalize all the faces by running the following code:
    python align/align_dataset.py data/landmarks.txt data/webcaricacture_aligned_256 --scale 0.7
    The command will normalize all the photos and caricatures using the landmark points pre-defined in the WebCaricature protocol (we use only 5 landmarks). Notice that during deployment, we will use MTCNN to detect the face landmarks for images not in the dataset.

Training

  1. Before training, you need to download the discriminator model to initialize the parameters of the disrcimanator, which is pre-trained as an identity classifier. Unzip the files under pretrained/discriminator_casia_256/.

  2. The configuration files for training are saved under config/ folder, where you can define the dataset prefix, training list, model file and other hyper-parameters. Use the following command to run the default training configuration:

    python train.py config/default.py

    The command will create an folder under log/default/ which saves all the checkpoints, test samples and summaries. The model directory is named as the time you start training.

Testing

  • Run the test code in the following format:
    python test.py /path/to/model/dir /path/to/input/image /prefix/of/output/image
  • For example, if you want to use the pre-trained model, download the model and unzip it into pretrained/warpgan_pretrained. Then, run the following command to generate 5 images for captain marvel of different random styles:
    python test.py pretrained/warpgan_pretrained \
    data/example/CaptainMarvel.jpg \
    result/CaptainMarvel \
    --num_styles 5
  • You can also change the warping extent by using the --scale argument. For example, the following command doubles the displacement of the warpping control points:
    python test.py pretrained/warpgan_pretrained \
    data/example/CaptainMarvel.jpg \
    result/CaptainMarvel \
    --num_styles 5 --scale 2.0

Pre-trained Model

Discriminator Initializaiton:

Google Drive

WarpGAN:

Google Drive

warpgan's People

Contributors

ronny3050 avatar seasonsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

warpgan's Issues

code problem

python align/align_dataset.py data/landmarks.txt data/webcaricacture_aligned_256 --scale 0.7

'webcaricacture_aligned_256' should be 'webcaricature_aligned_256'

Use of warping module independently

Hey, great work! Just a question. It is mentioned in the paper that

The entire warping module is differentiable and can be trained as part of an end-to-end system.

I looked into the code and found (If I am not wrong) that the following lines are responsible for warping.

WarpGAN/warpgan.py

Lines 68 to 70 in 794e24d

encode_B, styles_B = self.encoder(self.images_B)
deform_BA, render_BA, ldmark_pred, ldmark_diff = self.decoder(encode_B, self.scales_B, None)
So, is there any way of using this encoder and decoder by only using the pretained weights available?

some questions on the control points

Thanks for this repo!
I have some questions on the prediction of control points.

(1). Why the image_size inputted to the decoder is (112 * 112)?

(2). What's the use of ldmark_mean?

(3). How to visualize the control points? (I have tried to visualize the control points by outputting Decoder/WarpController/ldmark_pred and Decoder/WarpController/ldmark_diff, but some of them are out of the image. What's more, when using different warping scale, the output image changes, but ldmark_diff remains constant...)

How to use get_styles in wargan.py?

I find a function get_styles() in wargan.py and I tried to use it. But found its result is not ~N(0; I). Could someone tell me why and how to use it?

Why the dimension of the patch logit for **each example** is in 64*3 not only 3?

Why the dimension of the patch logit for each example is in 64*3 not only 3?

related code shown below

def discriminator(images, num_classes, bottleneck_size=512, keep_prob=1.0, phase_train=True,
weight_decay=0.0, reuse=None, scope='Discriminator'):
with slim.arg_scope([slim.conv2d, slim.fully_connected],
weights_regularizer=slim.l2_regularizer(weight_decay),
activation_fn=leaky_relu,
normalizer_fn=None,
normalizer_params=batch_norm_params):
with tf.variable_scope(scope, [images], reuse=reuse):
with slim.arg_scope([slim.batch_norm, slim.dropout],
is_training=phase_train):

            print('{} input shape:'.format(scope), [dim.value for dim in images.shape])

            net =conv(images, 32, kernel_size=4, stride=2, scope='conv1')
            print('module_1 shape:', [dim.value for dim in net.shape])
            
            net = conv(net, 64, kernel_size=4, stride=2, scope='conv2')
            print('module_2 shape:', [dim.value for dim in net.shape])

            net = conv(net, 128, kernel_size=4, stride=2, scope='conv3')
            print('module_3 shape:', [dim.value for dim in net.shape])

         
            net = conv(net, 256, kernel_size=4, stride=2, scope='conv4')
            print('module_4 shape:', [dim.value for dim in net.shape])

            net = conv(net, 512, kernel_size=4, stride=2, scope='conv5')
            print('module_5 shape:', [dim.value for dim in net.shape])


            # Patch Discrminator
            patch5_logits = slim.conv2d(net, 3, 1, activation_fn=None, normalizer_fn=None, scope='patch5_logits')
            patch_logits = tf.reshape(patch5_logits, [-1,3])

How can I restore my training?

I use google colab to train WarpGAN model.
Because the training time is too long, I have to stop it and save my log files.

Now, I want to continue my training.
Can I restore my training?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.