L4T Multimedia API Reference

28.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
multimedia_api/ll_samples/samples/11_camera_object_identification/README.md
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 @page 11_camera_object_identification_build_and_run Building and Running
30 @{
31 
32 This sample uses Caffe to classify the kinds of objects that appear in
33 the camera stream.
34 
35 ### Prerequisites ###
36 * You have followed Steps 1-3 in @ref mmapi_build.
37 * You have a working camera module.
38 
39 ### To build and run
40 
41 1. Set up the Caffe environment.
42 
43  a) Install packages from APT with the following commands:
44 
45  $ sudo add-apt-repository universe
46  $ sudo add-apt-repository multiverse
47  $ sudo apt-get update
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
51 
52  b) Download Caffe source package from the following website:
53 
54  https://github.com/BVLC/caffe
55 
56  And copy the package to `$HOME` directory on the target board
57  with the following command:
58 
59  $ mkdir -pv $HOME/Work/caffe
60  $ cp caffe-master.zip $HOME/Work/caffe/
61  $ cd $HOME/Work/caffe/ && unzip caffe-master.zip
62 
63  c) Build Caffe source with the following commands:
64 
65  $ cd $HOME/Work/caffe/caffe-master
66  Locate and edit `Makefile.config.example`.
67 
68  Uncomment the following line to enable cuDNN acceleration:
69 
70  USE_CUDNN := 1
71 
72  Add two lines to CUDA architecture setting:
73 
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.
77 
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
80  Then enter:
81 
82  $ cp Makefile.config.example Makefile.config
83  $ make -j4
84 
85  The library libcaffe.so is generated in the `build/lib` directory.
86 
87 2. Compile the OpenCV consumer library. This library is needed for Caffe and
88  must be compiled on the target board.
89 
90  $ cd 11_camera_object_identification/opencv_consumer_lib
91 
92  Check the Makefile to ensure the following variables are set correctly:
93 
94  CUDA_DIR:=/usr/local/cuda
95  CAFFE_DIR:=$HOME/Work/caffe/caffe-master
96  Then enter:
97 
98  $ make
99 
100  This command generates the library `libopencv_consumer.so` in the current directory.
101 
102 3. Download the Caffe model binaries with the following commands:
103 
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/
108 
109  Get the `ImageNet` labels file with the following command:
110 
111  $ ./data/ilsvrc12/get_ilsvrc_aux.sh
112 
113 4. Build and run the sample with the following commands:
114 
115  $ cd 11_camera_object_identification
116  $ make
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
124 @}