caffe以及apollocaffe的安装:

注:这是我安装caffe和apollocaffe的一些笔记。希望对初学者能有一些帮助。

安装步骤:

一、   安装虚拟机

1.       VirtualBox的安装

1)       从http://download.virtualbox.org/virtualbox/4.3.12/VirtualBox-4.3.12-93733-Win.exe下载VirtualBox4.3.12的安装包(32位系统安装4.3.12版本以下的VirtualBox,否则无法运行);

2)       双击安装包打开安装向导,除去安装路径其余设置都为默认格式,可点击【Next】直接进行安装;

3)       设置完成之后点击【Install】进行安装;

4)       安装完成之后点击【finish】。

2.       在VirtualBox下安装Ubuntu 14.04。

1)       从http://releases.ubuntu.com/14.04/ubuntu-14.04.5-desktop-i386.iso下载ubuntu14.04的镜像文件;

2)       打开VirtualBox软件,如图1所示:


图1打开VirtualBox软件图示

3)         选择新建,然后点击下一步出现了,内存大小的分配,我们不修改,选择系统默认,然后再点击下一步,就出现了创建虚拟硬盘的图片,我们选择创建。然后出现,虚拟硬盘文件类型,我们不做修改,直接下一步;然后就是创建虚拟硬盘,我们用软件选择默认的动态分配,然后下一步,然后创建。最后我们可以看到virtualbox上面有一个ubuntu的图标了;

4)         我们现在选中ubuntu然后,点击上面的启动按钮,弹出一个对话框。然后选择我们已经下载好的ubuntu的虚拟光盘文件,然后点击启动;

5)         此刻,我们进入ubuntu安装界面进行安装(设置都为默认值)。

二、          在Ubuntu 14.04下搭建caffe

1.Ubuntu安装完成之后,单击图1中的ubuntu图标进入虚拟机界面;

2.新建文件夹deep-learning;

3.通过“Ctrl+Alt+T键”进入虚拟机终端界面(以下步骤均是在终端输入指令);

4.进入deep-learning文件夹

    cd deep-learning

5.安装依赖库(一)

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-devlibhdf5-serial-dev protobuf-compiler

sudo apt-get install --no-install-recommends libboost-all-dev

6.安装BLAS

sudo apt-get install libatlas-base-dev

7.安装opencv

1)       搭建编译环境

sudo apt-get install build-essential

2)       安装依赖库

       sudo apt-get install build-essential libgtk2.0-dev libjpeg-devlibtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpypython-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-devlibopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-devlibqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-devlibdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk antlibvtk5-qt4-dev

3)   下载opencv2.4.9

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

4)       解压opencv2.4.9

unzipopencv-2.4.9.zip

5)       进入opencv-2.4.9文件夹

cd opencv-2.4.9

6)       Cmake opencv源文件包

mkdir release(创建release文件夹)

cd release(进入 release文件夹)

cmake –DCMAKE_BUILD_TYPE=RELEASE –D CMAKE_INSTALL_INSTALL_PREFIX=/usr/local/ ..

7)       make和install(make耗时较长)

make

sudo make install

8)       配置opencv相关

sudo gedit/etc/ld.so.conf.d/opencv.conf(进入文件指令)

9)       在空文件里添加如下代码并保存

/usr/local/lib

10)    执行以下代码

sudo ldconfig

11)    在文件末尾添加如下代码

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

exportPKG_CONFIG_PATH

12)    检查opencv是否安装成功

cd~/deep-learning/opencv-2.4.9/samples/c

chmod +x build_all.sh

./build_all.sh

8.安装依赖库(二)

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

9.下载caffe

    sudo apt-get install git

git clone http://github.com/BVLC/caffe.git

10.编译caffe

1) cd caffe(进入caffe文件夹)

2) cp Makefile.config.example Makefile.config(拷贝Makefile.config.example 到Makefile.config)

3)修改配置文件Makefile.config

l  取消对CPU_ONLY := 1的注释#

l  配置一些引用文件(加黑部分为需要添加的)

INCLUDE_DIRS:= $(PYTHON_INCLUDE) /usr/local/include  /usr/include/hdf5/serial

LIBRARY_DIRS := $(PYTHON_LIB)  /usr/local/lib   /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

BLAS := atlas

 4) 编译caffe

      make all

make test

make runtest

11.配置pycaffe

1) 安装依赖库

sudo pip install -r python/requirements.txt

2) 配置pycaffe

sudo apt-get install gfortran(安装fortran编译器)

make pycaffe

exportPYTHONPATH=$PYTHONPATH:~/deep-learning/caffe/python

三. 搭建apollocaffe

1.下载apollocaffe

cd~/deep-learning/(进入deep-learning文件夹)

gitclone http://github.com/Russell91/apollocaffe.git && cd apollocaffe(下载apollocaffe并进入apollocaffe文件夹)

2.安装依赖库

pipinstall -r python/requirements.txt (安装依赖库)

3.设置环境变量

exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/deep-learning/apollocaffe/build/lib #contains libcaffe.so

exportPYTHONPATH=$PYTHONPATH:~/deep-learning/apollocaffe/python

cp ~/deep-learning/caffe/Makefile.config Makefile.config

4.运行

make

maketest

makeruntest

四.运行reinspect

1.下载reinspect

cd~/deep-learning/(进入deep-learning文件夹)

gitclone http://github.com/Russell91/reinspect && cd apollocaffe(下载reinspect并进入reinspect文件夹)

2.安装依赖项

pipinstall jupyter

pipinstall munkres

3.设置环境变量:

exportPYTHONPATH=$PYTHONPATH:~/deep-learning/caffe/python

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/deep-learning/apollocaffe/build/lib# contains libcaffe.so

exportPYTHONPATH=$PYTHONPATH:~/deep-learning/apollocaffe/python

4.在该文件夹内检测环境搭建是否成功

Python

>>import caffe

>>import apollocaffe

>>import cv2(注:如果没有提示错误则表示安装成功)

通过“Ctrl+Z”键退出python命令

5.下载googlenet

  cd ~/apollocaffe/scripts(进入~/apollocaffe/scripts路径)

  python download_model_binary.py ~/deep-learning/apollocaffe/models/bvlc_googlenet(执行该代码,完成下载)

5.运行reinspect

make

make eval

make train

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