HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
English Translate 中文翻訳
LINK
BACK
 

[NEW] 2018/08/20

Raspberry Piで MXNet port of SSD Single Shot MultiBoxを動かして画像の物体検出をする方法 Raspberry Piで MXNet port of SSD Single Shot MultiBoxを動かして画像の物体検出をする方法

(ラズパイで MXNet port of SSD Single Shot MultiBox Object Detectorで物体検出を行なってみる)

Tags: [Raspberry Pi], [電子工作], [ディープラーニング]






● Raspberry Piで MXNet port of SSD Single Shot MultiBox Object Detectorで物体検出を行なってみる

 Raspberry Piで MXNet port of SSD Single Shot MultiBox Object Detectorで物体検出を行なってみる

zhreshold/mxnet-ssd
 MXNet port of SSD: Single Shot MultiBox Object Detector. Reimplementation of https://github.com/weiliu89/caffe/tree/ssd

weiliu89/caffe - SSD: Single Shot MultiBox Detector
 SSD is an unified framework for object detection with a single network. You can use the code to train/evaluate a network for object detection task. For more details, please refer to our arXiv paper and our slide.


●今回動かした Raspberry Pi Raspbian OSのバージョン

 RASPBIAN STRETCH WITH DESKTOP
 Version:June 2018
 Release date: 2018-06-27
 Kernel version: 4.14
pi@raspberrypi:~/pytorch $ uname -a
Linux raspberrypi 4.14.50-v7+ #1122 SMP Tue Jun 19 12:26:26 BST 2018 armv7l GNU/Linux


● Raspberry Piで MXNet port of SSD Single Shot MultiBox Object Detectorを Gitソースリストからビルドする。

zhreshold/mxnet-ssd


# お決まりの sudo apt-get updateで最新状態に更新する
sudo apt-get update

# Getting started
# Building the MXNet port of SSD Single Shot MultiBox Object Detector on Raspberry Pi

# MXNet port of SSD Single Shot MultiBox Object Detectorのビルドに必要なパッケージをインストールする
sudo apt-get install python-opencv python-matplotlib python-numpy

# Cloning the MXNet port of SSD Single Shot MultiBox Object Detector
cd
git clone --recursive https://github.com/zhreshold/mxnet-ssd.git
cd mxnet-ssd/mxnet

# config.mkファイルをコピーする
# for Ubuntu/Debian
cp make/config.mk ./config.mk
# modify it if necessary

cat ./config.mk

cat ./config.mk

# whether use CUDA during compile
USE_CUDA = 0

# whether use opencv during compilation
# you can disable it, however, you will not able to use
# imbin iterator
USE_OPENCV = 1

# use openmp for parallelization
USE_OPENMP = 1

# whether use NNPACK library
USE_NNPACK = 0

# choose the version of blas you want to use
# can be: mkl, blas, atlas, openblas
# in default use atlas for linux while apple for osx
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
USE_BLAS = apple
else
USE_BLAS = atlas
endif
# openmp
sudo apt-get -y install libomp-dev
pi@raspberrypi:~/mxnet-ssd/mxnet $ make
Makefile:218: WARNING: Significant performance increases can be achieved by installing and enabling gperftools or jemalloc development packages
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
g++ -std=c++11 -c -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/pi/mxnet-ssd/mxnet/mshadow/ -I/home/pi/mxnet-ssd/mxnet/dmlc-core/include -fPIC -I/home/pi/mxnet-ssd/mxnet/nnvm/include -I/home/pi/mxnet-ssd/mxnet/dlpack/include -Iinclude -funroll-loops -Wno-unused-variable -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -DMSHADOW_USE_SSE=0 -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=1  -fopenmp  -DMXNET_USE_LIBJPEG_TURBO=0 -MMD -c src/operator/nn/softmax.cc -o build/src/operator/nn/softmax.o
In file included from /home/pi/mxnet-ssd/mxnet/mshadow/mshadow/tensor.h:16:0,
                 from include/mxnet/base.h:31,
                 from src/operator/nn/./../mxnet_op.h:29,
                 from src/operator/nn/./softmax-inl.h:29,
                 from src/operator/nn/softmax.cc:24:
/home/pi/mxnet-ssd/mxnet/mshadow/mshadow/./base.h:147:23: fatal error: cblas.h: No such file or directory
     #include <cblas.h>
                       ^
compilation terminated.
Makefile:349: recipe for target 'build/src/operator/nn/softmax.o' failed
make: *** [build/src/operator/nn/softmax.o] Error 1

