Raspberry Pi 3

Caffe installation in Raspberry Pi 3

This is a installation of caffe in raspberry pi

Installation of dependencies

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install -y gfortran cython

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler git

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

sudo apt-get install -y python-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libatlas-base-dev python-skimage

sudo pip install pyzmq jsonschema pillow numpy scipy ipython jupyter pyyaml

Install caffe

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

cd caffe

cp Makefile.config.example Makefile.config

sudo nano Makefile.config

Modify next lines, instead of these

'#'CPU_ONLY := 1

/usr/lib/python2.7/dist-packages/numpy/core/include

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

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

with

CPU_ONLY := 1

/usr/local/lib/python2.7/dist-packages/numpy/core/include

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

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/arm-linux-gnueabihf/hdf5/serial/

Put in your terminal

make all

make test

make runtest

make pycaffe

./scripts/download_model_binary.py models/bvlc_googlenet

sudo nano ~/.bashrc

export PYTHONPATH=/home/pi/caffe/python:$PYTHONPATH // Add at the end of file

CMake Build
In lieu of manually editing Makefile.config to configure the build, Caffe offers an unofficial CMake build thanks to @Nerei, @akosiorek, and other members of the community. It requires CMake version >= 2.8.7. The basic steps are as follows:

mkdir build
cd build
cmake ..
make all
make install
make runtest

Protobuf installation

cd ~/caffe

cd python

python setup.py build

python setup.py google_test

sudo python setup.py install

Building OpenCV from source

首先,更新以下系统:

$ sudo apt-get update
$ sudo apt-get upgrade

接着,安装需要的编译工具

$ sudo apt-get install build-essential cmake pkg-config

然后,安装相应的依赖包

$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran

然后在Github的opencv项目主页下载你需要的版本,注意contrib的版本和opencv的版本要一致。
opencv源码下载地址:
https://github.com/opencv/opencv/releases
contrib源码下载地址:
https://github.com/opencv/opencv_contrib/releases

下载好opencv的源码压缩包以后,将其解压,然后,进入到opencv的文件夹中(这里我以opencv3.1.0为例):
(注意,如果下面的指令报错,就将所有-D后面的空格删除)

$ cd ~/opencv-3.1.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \ #这里是opencv的安装路径,建议不要修改,就采用默认的安装路径即可
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
    -D PYTHON_EXECUTABLE=~/.pyenv/bin/python \ #这是要用来编译的python路径
    -D BUILD_EXAMPLES=ON ..  # 我在编译例子时遇到错误,把它改为OFF通过

上边的参数配置中,有几处是需要根据你自己电脑上的路径来设置的:

CMAKE_INSTALL_PREFIX:opencv的安装路径,可以自己设置,但建议就用默认路径
OPENCV_EXTRA_MODULES_PATH:contrib文件夹的所在路径,取决于你刚刚下载的contrib压缩包解压后的文件位置
PYTHON_EXECUTABLE:用来进行编译的python路径,如果你不知道自己所有python的路径的话,可以利用指令which python来查询
完成cmake的配置后,利用make指令进行编译:

$ make

然后在进行安装

$ sudo make install
$ sudo ldconfig

最后,建立软连接

$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
sudo apt-get install clang libicu-dev
标签: 无
返回文章列表 文章二维码
本页链接的二维码
打赏二维码
添加新评论