CartoonGAN

CartoonGAN - my attempt to implement it

Within this repo, I try to implement a cartoon GAN as described in this paper [1] with PyTorch.

result example

Generate dataset

For training the GAN, photos and cartoon images are needed. I provide scripts to locally download these images from public and legally-to-use sources. As this are not the same input data as used in the paper, this may be a point of discussion. See the following sections for more information about the data I used.

Cartoon images

In the original paper, the data was produced by extracting images from anime movies, e.g. the movie "Spirited Away" by Miyazaki Hayao.
Due to copyright reasons I tried to find an alternative dataset, which I have found in the safebooru
[2] dataset from kaggle. Problem of this procedure are the different creators and their different styles of the images. This will lead to training data from which it is hard to learn from. This will not train the network properly I think, but I give it a try. In the paper, only one style from one artist is used.

I get the cartoon part of the dataset for my implementation of the cartoon GAN the following way: This step is resumeable.

Edge-smoothed version of cartoon images

To make the GAN better learn to produce clear edges in the cartoon image, the model is trained with an edge-smoothed version on every cartoon image, too. In the paper, the edges are first detected by canny-edge, then the edges are dilated and smoothed with gaussian smoothing. In my implementation, I do the canny edges, the dilation and the gaussian blur with openCV and I make the white backbground transparent and paste the edges back on the original image with Pillow.

I create a edge-smoothed version of every cartoon image:
This step is resumeable.

Photos

In the paper, photos are downloaded from flickr. In my implementation I try to use the COCO [3] dataset, especially the category person.
I get the photos for the dataset as follows:

My implementation for this COCO part download uses snippets for the main download part of the provided Demo-Implementation of the PythonAPI for the COCO-API from the project in [4], Credits and thanks to the authors!