1. 程式人生 > >Intel® Movidius™ Neural Compute SDK - object-detector

Intel® Movidius™ Neural Compute SDK - object-detector

Intel® Movidius™ Neural Compute SDK - object-detector

https://github.com/movidius/ncappzoo/tree/master/apps/object-detector

ncappzoo/apps/object-detector/

object-detector

Detect objects in images using Single Shot Multibox Detectors (SSD) or Tiny Yolo on Intel® Movidius™ Neural Compute Stick (NCS).

Prerequisites

This code example requires that the following components are available:

Movidius Neural Compute Stick
Movidius Neural Compute SDK
https://software.intel.com/en-us/neural-compute-stick

Running this example

mkdir -p ~/workspace
cd ~/workspace
git clone https://github.com/movidius/ncappzoo
cd ~/workspace/ncappzoo/apps/object-detector/
make run

When the application runs normally and is able to connect to the NCS device, the output will be similar to this:

==============================================================
I found these objects in pic_064.jpg
Execution time: 80.40859ms
--------------------------------------------------------------
99.7%	12: dog: Top Left: (46, 52) Bottom Right: (169, 182)
[email protected]:~/ncs_work/ncappzoo/apps/object-detector$ make run

making MobileNet SSD
(cd ../../caffe/SSD_MobileNet; test -f graph || make compile;)

Running object-detector.py for MobileNet SSD
python3 object-detector.py
/usr/local/lib/python3.5/dist-packages/skimage/transform/_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
  warn("The default mode, 'constant', will be changed to 'reflect' in "

==============================================================
I found these objects in nps_chair.png
Execution time: 80.1279ms
--------------------------------------------------------------
100.0%	9: chair: Top Left: (106, 230) Bottom Right: (668, 583)
/usr/lib/python3/dist-packages/PIL/ImageFont.py:410: DeprecationWarning: decodestring() is a deprecated alias, use decodebytes()
  ''')), Image.open(BytesIO(base64.decodestring(b'''
/usr/lib/python3/dist-packages/PIL/ImageFont.py:434: DeprecationWarning: decodestring() is a deprecated alias, use decodebytes()
  '''))))
==============================================================


making Tiny Yolo
(cd ../../caffe/TinyYolo; test -f graph || make compile;)

Running object-detector.py for Tiny Yolo
python3 object-detector.py -n TinyYolo -g ../../caffe/TinyYolo/graph -l ../../caffe/TinyYolo/labels.txt -M 0 0 0 -S 0.00392 -D 448 448 -c rgb
No devices found
[email protected]:~/ncs_work/ncappzoo/apps/object-detector$

You should also see the image with a bounding box around the detected object.

Configuring this example

This example performs an inference on ncappzoo/data/images/pic_064.jpg by default; you can supply your own image using the --image options. Below is an example:

python3 object-detector.py --image ../../data/images/pic_053.jpg
[email protected]:~/ncs_work/ncappzoo/apps/object-detector$ python3 object-detector.py --image ../../data/images/pic_053.jpg
/usr/local/lib/python3.5/dist-packages/skimage/transform/_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
  warn("The default mode, 'constant', will be changed to 'reflect' in "

==============================================================
I found these objects in pic_053.jpg
Execution time: 79.9207ms
--------------------------------------------------------------
99.0%	17: sheep: Top Left: (11, 35) Bottom Right: (160, 250)
/usr/lib/python3/dist-packages/PIL/ImageFont.py:410: DeprecationWarning: decodestring() is a deprecated alias, use decodebytes()
  ''')), Image.open(BytesIO(base64.decodestring(b'''
/usr/lib/python3/dist-packages/PIL/ImageFont.py:434: DeprecationWarning: decodestring() is a deprecated alias, use decodebytes()
  '''))))
98.0%	17: sheep: Top Left: (95, 83) Bottom Right: (159, 175)
==============================================================

[email protected]:~/ncs_work/ncappzoo/apps/object-detector$

在這裡插入圖片描述

Customizing this example

You can use this project as a template for your custom SSD/TinyYolo object detector app. Below are some tips to help customize the example.

  1. Before attemping to customize, check if the built-in options would suffice. Run python3 object-detector.py -h to list all available options.
[email protected]:~/ncs_work/ncappzoo/apps/object-detector$ python3 object-detector.py -h
usage: object-detector.py [-h] [-n NETWORK] [-g GRAPH] [-i IMAGE] [-l LABELS]
                          [-M MEAN [MEAN ...]] [-S SCALE] [-D DIM [DIM ...]]
                          [-c COLORMODE]

Object detection using SSD on Intel® Movidius™ Neural Compute Stick.

optional arguments:
  -h, --help            show this help message and exit
  -n NETWORK, --network NETWORK
                        network name: SSD or TinyYolo.
  -g GRAPH, --graph GRAPH
                        Absolute path to the neural network graph file.
  -i IMAGE, --image IMAGE
                        Absolute path to the image that needs to be inferred.
  -l LABELS, --labels LABELS
                        Absolute path to labels file.
  -M MEAN [MEAN ...], --mean MEAN [MEAN ...]
                        ',' delimited floating point values for image mean.
  -S SCALE, --scale SCALE
                        Absolute path to labels file.
  -D DIM [DIM ...], --dim DIM [DIM ...]
                        Image dimensions. ex. -D 224 224
  -c COLORMODE, --colormode COLORMODE
                        RGB vs BGR color sequence. This is network dependent.
[email protected]:~/ncs_work/ncappzoo/apps/object-detector$
  1. Steps 1, 2 and 5 are common across all Neural Compute Stick apps, so you can re-use those fuctions without modifications.

  2. Step 3, ‘Pre-process the images’ is probably the most customizable function. As the name suggests, you can include all image pre-processing tasks in this function. Ex. if you don’t want to warp the input image, just crop it before calling skimage.transform.resize.

  3. [Future functionality] If you decide to use a different model, the deserialize_output.ssd function call in step 4 should be replaced by a deserializer module suitable for the chosen model.