Giter Club home page Giter Club logo

block-shuffle's Introduction

Block Shuffle: A Method for High-resolution Fast Style Transfer with Limited Memory

Introduction

For high-resolution images, most mobile devices and personal computers cannot stylize them due to memory limitations. To solve this problem, we proposed a novel method named block shuffle, which can stylize high-resolution images with limited memory. In our experiments, we used Logan Engstrom's implementation of Fast Style Transfer as the baseline. In this repository, we provided the source code and 16 trained models. In addition, we developed an Android demo app, if you are interested in it, please click here.

Requirements

  1. CUDA 9, cudnn 7
  2. Python 3.6
  3. Python packages: tensorflow-gpu==1.9, opencv-python, numpy

High-resolution Image Stylization

Trained Fast Style Transfer Models

#01 #02 #03 #04 #05 #06 #07 #08
style style style style style style style style
#09 #10 #11 #12 #13 #14 #15 #16
style style style style style style style style

Baseline

Use baseline.py to stylize a high-resolution image. A GPU with 12GB memory can stylize up to 4000*4000 images (if your GPU doesn't have enough memory, it will throw an OOM error). Example usage:

python baseline.py --input examples/content/xxx.jpg \
  --output examples/result/xxx.jpg \
  --model models/01/model.pb \
  --gpu 0

Feathering-based Method

Use feathering-based.py to stylize a high-resolution image. This method is very simple, but it doesn't work well. Example usage:

python feathering-based.py --input examples/content/xxx.jpg \
  --output examples/result/xxx.jpg \
  --model models/01/model.pb \
  --gpu 0

Block Shuffle Method (Ours)

Use block_shuffle.py to stylize a high-resolution image. In our experiments, we set the max-width to 1000. If your GPU cannot stylize a 1000*1000 image, you can change this parameter to a smaller value. Example usage:

python block_shuffle.py --input examples/content/xxx.jpg \
  --output examples/result/xxx.jpg \
  --model models/01/model.pb \
  --max-width 1000 \
  --gpu 0

Training Style Transfer Networks

Download the COCO2014 Dataset and the Pre-trained VGG-19

We provided 16 trained fast style transfer models. If you want to train a new model, please download the COCO2014 dataset and the pre-trained VGG-19. If not, you can skip this step.

You can run setup.sh to download the COCO2014 dataset and the pre-trained VGG-19. Or you can download them from the following link (place them in data/):

  1. COCO2014 dataset
  2. pre-trained VGG-19

Train

Use style.py to train a new style transfer network. Training takes 26 hours on a Nvidia Telas K80 GPU. Example usage:

python style.py --style examples/style/style.jpg \
  --checkpoint-dir checkpoint/style01 \
  --test examples/content/chicago.jpg \
  --test-dir checkpoint/style01

Export

Use export.py to export .pb files. Example usage:

python export.py --input checkpoint/xxx/fns.ckpt \
  --output checkpoint/xxx/models.pb \
  --gpu 0 

Some Experimental Results

Style Content Baseline Baseline+Feathering Baseline+Block Shuffle (Ours)
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style
style style style style style

block-shuffle's People

Contributors

czczup avatar

Stargazers

 avatar

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.