sudo apt-get -y install libatlas-base-dev
In file included from src/io/image_aug_default.cc:29:0:
src/io/./image_augmenter.h:30:30: fatal error: opencv2/opencv.hpp: No such file or directory
 #include <opencv2/opencv.hpp>
                              ^
compilation terminated.
Makefile:349: recipe for target 'build/src/io/image_aug_default.o' failed
make: *** [build/src/io/image_aug_default.o] Error 1

sudo apt-get -y install libcv-dev libcvaux-dev libhighgui-dev
In file included from src/io/./image_augmenter.h:30:0,
                 from src/io/image_aug_default.cc:29:
/usr/include/opencv2/opencv.hpp:51:35: fatal error: opencv2/photo/photo.hpp: No such file or directory
 #include "opencv2/photo/photo.hpp"
                                   ^
compilation terminated.
Makefile:349: recipe for target 'build/src/io/image_aug_default.o' failed
make: *** [build/src/io/image_aug_default.o] Error 1

sudo apt-get -y install libopencv-dev

 これで makeに成功します。ビルド完了まで数時間掛かります。
make

g++ -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/pi/mxnet-ssd/mxnet/mshadow/ -I/home/pi/mxnet-ssd/mxnet/dmlc-core/include -fPIC -I/home/pi/mxnet-ssd/mxnet/nnvm/include -I/home/pi/mxnet-ssd/mxnet/dlpack/include -Iinclude -funroll-loops -Wno-unused-variable -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -DMSHADOW_USE_SSE=0 -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=1 -I/usr/include/opencv -fopenmp -DMXNET_USE_LAPACK  -DMXNET_USE_LIBJPEG_TURBO=0 -std=c++11  -o bin/im2rec tools/im2rec.cc build/src/operator/nn/softmax.o build/src/operator/mkl/mkl_cppwrapper.o build/src/operator/mkl/mkl_memory.o build/src/operator/random/sample_multinomial_op.o build/src/operator/random/multisample_op.o build/src/operator/random/sample_op.o build/src/operator/tensor/elemwise_binary_broadcast_op_basic.o build/src/operator/tensor/elemwise_binary_op_logic.o build/src/operator/tensor/elemwise_binary_op_extended.o build/src/operator/tensor/square_sum.o build/src/operator/tensor/indexing_op.o build/src/operator/tensor/matrix_op.o build/src/operator/tensor/dot.o build/src/operator/tensor/elemwise_sum.o build/src/operator/tensor/init_op.o build/src/operator/tensor/la_op.o build/src/operator/tensor/broadcast_reduce_op_index.o build/src/operator/tensor/elemwise_binary_op.o build/src/operator/tensor/elemwise_binary_scalar_op_logic.o build/src/operator/tensor/elemwise_scatter_op.o build/src/operator/tensor/elemwise_unary_op_basic.o build/src/operator/tensor/elemwise_binary_broadcast_op_extended.o build/src/operator/tensor/broadcast_reduce_op_value.o build/src/operator/tensor/control_flow_op.o build/src/operator/tensor/elemwise_binary_op_basic.o build/src/operator/tensor/elemwise_binary_scalar_op_extended.o build/src/operator/tensor/elemwise_binary_broadcast_op_logic.o build/src/operator/tensor/sparse_retain.o build/src/operator/tensor/elemwise_binary_scalar_op_basic.o build/src/operator/tensor/ordering_op.o build/src/operator/tensor/cast_storage.o build/src/operator/tensor/elemwise_unary_op_trig.o build/src/operator/contrib/multibox_target.o build/src/operator/contrib/proposal.o build/src/operator/contrib/count_sketch.o build/src/operator/contrib/dequantize.o build/src/operator/contrib/psroi_pooling.o build/src/operator/contrib/deformable_psroi_pooling.o build/src/operator/contrib/ctc_loss.o build/src/operator/contrib/multibox_prior.o build/src/operator/contrib/multi_proposal.o build/src/operator/contrib/fft.o build/src/operator/contrib/quantize.o build/src/operator/contrib/deformable_convolution.o build/src/operator/contrib/ifft.o build/src/operator/contrib/multibox_detection.o build/src/operator/custom/native_op.o build/src/operator/custom/ndarray_op.o build/src/operator/custom/custom.o build/src/operator/nnpack/nnpack_util.o build/src/io/image_aug_default.o build/src/io/io.o build/src/io/iter_csv.o build/src/io/iter_image_det_recordio.o build/src/io/image_io.o build/src/io/image_det_aug_default.o build/src/io/iter_image_recordio.o build/src/io/iter_mnist.o build/src/io/iter_image_recordio_2.o build/src/io/iter_libsvm.o build/src/common/utils.o build/src/common/rtc.o build/src/nnvm/legacy_op_util.o build/src/nnvm/legacy_json_util.o build/src/imperative/cached_op.o build/src/imperative/imperative.o build/src/ndarray/ndarray_function.o build/src/ndarray/ndarray.o build/src/operator/instance_norm.o build/src/operator/pooling.o build/src/operator/convolution_v1.o build/src/operator/sequence_reverse.o build/src/operator/spatial_transformer.o build/src/operator/deconvolution.o build/src/operator/softmax_output.o build/src/operator/operator_util.o build/src/operator/crop.o build/src/operator/batch_norm_v1.o build/src/operator/rnn.o build/src/operator/swapaxis.o build/src/operator/sequence_last.o build/src/operator/operator.o build/src/operator/optimizer_op.o build/src/operator/lrn.o build/src/operator/correlation.o build/src/operator/pad.o build/src/operator/fully_connected.o build/src/operator/sequence_mask.o build/src/operator/concat.o build/src/operator/make_loss.o build/src/operator/grid_generator.o build/src/operator/cudnn_algoreg.o build/src/operator/pooling_v1.o build/src/operator/identity_attach_KL_sparse_reg.o build/src/operator/upsampling.o build/src/operator/svm_output.o build/src/operator/bilinear_sampler.o build/src/operator/loss_binary_op.o build/src/operator/convolution.o build/src/operator/roi_pooling.o build/src/operator/cudnn_batch_norm.o build/src/operator/cross_device_copy.o build/src/operator/regression_output.o build/src/operator/slice_channel.o build/src/operator/leaky_relu.o build/src/operator/activation.o build/src/operator/batch_norm.o build/src/operator/dropout.o build/src/operator/softmax_activation.o build/src/operator/l2_normalization.o build/src/engine/profiler.o build/src/engine/naive_engine.o build/src/engine/threaded_engine_pooled.o build/src/engine/threaded_engine.o build/src/engine/engine.o build/src/engine/threaded_engine_perdevice.o build/src/storage/storage.o build/src/c_api/c_api_executor.o build/src/c_api/c_api_symbolic.o build/src/c_api/c_api_ndarray.o build/src/c_api/c_predict_api.o build/src/c_api/c_api_function.o build/src/c_api/c_api.o build/src/c_api/c_api_error.o build/src/executor/inplace_addto_detect_pass.o build/src/executor/graph_executor.o build/src/executor/infer_graph_attr_pass.o build/src/executor/attach_op_execs_pass.o build/src/executor/attach_op_resource_pass.o build/src/kvstore/kvstore.o build/src/resource.o build/src/initialize.o /home/pi/mxnet-ssd/mxnet/dmlc-core/libdmlc.a /home/pi/mxnet-ssd/mxnet/nnvm/lib/libnnvm.a -pthread -lm -lcblas -fopenmp -lrt /usr/lib/arm-linux-gnueabihf/libopencv_calib3d.so -lopencv_calib3d /usr/lib/arm-linux-gnueabihf/libopencv_contrib.so -lopencv_contrib /usr/lib/arm-linux-gnueabihf/libopencv_core.so -lopencv_core /usr/lib/arm-linux-gnueabihf/libopencv_features2d.so -lopencv_features2d /usr/lib/arm-linux-gnueabihf/libopencv_flann.so -lopencv_flann /usr/lib/arm-linux-gnueabihf/libopencv_gpu.so -lopencv_gpu /usr/lib/arm-linux-gnueabihf/libopencv_highgui.so -lopencv_highgui /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.so -lopencv_imgproc /usr/lib/arm-linux-gnueabihf/libopencv_legacy.so -lopencv_legacy /usr/lib/arm-linux-gnueabihf/libopencv_ml.so -lopencv_ml /usr/lib/arm-linux-gnueabihf/libopencv_objdetect.so -lopencv_objdetect /usr/lib/arm-linux-gnueabihf/libopencv_ocl.so -lopencv_ocl /usr/lib/arm-linux-gnueabihf/libopencv_photo.so -lopencv_photo /usr/lib/arm-linux-gnueabihf/libopencv_stitching.so -lopencv_stitching /usr/lib/arm-linux-gnueabihf/libopencv_superres.so -lopencv_superres /usr/lib/arm-linux-gnueabihf/libopencv_ts.so /usr/lib/arm-linux-gnueabihf/libopencv_video.so -lopencv_video /usr/lib/arm-linux-gnueabihf/libopencv_videostab.so -lopencv_videostab -llapack
pi@raspberrypi:~/mxnet-ssd/mxnet $ make runtest
Makefile:218: WARNING: Significant performance increases can be achieved by installing and enabling gperftools or jemalloc development packages
g++ -std=c++11 -Itests/cpp/include -Isrc -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/pi/mxnet-ssd/mxnet/mshadow/ -I/home/pi/mxnet-ssd/mxnet/dmlc-core/include -fPIC -I/home/pi/mxnet-ssd/mxnet/nnvm/include -I/home/pi/mxnet-ssd/mxnet/dlpack/include -Iinclude -funroll-loops -Wno-unused-variable -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -DMSHADOW_USE_SSE=0 -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=1 -I/usr/include/opencv -fopenmp -DMXNET_USE_LAPACK  -DMXNET_USE_LIBJPEG_TURBO=0 -I/include/ -MM -MT tests/cpp/operator/core_op_runner_test tests/cpp/operator/core_op_runner_test.cc > build/tests/cpp/operator/core_op_runner_test.d
g++ -c -std=c++11 -Itests/cpp/include -Isrc -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/pi/mxnet-ssd/mxnet/mshadow/ -I/home/pi/mxnet-ssd/mxnet/dmlc-core/include -fPIC -I/home/pi/mxnet-ssd/mxnet/nnvm/include -I/home/pi/mxnet-ssd/mxnet/dlpack/include -Iinclude -funroll-loops -Wno-unused-variable -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -DMSHADOW_USE_SSE=0 -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=1 -I/usr/include/opencv -fopenmp -DMXNET_USE_LAPACK  -DMXNET_USE_LIBJPEG_TURBO=0 -I/include/ -o build/tests/cpp/operator/core_op_runner_test.o tests/cpp/operator/core_op_runner_test.cc
tests/cpp/operator/core_op_runner_test.cc:28:25: fatal error: gtest/gtest.h: No such file or directory
 #include <gtest/gtest.h>
                         ^
compilation terminated.
tests/cpp/unittest.mk:24: recipe for target 'build/tests/cpp/operator/core_op_runner_test.o' failed
make: *** [build/tests/cpp/operator/core_op_runner_test.o] Error 1

# Google Test
# apt-get install libgtest-devは駄目 NG
sudo apt-get -y install libgtest-dev
# Setting up libgtest-dev:armhf (1.8.0-6) ...
# libgtest0は存在しない

pi@raspberrypi:~/mxnet-ssd/mxnet $ make runtest
/usr/bin/ld: cannot find -lgtest
collect2: error: ld returned 1 exit status
tests/cpp/unittest.mk:39: recipe for target 'build/tests/cpp/mxnet_test' failed
make: *** [build/tests/cpp/mxnet_test] Error 1

 どうすれば良いんだ?(下記の様に Gitのソースリストからビルドする)


# ---
pi@raspberrypi:~/mxnet-ssd $ sudo apt-get install libgtest0
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libgtest0

pi@raspberrypi:~/mxnet-ssd $ apt-cache search libgtest
libgtest-dev - Google's framework for writing C++ tests [source code]

● Google Testを Gitのソースリストからビルドする
# https://github.com/google/googletest
cd
git clone https://github.com/google/googletest.git
cd googletest

sudo apt-get -y install cmake

