Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eriknomitch/f3a0c682dbb2207d36ae547a4f1c6ea6 to your computer and use it in GitHub Desktop.
Save eriknomitch/f3a0c682dbb2207d36ae547a4f1c6ea6 to your computer and use it in GitHub Desktop.
Installing Dependencies for fast-neural-doodle

Installing Dependencies for fast-neural-doodle

Install Torch

Torch / Getting Started

cd

git clone https://github.com/torch/distro.git ~/torch --recursive

cd ~/torch; bash install-deps;

./install.sh

sudo apt-get install python-pip

sudo pip install numpy scipy h5py sklearn imread pillow protobuf

# Exit any shells

Install torch-hd5

GitHub / torch-hd5 / Usage

cd

sudo apt-get install libhdf5-serial-dev hdf5-tools luarocks

git clone https://github.com/deepmind/torch-hdf5

cd torch-hdf5

luarocks make hdf5-0-0.rockspec LIBHDF5LIBDIR="/usr/lib/x8664-linux-gnu/"

Install Nvidia CUDA

Visit the CUDA downloads page

Navigate through until you find the .deb.

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb

sudo apt-get update

sudo apt-get install cuda

Install fast-neural-doodle

GitHub / fast-neural-doodle

cd

git clone https://github.com/DmitryUlyanov/fast-neural-doodle.git

cd fast-neural-doodle

cd data/pretrained && bash download_models.sh && cd ../..

cd

sudo apt-get install libprotobuf-dev protobuf-compiler nvidia-cuda-toolkit

luarocks install loadcaffe

# NOTE: This step requires <= gcc v.4.9 to compile cutorch.
#
# It's not clean, but you if you run into issues, you can hack around it with this:
# 
# sudo apt-get install gcc-4.9
# cd /usr/bin
# ls -l | grep gcc # NOTE WHICH gcc-* VERSION THE GCC SYMBOLIC LINK IS POINTING TO
# sudo rm gcc
# sudo ln -s gcc-4.9 gcc
#
# And revert later with
#
# cd /usr/bin
# sudo rm gcc
# sudo ln -s gcc-<YOUR-ORIGINAL-VERSION> gcc
luarocks install cutorch

luarocks install cunn

Install My Helper Script (Optional)

Add this file at ~/run-fast-neural-doodle:

#!/bin/bash

# ------------------------------------------------
# GLOBALS ----------------------------------------
# ------------------------------------------------

# ------------------------------------------------
# USAGE ------------------------------------------
# ------------------------------------------------
function _usage() {
  "usage: $0 <N-COLORS>"
  exit 1
}

function _create_masks_hd5() {
  python get_mask_hdf5.py --n_colors=$1 --style_image=$HOME/source.png --style_mask=$HOME/mask.jpg --target_mask=$HOME/mask.png && \
 th fast_neural_doodle.lua -masks_hdf5 masks.hdf5
}

function _run_fast_neural_doodle() {
  cd ~/fast-neural-doodle || exit 1

  if ! _create_masks_hd5 $1; then
    echo "fatal: Could not create hdf5 masks."
    exit 1
  fi

  mkdir ~/out

  mv *.png ~/source.png ~/*mask*.png out/

  cd

  test -f out.tar.gz && rm out.tar.gz

  tar -cvzf out.tar.gz out && rm -rf out
}

# ------------------------------------------------
# MAIN -------------------------------------------
# ------------------------------------------------

if [[ -z $1 ]] ; then
  _usage
fi

_run_fast_neural_doodle $*

Execute this script with the number of colors as an argument. Example:

cd
./run-fast-neural-doodle 3

NOTE: If your mask includes white, that counts towards your total number of colors.

This will process your images from ~/source.png ~/style_mask.png and ~/target_mask.png with fast-neural-doodle and output ~/out.tar.gz containing the resulting rendered frames (and the originals).


See GitHub / fast-neural-doodle for more on usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment