Skip to content

Instantly share code, notes, and snippets.

@edwios
Forked from soobrosa/install_caffe_rpi.sh
Last active September 26, 2017 14:02
Show Gist options
  • Save edwios/25516133811e20d7b1e1aa9bdd48d71e to your computer and use it in GitHub Desktop.
Save edwios/25516133811e20d7b1e1aa9bdd48d71e to your computer and use it in GitHub Desktop.
Caffe install + benchmark script for Raspbian Jessie
# tested on a Raspbery Pi 3 running a Raspbian Jessie July 2017
# Install OpenCV 3.3
# See: https://gist.github.com/edwios/5410ceabca579bed7ff1d1b62ee395a1
# dependencies
apt-get update
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libopenblas-dev
sudo apt-get install libatlas-base-dev
cd /usr/lib/arm-linux-gnueabihf/
sudo ln -s libhdf5_serial.so.100.0.1 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.100.0.0 libhdf5_hl.so
# Prepare for the Python3 virtual environment
python3 -m venv caffe_venv
source caffe_venv/bin/activate
# get your Caffe .ZIP from https://github.com/BVLC/caffe
# uncompress and change to its directory
cp Makefile.config.example Makefile.config
nano Makefile.config
# For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config
# If not using CUDA, comment CUDA_ARCH
# Uncomment OPENCV_VERSION := 3
# Add venv Python3 include/ and lib/ to PYTHON_INCLUDE and PYTHON_LIB
# E.g.
# PYTHON_LIB += /home/pi/caffe_venv/lib
# PYTHON_INCLUDE += /home/pi/caffe_venv/include
# Uncomment Homebrew PYTHON_INCLUDE
# Add PYTHON_LIB += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/lib
# Add /usr/include/hdf5/serial to INCLUDE_DIRS
# See this gist for the Makefile.config
# ready to build and test
make all
make test
make runtest
# official test from http://caffe.berkeleyvision.org/gathered/examples/cpp_classification.html
sudo pip install pyyaml six
./scripts/download_model_binary.py models/bvlc_reference_caffenet
./data/ilsvrc12/get_ilsvrc_aux.sh
# run at least three times
time ./build/examples/cpp_classification/classification.bin \
models/bvlc_reference_caffenet/deploy.prototxt \
models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel \
data/ilsvrc12/imagenet_mean.binaryproto \
data/ilsvrc12/synset_words.txt \
examples/images/cat.jpg
# can't even run due to memory limits
#
# terminate called after throwing an instance of 'std::bad_alloc'
# what(): std::bad_alloc
# Aborted
# now grab Squeezenet
# you need both deploy.prototxt
# and squeezenet_v1.1.caffemodel from
# https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1
# https://raw.githubusercontent.com/rmekdma/SqueezeNet/9d981310f66e5285083123cba364b3efa4a6ff55/SqueezeNet_v1.1/deploy.prototxt
time ./build/examples/cpp_classification/classification.bin \
models/squeezenet11/deploy.prototxt \
models/squeezenet11/squeezenet_v1.1.caffemodel \
data/ilsvrc12/imagenet_mean.binaryproto \
data/ilsvrc12/synset_words.txt \
examples/images/cat.jpg
# real 0m1.555s
# user 0m1.070s
# sys 0m0.480s
#
# real 0m2.424s
# user 0m1.160s
# sys 0m0.380s
#
# real 0m1.565s
# user 0m1.140s
# sys 0m0.390s
# so user is about 1.1s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment