Installing the OpenVino Toolkit
Installing software for Intel’s Neural Compute Stick 2, Movidius, on a Raspberry Pi 4, 8GB
About Movidius
In short, Intel bought the company that made first Movidius Neural Compute stick, and then came out with a second version, presumably backed with Intel’s hardware resources. This post is about that second stick, the Movidius Neural Compute stick 2 by Intel.
Why I am writing this
At the time of this writing (June 2021) there are no updated all-in-one guides for installation of this device on a Raspberry Pi. So I wanted to put something out there in case anyone else might find this useful.
I referenced this article from hackster.io, the OpenVino instructions here, and this YouTube video by Intel helped a little bit too, but the directory names and files and locations seemed to have changed since 2019 and it seems that most of the “walk-through” documentation is from that time, and the available OpenVino packages are from 2020, where the inference_gpu_engine_vpu
directory appears to now be named just inference_engine
(which is confusing because there is another directory with the same name inside the deployment_tools
directory).
Steps
Check your power
Check this article about power requirements (you should be fine if you bought a Canakit or a Raspberry Pi power source, but it couldn’t hurt to check). I ran the following command and got back “0.0” (which I think is good):
vcgencmd get_throttled
Get the OpenVino Software
Download the software from here: https://storage.openvinotoolkit.org/repositories/openvino/packages/ (Intel does not have a folder/file name format for the latest release so you cannot just use the same wget
command to download the latest package, since the package I use today may not be available in the future). I put this file in my Downloads folder, but it does not matter since we will unzip it to a different directory.
Create and move to the directory which we will be unpacking to: mkdir /opt/intel/openvino/ && cd /opt/intel/openvino/
Unpack the software by running the following command in Downloads (or wherever the .tgz
file was downloaded to:
sudo tar -zxvf l_openvino_toolkit_runtime_raspbian_p_<package>.tgz -strip 1 -C /opt/intel/openvino/
Warning: this unpacks to root/opt/
and requires admin access.
Install CMake
We need to install CMake so we can install some dependencies later. Fortunately, the heavy lifting has already been done with this portion. I say fortunately because CMake is a wonderful tool, however, the documentation for beginners for CMake is hard to find. Install CMake by running:
sudo apt install cmake
Setup Environment Variables
We need to setup some Environment Variables. It seems that any PYTHONPATH issues may have been resolved since 2019, so running the shell file should be fine on its own.
source /opt/intel/openvino/bin/setupvars.sh
You should see a message: [setupvars.sh] OpenVINO environment initialized
OPTIONAL — adding the line to .bashrc
It is worth noting that you will need to run the above command every time you open a new terminal. For convenience, you can add the above command to your .bashrc
file with the following command:
echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bashrc
I found it convenient to use this, and it is pretty easy to remove this line if you change your mind later (by just opening the .bashrc
file and removing or commenting out the line).
If you go this route, you should see the following everytime you open a terminal: [setupvars.sh] OpenVINO environment initialized
Add USB Rules
You will need to add USB Rules for your pi user (or whichever user you are currently logged in as). Add your user to the “users” group with the command:
sudo usermod -a -G users "$(whoami)"
After running this, you must log out and log back in for it to take effect.
If you did not add the Environment Variable line to .bashrc
, run:
source /opt/intel/openvino/bin/setupvars.sh
Install the USB Rules:
sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh
Try running a sample
Now this next part you should probably download and run from your home directory, or another place where you have write-access. I personally made a directory named openvino like so:
mkdir ~/Documents/openvino && cd ~/Documents/openvino
Inside your directory, create and move to a new directory, build
:
mkdir build && cd build
Run CMake to build the Object Detection Sample:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino/deployment_tools/inference_engine/samples/cppmake -j2 object_detection_sample_ssd
Download the pre-trained model from Intel.
I like to keep my packages somewhat separate, so I backed out of build
before cloning the open_model_zoo
repository:
cd ~/Documents/openvino/
And clone the open_model_zoo
repository, etc.:
git clone --depth 1 https://github.com/openvinotoolkit/open_model_zoo
cd open_model_zoo/tools/downloader
python3 -m pip install -r requirements.in
python3 downloader.py --name face-detection-adas-0001
Run the sample!
Get a picture ready! But do not run this, it will not work (even if you cloned that last repository inside of build
). I put it here because this was in the instructions I read, and because the placement of these files may change in the future.
./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i <path_to_image>
I had so much trouble with this part because the documentation does not seem to give paths to anything. Eventually I found the files by looking through every directory in /opt/intel/openvino/
as well as every directory in ~/Documents/openvino/
— and all of the files we need are in the latter directory.
The command we are about to run will generate an altered image (assuming said image has a face). The altered image will be placed in whichever folder you run the command from in your terminal. Personally, I like keeping my pictures together, so I moved to the Pictures directory:
cd ~/Pictures/
I then ran the following command explicitly naming all paths:
~/Documents/openvino/build/armv7l/Release/object_detection_sample_ssd -m ~/Documents/openvino/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml -d MYRIAD -i ~/Pictures/image.jpg
Alternatively, if you cloned the open_model_zoo into the build directory, you can run the following:
~/Documents/openvino/build/armv7l/Release/object_detection_sample_ssd -m ~/Documents/openvino/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml -d MYRIAD -i ~/Pictures/image.jpg
And you should now have a new file named out_0.bmp
in whichever directory you executed the above code from!