• Stars
    star
    112
  • Rank 310,446 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Data-parallel image stylization using Caffe.

style_transfer

Data-parallel image stylization using Caffe. Implements A Neural Algorithm of Artistic Style [1].

Dependencies:

The current preferred Python distribution for style_transfer is Anaconda (Python 3.6+ version). style_transfer will run faster with Anaconda than with other Python distributions due to its inclusion of the MKL BLAS (mathematics) library. In addition, if you are running Caffe without a GPU, style_transfer will run a great deal faster if compiled with MKL (BLAS := mkl in Makefile.config).

Cloud computing images are available with style_transfer and its dependencies preinstalled.

Command line arguments are documented in detail in the work-in-progress parameter usage guide.

Features

  • The image is divided into tiles which are processed one per GPU at a time. Since the tiles can be sized so as to fit into GPU memory, this allows arbitrary size images to be processed—including print size. Tile seam suppression is applied after every iteration so that seams do not accumulate and become visible. (ex: --size 2048 --tile-size 1024)
  • Images are processed at multiple scales. Each scale's final iterate is used as the initial iterate for the following scale. Processing a large image at smaller scales first markedly improves output quality.
  • Multi-GPU support (ex: --devices 0 1 2 3). Four GPUs, for instance, can process four tiles at a time.
  • Can perform simultaneous Deep Dream and image stylization.
  • L-BFGS [2] and Adam (gradient descent) [4] optimizers.

Examples

The obligatory Golden Gate Bridge + The Starry Night (van Gogh) style transfer (big version):

Golden Gate Bridge + The Shipwreck of the Minotaur (Turner) (big version):

barn and pond (Cindy Branham) + The Banks of the River (Renoir) (big version):

Installation

pycaffe and Anaconda (Python 3.6 version)

On macOS (with Homebrew-provided Boost.Python):

ANACONDA_HOME := $(HOME)/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		$(ANACONDA_HOME)/include/python3.6m \
		$(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
PYTHON_LIBRARIES := boost_python3 python3.6m
PYTHON_LIB := $(ANACONDA_HOME)/lib

The exact name of the Boost.Python library will differ on Linux but the rest should be the same.

Building pycaffe for Python 3.7 (macOS)

On macOS, you can install Python 3 and Boost.Python using Homebrew:

brew install python
brew install numpy
brew install boost-python3

Then insert these lines into Caffe's Makefile.config to build against the Homebrew-provided Python 3.7:

PYTHON_DIR := /usr/local/opt/python3/Frameworks/Python.framework/Versions/3.7
PYTHON_LIBRARIES := boost_python37 python3.7m
PYTHON_INCLUDE := $(PYTHON_DIR)/include/python3.7m \
	/usr/local/lib/python3.7/site-packages/numpy/core/include
PYTHON_LIB := $(PYTHON_DIR)/lib

make pycaffe ought to compile the Python 3 bindings now.

Note that on macOS you currently have to set an environment variable before running style_transfer to prevent a crash on forking:

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

Building pycaffe for Python 3.5 (Ubuntu 16.04)

Note that Python 3.6+ is required now and these instructions need to be updated.

On Ubuntu 16.04, follow Caffe's Ubuntu 15.10/16.04 install guide. The required Makefile.config lines for Python 3.5 are:

PYTHON_LIBRARIES := boost_python-py35 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
                  /usr/local/lib/python3.5/dist-packages/numpy/core/include
PYTHON_LIB := /usr/lib

Installing style_transfer's Python dependencies (all systems)

Using pip:

pip3 install -Ur requirements.txt

References

[1] L. Gatys, A. Ecker, M. Bethge, "A Neural Algorithm of Artistic Style"

[2] D. Liu, J. Nocedal, "On the limited memory BFGS method for large scale optimization"

[3] A. Mahendran, A. Vedaldi, "Understanding Deep Image Representations by Inverting Them"

[4] D. Kingma, J. Ba, "Adam: A Method for Stochastic Optimization"

[5] K. Simonyan, A. Zisserman, "Very Deep Convolutional Networks for Large-Scale Image Recognition"

More Repositories

1

k-diffusion

Karras et al. (2022) diffusion models for PyTorch
Python
1,263
star
2

v-diffusion-pytorch

v objective diffusion inference code for PyTorch.
Python
708
star
3

style-transfer-pytorch

Neural style transfer in PyTorch.
Python
442
star
4

v-diffusion-jax

v objective diffusion inference code for JAX.
Python
207
star
5

simulacra-aesthetic-models

Python
130
star
6

deep_dream

A parallel implementation of the Deep Dream image processing algorithm which is able to process arbitrarily large images.
Jupyter Notebook
100
star
7

consistency-models

A JAX implementation of the continuous time formulation of Consistency Models
Python
74
star
8

LDLM

Latent Diffusion Language Models
Python
66
star
9

cloob-training

CLOOB training (JAX) and inference (JAX and PyTorch)
Python
63
star
10

esgd

ESGD-M is a stochastic non-convex second order optimizer, suitable for training deep learning models, for PyTorch.
Python
58
star
11

mdmm

The Modified Differential Multiplier Method (MDMM) for PyTorch
Python
41
star
12

vgg_loss

A VGG-based perceptual loss function for PyTorch.
Python
38
star
13

jax-wavelets

The 2D discrete wavelet transform for JAX
Python
25
star
14

cond_transformer_2

A CLIP conditioned Decision Transformer.
Python
22
star
15

clip-guided-diffusion

CLIP Guided Diffusion
Python
14
star
16

mdmm-jax

Gradient-based constrained optimization for JAX
Python
14
star
17

tv-denoise

Total variation denoising for images.
Python
13
star
18

shared_ndarray

A pickleable wrapper for sharing NumPy ndarrays between processes using POSIX shared memory.
Python
13
star
19

pytorch-caffe-models

The original weights of some Caffe models, ported to PyTorch.
Python
10
star
20

pharmacokinetics

A Flask web application to calculate and plot drug concentration over time.
Python
10
star
21

pyparsing-highlighting

Syntax highlighting for prompt_toolkit and HTML with pyparsing.
Python
9
star
22

aiohttp_index

aiohttp.web middleware to serve index files (e.g. index.html) when static directories are requested.
Python
8
star
23

rope-flax

Rotary Position Embedding for Flax
Python
4
star
24

ucs

Implements the CAM02-UCS (Luo et al. (2006)) forward transform.
Python
4
star
25

philips-hue

A CLI tool to interface with Philips Hue lights.
Python
4
star
26

dice-mc

DiCE: The Infinitely Differentiable Monte-Carlo Estimator
Python
3
star
27

average

Exponentially weighted moving averages with initialization bias correction.
Python
3
star
28

synthraw

Synthesizes camera raw files
Python
2
star
29

huething

This is a work in progress to control my four Philips Hue bulbs.
Python
2
star
30

base58

Package base58 implements base58 encoding as used in Bitcoin addresses.
Go
2
star
31

crowsonkb.github.io

HTML
2
star
32

websynth

pNaCl-Csound based softsynth
JavaScript
2
star
33

color_schemer

A web application to translate color schemes between dark- and light-background.
Python
1
star
34

cluster

Package cluster performs hierarchical clustering of term vectors.
Go
1
star
35

gradient-maker3

A web application to generate color gradients using the CAM02-UCS colorspace.
Python
1
star
36

scihub-lookup

A Safari extension to look up the current page on Sci-Hub
JavaScript
1
star
37

fragments

Miscellaneous useful, reusable code fragments
Python
1
star
38

.zsh

My zsh configuration
Shell
1
star
39

randomness

Generates random secrets (passwords, etc).
Python
1
star