即插即用神经网络
1. Setup
1.1 Installing software
This code is built on top of Caffe. You'll need to install the following:
1.1.1 Install Caffe; follow the official installation instructions.
见笔记http://blog.csdn.net/lien0906/article/details/46816273
1.1.2 Build the Python bindings for Caffe
If you want to try example 5 (image captioning), you would need to use the Caffe provided here instead
这个意思是用绑定了python的caffe包代替一般的caffe。
1.1.3 You can optionally build Caffe with the GPU option to make it run faster (recommended)
将1.1.2中下载的caffe_lrcn-master文件夹中的Makefile.config.example原地赋值一份并重命名为Makefile.config,打开该文件,将CPU_ONLY := 1前面的#去掉(也就是反注释),选择只用cpu
1.1.4 Make sure the path to your caffe/python
folder in settings.py is correct
settings.py中的caffe_root="/home/bigbug/caffe_lrcn-master"
1.1.5 Install ImageMagick command-line interface on your system (for post-processing the images)
ubuntu系统中默认安装了ImageMagick,可以通过ubuntu终端输入identify -version查看版本信息
1.2 Downloading models
1.2.1 You will need to download a few models to run the examples below. There are download.sh
scripts provided for your convenience.
cd到对应的.sh文件回车即可。
generator.caffemodel
bvlc_reference_caffenet.caffemodel
placesCNN.tar.gz
lrcn_caffenet_iter_110000.caffemodel
- The generator network (Noiseless Joint PPGN-h) can be downloaded via:
cd nets/generator/noiseless && ./download.sh
- The encoder network (here BVLC reference CaffeNet):
cd nets/caffenet && ./download.sh
- For example 4, download AlexNet CNN trained on MIT Places dataset:
cd nets/placesCNN && ./download.sh
- For example 5, download LRCN image captioning model:
cd nets/lrcn && ./download.sh
1.2.2 Settings:
- Paths to the downloaded models are in settings.py. They are relative and should work if the
download.sh
scripts run correctly.
2. Usage
Examples
We provide here 5 different examples as a starting point. Feel free to fork away to produce even cooler results!
1_class_conditional_sampling.sh: Sampling conditioning on the class "junco" (output unit #13 of the CaffeNet DNN trained on ImageNet dataset). This script produces a sampling chain for a single given class.
- Running
./1_class_conditional_sampling.sh 13
另外,如果运行报错ImportError no module named caffe,说明python和caffe的接口没有设置好,方法为:
1)、更改配置文件
sudo vim ~/.bashrc
打开的文件末尾输入两行
#caffe
export PYTHONPATH=/home/bigbug/caffe_lrcn-master/python
保存
source ~/.bashrc
2)、安装其他接口模块
先安装
sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cython ipython
再更新
sudo apt-get update
最后在/home/bigbug/caffe_lrcn-master路径下执行
make pycaffe -j8
3)、测试
在终端输入python进入python环境,输入命令import caffe,没有出现报错即可,再输入exit()返回ubuntu终端