29 @page 11_camera_object_identification_build_and_run Building and Running
32 This sample uses Caffe to classify the kinds of objects that appear in
36 * You have followed Steps 1-3 in @ref mmapi_build.
37 * You have a working camera module.
41 1. Set up the Caffe environment.
43 a) Install packages from APT with the following commands:
45 $ sudo add-apt-repository universe
46 $ sudo add-apt-repository multiverse
48 $ sudo apt-
get install libboost-all-dev libprotobuf-dev libleveldb-dev libsnappy-dev
49 $ sudo apt-
get install libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev
50 $ sudo apt-
get install liblmdb-dev libblas-dev libatlas-base-dev
52 b) Download Caffe source
package from the following website:
56 And copy the package to `$HOME` directory on the target board
57 with the following command:
59 $ mkdir -pv $HOME/Work/caffe
60 $ cp caffe-master.zip $HOME/Work/caffe/
61 $ cd $HOME/Work/caffe/ && unzip caffe-master.zip
63 c) Build Caffe source with the following commands:
65 $ cd $HOME/Work/caffe/caffe-master
66 Locate and edit `Makefile.config.example`.
68 Uncomment the following line to enable cuDNN acceleration:
72 Add two lines to CUDA architecture setting:
74 -gencode arch=compute_53,code=sm_53 \
75 -gencode arch=compute_62,code=sm_62
76 And modify the following two lines. Then save and close the file.
78 INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
79 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu/hdf5/serial
82 $ cp Makefile.config.example Makefile.config
85 The library libcaffe.so is generated in the `build/lib` directory.
87 2. Compile the OpenCV consumer library. This library is needed for Caffe and
88 must be compiled on the target board.
90 $ cd 11_camera_object_identification/opencv_consumer_lib
92 Check the Makefile to ensure the following variables are set correctly:
94 CUDA_DIR:=/usr/local/cuda
95 CAFFE_DIR:=$HOME/Work/caffe/caffe-master
100 This command generates the library `libopencv_consumer.so` in the current directory.
102 3. Download the Caffe model binaries with the following commands:
104 $ sudo apt-get install python-pip
105 $ sudo pip install pyyaml six
106 $ cd $HOME/Work/caffe/caffe-master
107 $ ./scripts/download_model_binary.py models/bvlc_reference_caffenet/
109 Get the `ImageNet` labels file with the following command:
111 $ ./data/ilsvrc12/get_ilsvrc_aux.sh
113 4. Build and run the sample with the following commands:
115 $ cd 11_camera_object_identification
117 $ export LD_LIBRARY_PATH=$HOME/Work/caffe/caffe-master/build/lib:/usr/local/cuda/lib64
118 $ ./camera_caffe -width 1920 -height 1080 \
119 -lib opencv_consumer_lib/libopencv_consumer.so \
120 -model $HOME/Work/caffe/caffe-master/models/bvlc_reference_caffenet/deploy.prototxt \
121 -trained $HOME/Work/caffe/caffe-master/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel \
122 -mean $HOME/Work/caffe/caffe-master/data/ilsvrc12/imagenet_mean.binaryproto \
123 -label $HOME/Work/caffe/caffe-master/data/ilsvrc12/synset_words.txt