mkdir build
cd build
cmake ..

make

sudo make install
pi@raspberrypi:~/mxnet-ssd/mxnet $ make runtest
Makefile:218: WARNING: Significant performance increases can be achieved by installing and enabling gperftools or jemalloc development packages
cd /home/pi/mxnet-ssd/mxnet/dmlc-core; make libdmlc.a USE_SSE=0 config=/home/pi/mxnet-ssd/mxnet/config.mk; cd /home/pi/mxnet-ssd/mxnet
make[1]: Entering directory '/home/pi/mxnet-ssd/mxnet/dmlc-core'
make[1]: 'libdmlc.a' is up to date.
make[1]: Leaving directory '/home/pi/mxnet-ssd/mxnet/dmlc-core'
LD_LIBRARY_PATH=/home/pi/mxnet-ssd/mxnet/lib: build/tests/cpp/mxnet_test

[==========] Running 53 tests from 11 test cases.
[----------] Global test environment set-up.
[----------] 9 tests from CORE_OP_RUNNER
[ RUN      ] CORE_OP_RUNNER.ExecuteBidirectionalSimpleUnaryList
TestBody
op.inputs()[0]: [dense] main shape: (5, 5)
[0.62945 , -0.72905 , 0.81158 , 0.67002 , -0.74603 ]
[0.93774 , 0.82675 , -0.55793 , 0.26472 , -0.38367 ]
[-0.80492 , 0.09444 , -0.44300 , -0.62324 , 0.09376 ]
[0.98576 , 0.91501 , 0.99292 , 0.92978 , 0.93539 ]
[-0.68477 , 0.45168 , 0.94119 , 0.96222 , 0.91433 ]
TestBody
...
[       OK ] CORE_OP_RUNNER.ExecuteBidirectionalList (6 ms)
[ RUN      ] CORE_OP_RUNNER.ExecuteBidirectionalDotProduct
Segmentation fault
tests/cpp/unittest.mk:42: recipe for target 'runtest' failed
make: *** [runtest] Error 139

