Deepdream是最近Google开源的一个很好玩的项目,让我们可以看到利用深度学习对图片进行分类时,相邻神经网络层次之间的信息传递。Deepdream是基于Caffe框架,因此主要是安装Caffe的依赖环境和Caffe框架。
git clone https://github.com/BVLC/caffe.git
cd caffe && cp Makefile.config.example Makefile.config
# 1. CUDA is required for GPU mode.
# 不采用GPU模式,只需要在 Makefile.config 中修改
CPU_ONLY := 1
# 2. BLAS via ATLAS, MKL, or OpenBLAS.
# Basic Linear Algebra Subprograms,基础线性代数程序集
# 应该是系统有自带了实现方案
# 3. Boost >= 1.55
# Deepdream是用Python接Caffe,因此还需要 boost.python 支持
brew install boost --with-python
brew install boost-python
# 4. OpenCV >= 2.4 including 3.0
# OpenCV 就不用说了
# 5. protobuf, glog, gflags
brew install protobuf
brew install glog
brew install gflags
# 6. IO libraries hdf5, leveldb, snappy, lmdb
brew install leveldb
brew install lmdb
brew tap homebrew/science
brew install homebrew/science/hdf5
# python driver for hdf5
pip install h5py
# 7. numpy for python
brew install numpy
官方推荐使用Anaconda,包含了大部分可能用到的Python package,然而这里有很大一个坑,Mac下面Anaconda是安装在~/anaconda
目录下,要使用~/anaconda/bin/python
或~/anaconda/bin/ipython
而非原系统的Python,这要求所有Homebrew安装的包都必须通过Anaconda下的Python来执行,因此如果从一开始就打算用Anaconda,要注意修改环境变量。
这里不使用Anaconda,注意Makefile.config中提到:
# 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
如果是通过Homebrew安装的numpy,需要添加numpy路径,否则会报错:
python/caffe/_caffe.cpp:10:10: fatal error: 'numpy/arrayobject.h' file not found
# Add this to PYTHON_INCLUDE in Makefile.config
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/Cellar/numpy/1.9.2_1/lib/python2.7/site-packages/numpy/core/include
make all
make test
make runtest
make pycaffe
都通过之后将 caffe/python/
添加到Python系统路径:
export PYTHONPATH=path/to/caffe/python:$PYTHONPATH
测试一下:
python
>>> import caffe
# 可能的错误
ImportError: No module named skimage.io
# 解决
pip install scikit-image
git clone https://github.com/google/deepdream.git
cd deepdream && ipython notebook
需要下载 BVLC GoogleNet Model到path/to/caffe/models/bvlc_googlenet/
,然后就可以基于自己的图片,让它做梦给你看!