可视化CNN

来源:互联网 发布:中兴网络机顶盒怎么用 编辑:程序博客网 时间:2024/06/05 20:04
reference:
https://github.com/yosinski/deep-visualization-toolbox
caffe配置使用OpenBLAS
http://wxyblog.com/2015/08/27/ubuntu-caffe-openblas/


knowleage:
BLAS:(Basic Linear Algebra Subprograms)
http://yufeigan.github.io/2014/12/14/Caffe%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B04-caffe%E5%AE%89%E8%A3%85%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84libraries/


一、install caffe.
reference:
http://caffe.berkeleyvision.org/install_apt.html
1. 安装依赖
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev


2.安装OPENBLAS
sudo apt-get install libopenblas-dev 
#sudo apt-get install libatlas-base-dev #也可以安装ATLAS,但是不支持CPU多线程
#或者安装MKL (Intel MKL:Intel Math Kernel Library,英特尔数学核心函数库,收费)


3.安装ubuntu 14版本的依赖库
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install python-opencv scipy python-skimage




4.download and compile  caffe 
 git clone https://github.com/BVLC/caffe.git
 cd caffe
 git remote add yosinski https://github.com/yosinski/caffe.git
 git fetch --all
 git checkout --track -b deconv-deep-vis-toolbox yosinski/deconv-deep-vis-toolbox
 < edit Makefile.config to suit your system if not already done in Step 0 
   BLAS := atlas 改为 BLAS := open
   CPU_ONLY := 1>
 make clean
 make -j
 make -j pycaffe


5. Download and configure Deep Visualization Toolbox code
$ git clone https://github.com/yosinski/deep-visualization-toolbox
$ cd deep-visualization-toolbox
$ cp models/caffenet-yos/settings_local.template-caffenet-yos.py settings_local.py
$ vi settings_local.py 
   /*设置caffevis_caffe_root 路径到caffe 安装路径*/
   /* (downloads a 230MB model and 1.1GB of jpgs to show as visualization): */  
$ cd models/caffenet-yos/
$ ./fetch.sh
$ cd ../..   


或者
Rerun as "./fetch.sh all" to also fetch fc6 and fc7 unit visualizations (Warning: 4.5G more)


6.Run it!
$ ./run_toolbox.py


7. 验证caffe安装成功,训练mnist 数据集
# cd ~/caffe
# sudo sh data/mnist/get_mnist.sh
# sudo sh examples/mnist/create_mnist.sh
# sudo vi examples/mnist/lenet_solver.prototxt
将最后一行的solver_mode:GPU改为solver_mode:CPU
# sudo sh examples/mnist/train_lenet.sh






三、问题:
1、sudo apt-get install libprotobuf-dev
Reading package lists... Error!
E: Unable to parse package file /var/lib/apt/lists/cn.archive.ubuntu.com_ubuntu_dists_trusty_multiverse_i18n_Translation-en%5fUS (1)
E: The package lists or status file could not be parsed or opened.
解决方案:
sudo rm -r /var/lib/apt/lists/* 
sudo apt-get update




四、模型研究:
1. model:
deep-visualization-toolbox-master\models\caffenet-yos\caffenet-yos-deploy.prototxt


input 227 X 227 X 3                      out: 1 3   227 227 (154587) 
conv1 kernel(11 X 11 X 3) channel 96     out: 1 96  55  55  (290400)
pool1  (3 X 3)  96                       out: 1 96  27  27  (69984)
conv2 kernel (5 X 5 X 96) channel 256    out: 1 96  27  27  (69984)
pool2  (3 X 3)                           out: 1 256 13  13  (43264)
conv3 kernel (3 X 3 X 256) channel 384   out: 1 384 13  13  (64896)
conv4 kernel (3 X 3 X 384) channel 384   out: 1 384 13  13  (64896)
conv5 kernel (3 X 3 X 384) channel 256   out: 1 256 13  13  (43264)
pool5  (3 X 3)                           out: 1 256 6   6   (9216)
fc6   output 4096                        out: 1 4096        (4096)
fc7   output 4096                        out: 1 4096        (4096)
fc8   output 1000                        out: 1 1000        (1000)






2.输入操作
o: next layer
u: previous layer
s: color 
e: load next file
w: load previous file
z: cycle zooming
c: toggle between camera and file