pi@raspberrypi:~/mxnet-ssd/mxnet $ free -h
              total        used        free      shared  buff/cache   available
Mem:           976M         35M        500M         12M        441M        871M
Swap:          2.0G          0B        2.0G


● Try the demo
cd
cd mxnet-ssd

# Resnet-50 512x512  VOC07+12 trainval  VOC07 test  79.1  fast
wget https://github.com/zhreshold/mxnet-ssd/releases/download/v0.6/resnet50_ssd_512_voc0712_trainval.zip
cd model
unzip ../resnet50_ssd_512_voc0712_trainval.zip
cd ..

# cd /path/to/mxnet-ssd
python demo.py --gpu 0
# RuntimeError: simple_bind error. Arguments:
# data: (1, 3, 512, 512)
# [00:13:38] src/storage/storage.cc:113: Compile with USE_CUDA=1 to enable GPU usage

# play with examples:
python demo.py --epoch 0 --images ./data/demo/dog.jpg --thresh 0.5
# RuntimeError: simple_bind error. Arguments:
# data: (1, 3, 512, 512)
# [00:14:17] src/storage/storage.cc:113: Compile with USE_CUDA=1 to enable GPU usage

python demo.py --cpu --network resnet50 --data-shape 512
# wait for library to load for the first time

# [00:14:32] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.10.1. Attempting to upgrade...
# [00:14:32] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
# Detection time for 1 images: 44.2037 sec
# _tkinter.TclError: no display name and no $DISPLAY environment variable
# SSHのターミナルで動かすと「画面が無えよ!」で怒られます
# ラズパイの X Window Systemを動かす
sudo systemctl start lightdm

# https://github.com/zhreshold/mxnet-ssd/blob/master/data/demo/dog.jpg

# ラズパイの X Window Systemのターミナルから実行する
python demo.py --cpu --network resnet50 --data-shape 512
# 69秒で画像の「車」「自転車」「犬」を認識して画面に表示します。

pi@raspberrypi:~/mxnet-ssd $ python demo.py --help
usage: demo.py [-h] [--network NETWORK] [--images IMAGES] [--dir [DIR]]
               [--ext [EXTENSION]] [--epoch EPOCH] [--prefix PREFIX] [--cpu]
               [--gpu GPU_ID] [--data-shape DATA_SHAPE] [--mean-r MEAN_R]
               [--mean-g MEAN_G] [--mean-b MEAN_B] [--thresh THRESH]
               [--nms NMS_THRESH] [--force FORCE_NMS] [--timer SHOW_TIMER]
               [--deploy] [--class-names CLASS_NAMES]

Single-shot detection network demo

optional arguments:
  -h, --help            show this help message and exit
  --network NETWORK     which network to use
  --images IMAGES       run demo with images, use comma to seperate multiple
                        images
  --dir [DIR]           demo image directory, optional
  --ext [EXTENSION]     image extension, optional
  --epoch EPOCH         epoch of trained model
  --prefix PREFIX       trained model prefix
  --cpu                 (override GPU) use CPU to detect
  --gpu GPU_ID          GPU device id to detect with
  --data-shape DATA_SHAPE
                        set image shape
  --mean-r MEAN_R       red mean value
  --mean-g MEAN_G       green mean value
  --mean-b MEAN_B       blue mean value
  --thresh THRESH       object visualize score threshold, default 0.6
  --nms NMS_THRESH      non-maximum suppression threshold, default 0.5
  --force FORCE_NMS     force non-maximum suppression on different class
  --timer SHOW_TIMER    show detection time
  --deploy              Load network from json file, rather than from symbol
  --class-names CLASS_NAMES
                        string of comma separated names, or text filename
