16

GitHub - ipsingh06/ml-desnapify

 5 years ago
source link: https://github.com/ipsingh06/ml-desnapify
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Desnapify

Desnapify is a deep convolutional generative adversarial network (DCGAN) trained to remove Snapchat filters from selfie images. It is based on the excellent pix2pix project by Isola et al., and specifically the Keras implementation by Thibault de Boissiere.

The following figure shows a few examples of the output of the Desnapify on doggy filter selfies. Top row is the input, middle row is the Desnapified output, bottom row is the target.

Desnapification of the doggy filter

Desnapify currently includes a model trained to remove the doggy filter from images of size 512x512. It can be easily trained to remove other filters as well. This is left for future work.

Requirements

  • Python 3.5
  • Tensorflow (tensorflow-gpu with cuDNN is recommended)
  • Keras (Note: as of this writing the latest release of Keras 2.2.4 has a bug which prevents the model from being loaded. You must install the latest Keras from source as described here)
  • Python modules listed in requirements.txt

Setup

  1. Set up a virtualenv

    mkvirtualenv -p python3.5 desnapify
  2. Clone this repo

    git clone https://github.com/ipsingh06/ml-desnapify.git
  3. Install the python modules

    cd ml-desnapify
    pip install -r requirements.txt
  4. Install Keras from source as described here

Using the provided model to Desnapify images

This section describes how to use the provided trained model to remove the doggy filter from your images. The provided script src/models/predict_model.py takes care of scaling the images. We will be using the samples provided in data/raw/samples/doggy.

  1. Download the pre-trained model weights.

    python src/models/download_weights.py
  2. Run the prediction script. This will cycle through and display the resulting output images alongside their inputs.

    python src/models/predict_model.py \
        models/doggy-512x512-v1/gen_weights_epoch030.h5 \
        data/raw/samples/doggy \
        --image_size 512 512

    To store the results into images files, specify the --output <path to directory> option. You can also specify --no_concat to store the output image only.

    python src/models/predict_model.py \
        models/doggy-512x512-v1/gen_weights_epoch030.h5 \
        data/raw/samples/doggy \
        --image_size 512 512 \
        --output out \
        --no_concat

    Check the out directory for output images.

Training the model

This section describes how to train the model yourself. This requires generating pairs of images with and without the filter applied. The provided data generation script includes functionality to apply the doggy filter to images. It can be extended to apply other Snapchat filters as well.

The following figure shows the pipeline for generating training data from selfie images. Data pipeline

The provided model was trained with the People's Republic of Tinder dataset available on Kaggle. You should be able to use any dataset of selfie images for training.

Note: the training script uses multiprocess queues for batch loading, so you don't have to worry about fitting your entire dataset into memory. Use as large a dataset as you like.

  1. Place the set of selfie images in data/raw/dataset directory.

  2. Run the data generation script to generate image-pairs with and without the doggy filter.

    python src/data/make_dataset.py apply-filter \
        data/raw/dataset \
        data/interim/dataset \
        --output_size 512 512 \
        --no_preserve_dir

    This script will create two directories data/interim/dataset/orig and data/interim/dataset/transformed. The first contains images to be used as input to the model, and the second images to be used as the target.

  3. Run the data generation script again to split the dataset into training, validation and testing sets. This also packages all three datasets into a single HDF5 file.

    python src/data/make_dataset.py create-hdf5 \
        data/interim/dataset \
        data/processed/dataset.h5

    This script will create the file data/processed/dataset.h5

  4. We should verify that the dataset was created properly.

    python src/data/make_dataset.py check-hdf5 data/processed/dataset.h5
  5. Finally, we can run the training script.

    python src/models/train_model.py \
        data/processed/dataset.h5 \
        --batch_size 4 \
        --patch_size 128 128 \
        --epochs 30

    We can see how well the model is learning and performing by looking at current_batch_training.png and current_batch_validation.png images in reports/logs directory.

    We can also visualize the performance metrics using Tensorboard:

    tensorboard --logdir=reports/logs

    Tensorboard

  6. After training completes the model weights are saved in models/. To test the model, see the Using the provided model section.

Acknowledgments

  1. pix2pix project by Isola et al.

  2. Keras implementation of pix2pix by Thibault de Boissiere

  3. The apply-filters script is based off snapchat-filters-opencv


Recommend

  • 189
    • Github github.com 6 years ago
    • Cache

    GitHub - matryx/calcflow

    Calcflow A Virtual Reality Tool for Mathematical Modeling! The repository contains the open-sourced code to Calcflow, a powerful mathematical visualization tool designed to give students, educators, and engineers a better grasp on...

  • 209
    • Github github.com 6 years ago
    • Cache

    Release 5.0 · javaee/glassfish · GitHub

    Release 5.0 · javaee/glassfish · GitHub ...

  • 457

    README.md ViaBTC Exchange Server ViaBTC Exchange Server is a trading backend with high-speed performance, designed for cryptocurrency exchanges. It can...

  • 198
    • Github github.com 6 years ago
    • Cache

    GitHub - Kyubyong/pytorch_exercises

    Pytorch Exercises Pytorch is one of the most popular deep learning libraries as of 2017. One possible way of familiarizing yourself with it, I think, is to practice with simple quizzes. That's where this project comes in. The outline will...

  • 108
    • Github github.com 6 years ago
    • Cache

    GitHub - Bytom/bytom: Bytom

    Bytom Official golang implementation of the Bytom protocol. Automated builds are available for stable releases and the unstable master branch. Binary archives are published at

  • 335
    • Github github.com 6 years ago
    • Cache

    GitHub - tmux/tmux: tmux source code

    Welcome to tmux! tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattach...

  • 174
    • Github github.com 6 years ago
    • Cache

    GitHub - Alexander-Miller/treemacs

  • 217

    Spring Boot

  • 132
    • Github github.com 6 years ago
    • Cache

    GitHub - savvisingh/DateRangePicker

    Date Range Picker Date Range Picker is a Calendar Picker View to show a Customized Date Range Picker with improved UI and functionality to add subtitles to the dates Screenshots Usage Add Calendar...

  • 376
    • 掘金 juejin.im 6 years ago
    • Cache

    玩转Github的新姿势-github-cli

    惊鸿一瞥 这是一个可以帮助你在命令行中完成Github的各种操作的cli工具。 创建它的初衷是因为我是一个命令行狂热爱好者,与此同时我也是一个Github的fans,每当我在命令行环境中进行开发工作时,如果此时我想看看Github上又诞生了什么新的有趣的开源项

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK