[PYTHON] Try moving deepdream

Google's deep learning feelings, [deepdream](https://github.com/google / deepdream) try to move. The environment is OS X 10.10.4, iMac (27-inch, Late 2012), NVIDIA GeForce GTX 675MX 1024 MB.

First install Caffe

For reference here. http://caffe.berkeleyvision.org/installation.html http://caffe.berkeleyvision.org/install_osx.html

CUDA The latest version of 7 is strongly suggested https://developer.nvidia.com/cuda-downloads

Caffe is good at Anaconda's Python, so I'll use that. http://continuum.io/downloads (Brew's uninstall or unlink, if yes)

In addition, add the necessary packages with brew.

brew install --fresh -vd snappy leveldb gflags glog szip lmdb
brew tap homebrew/science
#With Anaconda Python, hdf5 seems to be installed
brew install hdf5 opencv
brew install --build-from-source --with-python --fresh -vd protobuf

In the latest version of 1.58.0, boost and boost-python will cause a caffe compile error, so put 1.57.0 in the previous version. ↓ How to put Itinerant Bioinformaticist: Caffe incompatible with Boost 1.58.0

brew uninstall boost boost-python
cd $(brew --prefix)
cd Library/Formula
curl -O https://raw.githubusercontent.com/Homebrew/homebrew/6fd6a9b6b2f56139a44dd689d30b7168ac13effb/Library/Formula/boost.rb
curl -O https://raw.githubusercontent.com/Homebrew/homebrew/3141234b3473717e87f3958d4916fe0ada0baba9/Library/Formula/boost-python.rb
brew install boost boost-python

Finally the caffe body

git clone --depth 1 [email protected]:BVLC/caffe.git
cd caffe
pip install -r python/requirements.txt
cp Makefile.config.example Makefile.config

Rewrite Makefile.config to use Anaconda. (If you use Anaconda)

Makefile.config


#Excerpt
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \
#		/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		$(ANACONDA_HOME)/include/python2.7 \
		$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

compile.

make all -j4
make test
#Appropriately specify where the CUDA library is
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:~/anaconda/lib
make runtest
#↓ Not in the documentation but needed to use caffe from Python, maybe
make pycaffe

Only the caffemodel file is distributed separately, so from ↓. https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet The one that says caffemodel_url. Put it in caffe / models / bvlc_googlenet.

iPython Notebook

The sample code of deepdream is distributed in iPython Notebook format, so insert iPython Notebook. (It seems that Anaconda has it from the beginning)

pip install "ipython[notebook]"

deepdream try to move

If it is not included, enter it. (It seems that Anaconda has it from the beginning)

pip install numpy scipy pil

Drop deepdream.

git clone --depth 1 [email protected]:google/deepdream.git

Launch iPython Notebook

cd deepdream-master
#If the library around CUDA is not found ↓ Setting
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:~/anaconda/lib
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
ipython notebook

Select dream.ipynb because it opens on your browser. After that, if you click the play button on the toolbar, the python script will be executed from above. In [3] and this first line, rewrite the caffemodel file to the path.

model_path = '/some/path/caffe/models/bvlc_googlenet/' # substitute your path here

If there is no error, execute the In [7] script and you will get the example. inception.jpeg

iPython Notebook without using

To do it from normal Python, copy and paste the scripts that were in dream.ipynb into this file, and then do the rest. like this. https://gist.github.com/Saqoosha/50b83b10f8dfc1cc0a3b ↑ So ↓ You can do this. https://vimeo.com/132849531 (After outputting serial numbers, time remap with After Effects) This uses finetune_flickr_style instead of the default bvlc_googlenet. ʻEndparameter also needs to be changed. I'm usingpool5. If you change this, various pictures will change. To find out what can be specified for ʻend, callnet.blobs.keys ()and a list will appear.

Recommended Posts

Try moving deepdream
Try deepdream on Mac
Deep learning / Deep learning from scratch 2-Try moving GRU
Try python
try pysdl2
Try PyOpenGL