cd
cd mxnet-ssd

# MobileNet 512x512  VOC07+12 trainval  VOC07 test  72.5  super fast
wget https://github.com/zhreshold/mxnet-ssd/releases/download/v0.7-alpha/mobilenet-ssd-512.zip
cd ./model
unzip ../mobilenet-ssd-512.zip
#  inflating: mobilenet-ssd-512-0001.params
#  inflating: mobilenet-ssd-512-symbol.json
cd ..
# mobilenet-ssd-512
python demo.py --cpu --network mobilenet --data-shape 512
# [00:35:36] include/dmlc/logging.h:308: [00:35:36] src/io/local_filesys.cc:166: Check failed: allow_null  LocalFileSystem: fail to open "/home/pi/mxnet-ssd/model/ssd_mobilenet_512-symbol.json"
pi@raspberrypi:~/mxnet-ssd $ ls -l model/
-rw-r--r-- 1 pi pi  38829547 Oct 31  2017 mobilenet-ssd-512-0001.params
-rw-r--r-- 1 pi pi     77296 Oct 31  2017 mobilenet-ssd-512-symbol.json
-rw-r--r-- 1 pi pi        94 Aug 20 13:13 README.md
-rw-r--r-- 1 pi pi 124747072 Jun 26  2017 ssd_resnet50_512-0000.params
-rw-r--r-- 1 pi pi    132373 Jun 26  2017 ssd_resnet50_512-symbol.json

mv ./model/mobilenet-ssd-512-symbol.json ./model/ssd_mobilenet_512-symbol.json
mv ./model/mobilenet-ssd-512-0001.params ./model/ssd_mobilenet_512-0000.params
# mobilenet-ssd-512
python demo.py --cpu --network mobilenet --data-shape 512
# Detection time for 1 images: 185.8840 sec
#   File "/home/pi/mxnet-ssd/detect/detector.py", line 120, in visualize_detection
#     plt.imshow(img)
# _tkinter.TclError: no display name and no $DISPLAY environment variable
import scipy.misc
        scipy.misc.imsave('outfile.jpg', img)
# ImportError: No module named scipy.misc

---
from PIL import Image

        # plt.show()
        im = Image.fromarray(img)
        im.save("outfile.jpg", "jpeg")

● X Windowの画面が無くても動く様にする。
detect/detector.py
import matplotlib
matplotlib.use('Agg')

...

        # plt.show()
        plt.savefig('outfile.jpg')

# Default = ./data/demo/dog.jpg
# https://github.com/zhreshold/mxnet-ssd/blob/master/data/demo/dog.jpg
pi@raspberrypi:~/mxnet-ssd $ sudo systemctl stop lightdm

pi@raspberrypi:~/mxnet-ssd $ free -h
              total        used        free      shared  buff/cache   available
Mem:           976M         31M        850M        680K         94M        896M
Swap:          2.0G         32M        2.0G

# Resnet-50 512x512  VOC07+12 trainval  VOC07 test  79.1  fast
# Default = ./data/demo/dog.jpg
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network resnet50 --data-shape 512
[01:17:34] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.10.1. Attempting to upgrade...
[01:17:34] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
Detection time for 1 images: 33.1187 sec

# Default = ./data/demo/dog.jpg
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network resnet50 --data-shape 512
[01:18:57] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.10.1. Attempting to upgrade...
[01:18:57] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
Detection time for 1 images: 33.1510 sec

# Default = ./data/demo/dog.jpg
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network resnet50 --data-shape 512
[01:21:29] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.10.1. Attempting to upgrade...
[01:21:29] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
Detection time for 1 images: 33.5891 sec
・Resnet-50 512x512 dog.jpg
Resnet-50 512x512 dog.jpg



# MobileNet 512x512  VOC07+12 trainval  VOC07 test  72.5  super fast
# Default = ./data/demo/dog.jpg
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network mobilenet --data-shape 512
Detection time for 1 images: 8.2375 sec

# Default = ./data/demo/dog.jpg
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network mobilenet --data-shape 512
Detection time for 1 images: 8.2396 sec
・MobileNet 512x512 dog.jpg
MobileNet 512x512 dog.jpg



