GoogLeNet DeepDreams @ OS X step by step guide for girls by Artem Zaborskiy

You're reading this because you’ve seen the original “inceptionism” gallery of hallucinating neural networks. This tutorial will help you to produce images like these, or like the ones in this article.

Initially, I wrote this how-to for myself just to make the life simpler when I move the things to another Mac.

Long story short, our goal is to force that Interactive Python Notebook working.


Preconditions:

  • you’re running the OS X Yosemite 10.10.* and
  • you have all updates installed
  • you’re familiar with git
  • you have at least 4GB of free storage (not a problem nowdays, right?)
  • you’re at least 16 years old female.

In brief, we’re about to set up the following (plus tons of invisible shit):


Ok, the start is here:

  1. scene in which the reader first becomes a writer

    Make sure you have Git installed. Open the terminal window and type

    git --version

    It should say something like

    git version 2.3.2 (Apple Git-55)

    If it does not, install git from http://git-scm.com/download/mac, then close the terminal window and open it again.

  2. scene in which the reader makes a version

    Type in the terminal window:

    make --version

    there are two scenarios:
    A) either you have developer tools installed and it prints a version number...
    B) OR you see something like

    xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

    .. and a dialog pops up. Push the Install button and meditate for 2 minutes. Repeat the scene 2 again and again until you end up with

    GNU Make 3.81 
    ...followed by some boring stuff.
  3. scene in which the reader meets The Anaconda

    We’re going to install Anaconda. It will strangle you in the end, but for today we need it. So, just get it and follow the instructions. When you’re done, type in the terminal window:

    conda --version

    it should answer

    conda 3.14.1
  4. scene in which the reader dives into beer

    Make sure you have Homebrew installed, type in terminal:

    brew list

    if it says

    command not found

    then go to http://brew.sh/ and do what they say (note, it will ask for your passwords during the installation).

    When Homebrew is ready, run the following. This will install the dependencies required by Caffe.

    sudo chown -R `whoami` /usr/local
    brew install -vd snappy leveldb gflags glog szip lmdb
    brew tap homebrew/science
    brew install opencv
    

    .. pray and proceed:

    brew install --build-from-source --with-python -vd protobuf
    brew install --build-from-source -vd boost boost-python

    Now, to make sure it was OK, type

    protoc --version

    and it should answer

    libprotoc 2.6.1

    Just in case, install protobuf dependency required for the python scripts. Use pip:

    pip install protobuf
    
  5. scene in which the reader is having Caffe, while Caffe is having the reader.

    Obtain Caffe source codes from github.

    cd ~/
    git clone https://github.com/BVLC/caffe.git
    cd caffe
    

    Now it's time to build the Caffe. Copy the Make file and open it for editing:

    cp Makefile.config.example Makefile.config
    open -t Makefile.config

    Find the line #CPU_ONLY := 1 and uncomment it (remove #)

    Find the line starting from #ANACONDA_HOME and uncomment it also. Make sure ANACONDA_HOME points to the dir you have it installed to. With no comments your config should look like this:

     
    CPU_ONLY := 1
    CUDA_DIR := /usr/local/cuda
    CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
    		-gencode arch=compute_20,code=sm_21 \
    		-gencode arch=compute_30,code=sm_30 \
    		-gencode arch=compute_35,code=sm_35 \
    		-gencode arch=compute_50,code=sm_50 \
    		-gencode arch=compute_50,code=compute_50
    
    BLAS := atlas
     
    ANACONDA_HOME := /Users/artem/anaconda
    PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
            $(ANACONDA_HOME)/include/python2.7 \
            $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
    
    INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
    LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
     
    BUILD_DIR := build
    DISTRIBUTE_DIR := distribute
     
    TEST_GPUID := 0
    
    Q ?= @      
                

    Since some libraries are coming with Anaconda, you have to define the fallback path

    export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib

    Ok, seems like we're ready to build Caffe:

    make all -j8

    Where '8' is the number of CPU cores you probably have. There's about 50% probability that everything went smoothly. If you're lucky, make tests and run them:

    make test -j8
    make runtest

    Ideally, it should end with

    [----------] Global test environment tear-down
    [==========] 824 tests from 127 test cases ran. (27164 ms total)
    [  PASSED  ] 824 tests.
    
  6. scene in which the the сollective unconscious absorbs the reader

    We need to download the trained model from the Zoo. Let's start from BVLC GoogLeNet; simply type and execute this:

    scripts/download_model_binary.py models/bvlc_googlenet

    Finally, get the Neural Network art script (plus a couple of sample images) and play with it.

    curl -o dream.ipynb "https://raw.githubusercontent.com/google/deepdream/master/dream.ipynb"
    curl -o sky1024px.jpg "https://raw.githubusercontent.com/google/deepdream/master/sky1024px.jpg"
    curl -o flowers.jpg "https://raw.githubusercontent.com/google/deepdream/master/flowers.jpg"
    export PYTHONPATH=$HOME/caffe/python:$PYTHONPATH
    ipython notebook dream.ipynb

    It opens your browser and navigates to http://localhost:8888/notebooks/dream.ipynb where you should be able to run the script cell by cell to make your experiments in deepdreams.

  7. scene In which the reader meets Lucy in the sky with diamonds. Unfinished.