Getting Started 3: Movidius Neural Compute Stick with Pi 3 Raspbian Stretch Desktop ( Image Classification )
Movidius Neural Compute Stick
The Intel® Movidius™ Neural Compute Stick (NCS) (77 $) is a small USB deep learning device, which can be deployed on single board computers such as the Raspberry Pi, for prediction purpose rather than actually training network. For more information: (Movidius, Processor). For now, this stick supports two Deep Neural Network frameworks (TensorFlow and Caffe).
First of all, if you have any virtual environments onto your Pi, then intel’s movidius scripts will make it unstable by changing PYTHONPATH system variable, therefore i highly recommend fresh installation of Raspbian Stretch. You can follow my previous article to setup fresh installation of Raspbian Stretch, and Pi Camera.
The workflow for the Movidius NCS is described in the diagram below.
- First, we will be using either a pre-trained TensorFlow/Caffe model or train a network with Tensorflow/Caffe on the powerful GPU.
- Apply NCS SDK toolchain to generate a graph file, which is the only supported format by NCS.
- Exploit the graph file and NCS onto your Raspberry Pi 3 with Raspberry Stretch(Debian based).
- Apply the NCS API to send the graph file to the NCS and run predictions on images.
In this article, we’ll install NCS API-only mode toolchain on our raspberry pi which doesn't require installation of DNN frameworks such as Caffe or Tensorflow, nor it includes tools to generate graph files. I will also explain custom image classification python script, from PyImageSearch.
Setup PI & NCS in API Only Mode
After you have your pi setup with fresh installation of raspbian stretch, and running via TeamViewer, open up the terminal and update the system using:
sudo apt-get update && sudo apt-get upgrade
After that lets install some packages :
sudo apt-get install -y libusb-1.0–0-dev libprotobuf-dev
sudo apt-get install -y libleveldb-dev libsnappy-dev
sudo apt-get install -y libopencv-dev
sudo apt-get install -y libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev git automake
sudo apt-get install -y byacc lsb-release cmake
sudo apt-get install -y libgflags-dev libgoogle-glog-dev
sudo apt-get install -y liblmdb-dev swig3.0 graphviz
sudo apt-get install -y libxslt-dev libxml2-dev
sudo apt-get install -y gfortran
sudo apt-get install -y python3-dev python-pip python3-pip
sudo apt-get install -y python3-setuptools python3-markdown
sudo apt-get install -y python3-pillow python3-yaml python3-pygraphviz
sudo apt-get install -y python3-h5py python3-nose python3-lxml
sudo apt-get install -y python3-matplotlib python3-numpy
sudo apt-get install -y python3-protobuf python3-dateutil
sudo apt-get install -y python3-skimage python3-scipy
sudo apt-get install -y python3-six python3-networkx
Note that : We are using OpenCV with Python bindings, we will also need to install python-opencv binder. Likewise lets also install imutils and picamera API :
sudo apt-get install -y python-opencv
pip install imutils
pip install “picamera[array]”
Now its time to clone the NCSDK, but before that lets make sample directory on the Pi, and clone the SDK inside this directory.
git clone https://github.com/movidius/ncsdk
Lets also clone the NC App Zoo, which we require later as we proceed with this article.
git clone https://github.com/movidius/ncappzoo
Navigate to: cd ~/sample/ncsdk/api/src , & install the SDK in API mode using Makefile as below:
sudo make install
Connect your NCS, and test the Installation
Inside the NC App Zoo, there is a python script called hello_ncs_py, run it:
You will be the output as below:
Hello NCS! Device opened normally.
Goodbye NCS! Device closed normally.
NCS device working.
Finally, The NCS is up and running. Bravo!!!!!
Classification using Movidius NCS
We will be using pre-trained graph file of the SqueezeNet and GoogleNet which was available from Pyimagesearch . Please visit my github repository : https://github.com/Geo-Trackers/Movidius-NCS-Classification, for more details on example usage.
Thank you for your attention
Co-Founder at Pixel Labs ( https://www.pixelnetworks.net/)
Msc. Engineering & Technology ( Sustainable Agriculture)