# https://github.com/zhreshold/mxnet-ssd/blob/master/data/demo/street.jpg
# Resnet-50 512x512  VOC07+12 trainval  VOC07 test  79.1  fast
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network resnet50 --data-shape 512 --images ./data/demo/street.jpg
[01:28:15] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.10.1. Attempting to upgrade...
[01:28:15] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
Detection time for 1 images: 33.4200 sec
・Resnet-50 512x512 street.jpg
Resnet-50 512x512 street.jpg



# MobileNet 512x512  VOC07+12 trainval  VOC07 test  72.5  super fast
pi@raspberrypi:~/mxnet-ssd $ python demo.py --cpu --network mobilenet --data-shape 512 --images ./data/demo/street.jpg
Detection time for 1 images: 8.5379 sec
・MobileNet 512x512 street.jpg
MobileNet 512x512 street.jpg




● USE_JEMALLOC = 1
pi@raspberrypi:~/mxnet-ssd/mxnet $ make
Makefile:218: WARNING: Significant performance increases can be achieved by installing and enabling gperftools or jemalloc development packages
...

pi@raspberrypi:~/mxnet-ssd/mxnet $ cat ./config.mk | grep MALLOC
USE_JEMALLOC = 1

pi@raspberrypi:~/mxnet-ssd/mxnet $ apt-cache search jemalloc
libjemalloc-dev - development files and documentation for jemalloc

sudo apt-get -y install libjemalloc-dev
# Setting up libjemalloc1 (3.6.0-9.1) ...
# Setting up libjemalloc-dev (3.6.0-9.1) ...

pi@raspberrypi:~/mxnet-ssd/mxnet $ make
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
...

sudo apt-get -y install libopencv-dev

# make cleanで全部綺麗にする
pi@raspberrypi:~/mxnet-ssd/mxnet $ make clean

# gperftools or jemalloc
pi@raspberrypi:~/mxnet-ssd/mxnet $ make
Makefile:218: WARNING: Significant performance increases can be achieved by installing and enabling gperftools or jemalloc development packages
g++ -std=c++11 -c -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/pi/mxnet-ssd/mxnet/mshadow/ -I/home/pi/mxnet-ssd/mxnet/dmlc-core/include -fPIC -I/home/pi/mxnet-ssd/mxnet/nnvm/include -I/home/pi/mxnet-ssd/mxnet/dlpack/include -Iinclude -funroll-loops -Wno-unused-variable -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -DMSHADOW_USE_SSE=0 -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=1 -I/usr/include/opencv -fopenmp -DMXNET_USE_LAPACK  -DMXNET_USE_LIBJPEG_TURBO=0 -MMD -c src/operator/nn/softmax.cc -o build/src/operator/nn/softmax.o

pi@raspberrypi:~/mxnet-ssd/mxnet $ apt-cache search gperftools
google-perftools - command line utilities to analyze the performance of C++ programs
libgoogle-perftools-dev - libraries for CPU and heap analysis, plus an efficient thread-caching malloc
libgoogle-perftools4 - libraries for CPU and heap analysis, plus an efficient thread-caching malloc
libtcmalloc-minimal4 - efficient thread-caching malloc

# jemalloc(libjemalloc-dev)は apt-get install済みなので gperftoolsを apt-get install
sudo apt-get -y install libgoogle-perftools-dev
# Setting up libgoogle-perftools-dev (2.5-2.2) ...

# make cleanで全部綺麗にする
pi@raspberrypi:~/mxnet-ssd/mxnet $ make clean

# 警告が出なくなった!
pi@raspberrypi:~/mxnet-ssd/mxnet $ make
g++ -std=c++11 -c -DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/pi/mxnet-ssd/mxnet/mshadow/ -I/home/pi/mxnet-ssd/mxnet/dmlc-core/include -fPIC -I/home/pi/mxnet-ssd/mxnet/nnvm/include -I/home/pi/mxnet-ssd/mxnet/dlpack/include -Iinclude -funroll-loops -Wno-unused-variable -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -DMSHADOW_USE_SSE=0 -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_OPENCV=1 -I/usr/include/opencv -fopenmp -DMXNET_USE_LAPACK -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free  -DMXNET_USE_LIBJPEG_TURBO=0 -MMD -c src/operator/nn/softmax.cc -o build/src/operator/nn/softmax.o

# 2コアビルドで時間短縮(make -j3の 3コアだと SWAPが発生で逆に遅くなる)
pi@raspberrypi:~/mxnet-ssd/mxnet $ make -j2

2コアビルドで大体 100分くらいでビルドが完了します。



Tags: [Raspberry Pi], [電子工作], [ディープラーニング]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

Raspberry Piでメモリを馬鹿食いするアプリ用に不要なサービスを停止してフリーメモリを増やす方法
Raspberry Piでメモリを馬鹿食いするアプリ用に不要なサービスを停止してフリーメモリを増やす方法

  ラズパイでメモリを沢山使用するビルドやアプリ用に不要なサービス等を停止して使えるメインメモリを増やす

【成功版】最新版の Darknetに digitalbrain79版の Darknet with NNPACKの NNPACK処理を適用する
【成功版】最新版の Darknetに digitalbrain79版の Darknet with NNPACKの NNPACK処理を適用する

  ラズパイで NNPACK対応の最新版の Darknetを動かして超高速で物体検出や DeepDreamの悪夢を見る

【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法
【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法

  ラズパイに Darknet NNPACK darknet-nnpackをソースからビルドして物体検出を行なう方法

【成功版】Raspberry Piで Darknet Neural Network Frameworkをビルドする方法
【成功版】Raspberry Piで Darknet Neural Network Frameworkをビルドする方法

  ラズパイに Darknet Neural Network Frameworkを入れて物体検出や悪夢のグロ画像を生成する

【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法
【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法

  ラズパイに TensorFlow Deep Learning Frameworkを入れて Google DeepDreamで悪夢を見る方法

Raspberry Piで TensorFlow Deep Learning Frameworkを自己ビルドする方法
Raspberry Piで TensorFlow Deep Learning Frameworkを自己ビルドする方法

  ラズパイで TensorFlow Deep Learning Frameworkを自己ビルドする方法

Raspberry Piで Caffe Deep Learning Frameworkで物体認識を行なってみるテスト
Raspberry Piで Caffe Deep Learning Frameworkで物体認識を行なってみるテスト

  ラズパイで Caffe Deep Learning Frameworkを動かして物体認識を行なってみる

【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework

  ラズパイで Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する

【インストール版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning
【インストール版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning

  ラズパイで Caffe Deep Learning Frameworkをインストールして Deep Dreamを動かしてキモイ絵を生成する

Raspberry Piで Caffe2 Deep Learning Frameworkをソースコードからビルドする方法
Raspberry Piで Caffe2 Deep Learning Frameworkをソースコードからビルドする方法

  ラズパイで Caffe 2 Deep Learning Frameworkをソースコードから自己ビルドする方法

Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速でモリモリ量産してみるテスト
Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速でモリモリ量産してみるテスト

  OrangePi PC2に Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する

Raspberry Piに Jupyter Notebookをインストールして拡張子 ipynb形式の IPythonを動かす
Raspberry Piに Jupyter Notebookをインストールして拡張子 ipynb形式の IPythonを動かす

  ラズパイに IPython Notebookをインストールして Google DeepDream dream.ipynbを動かす

Raspberry Piで Deep Learningフレームワーク Chainerをインストールしてみる
Raspberry Piで Deep Learningフレームワーク Chainerをインストールしてみる

  ラズパイに Deep Learningのフレームワーク Chainerを入れてみた

Raspberry Piで DeepBeliefSDKをビルドして画像認識フレームワークを動かす方法
Raspberry Piで DeepBeliefSDKをビルドして画像認識フレームワークを動かす方法

  ラズパイに DeepBeliefSDKを入れて画像の物体認識を行なう

Raspberry Piで Microsoftの ELLをビルドする方法
Raspberry Piで Microsoftの ELLをビルドする方法

  ラズパイで Microsoftの ELL Embedded Learning Libraryをビルドしてみるテスト、ビルドするだけ

Raspberry Piで Apache MXNet Incubatingをビルドする方法
Raspberry Piで Apache MXNet Incubatingをビルドする方法

  ラズパイで Apache MXNet Incubatingをビルドしてみるテスト、ビルドするだけ

Raspberry Piで OpenCVの Haar Cascade Object Detectionでリアルタイムにカメラ映像の顔検出を行なってみる
Raspberry Piで OpenCVの Haar Cascade Object Detectionでリアルタイムにカメラ映像の顔検出を行なってみる

  ラズパイで OpenCVの Haar Cascade Object Detection Face & Eyeでリアルタイムでカメラ映像の顔検出をする方法

Raspberry Piで NNPACKをビルドする方法
Raspberry Piで NNPACKをビルドする方法

  ラズパイで NNPACKをビルドしてみるテスト、ビルドするだけ

Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ

  ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も



[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外はweb構成の変更で移動する場合があります)
Copyright (c) 2018 FREE WING, Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_mxnet_ssd_object_detector/