Running the NCSDK examples in Docker

In Movidius’s official documentation, Docker container is not an explicitly supported platform (as of Dec, 2017). Then I decided to test whether the NCS (Neural Compute Stick) can be accessed from a container. Benefiting from this discussion thread, I was able to run the ncsdk examples in a Docker container. Here are the steps I took to make it happen.
Note: I am an Intel employee but all options are on my own.

Prerequisites

My test environment:

  • Host: Ubuntu 16.04.2
  • Docker: docker-ce v17.09
  • Movidius compute stick attached

Build Docker image with ncsdk installed

The Dockerfile I used to install the ncsdk and make the examples is based on instructions from hughdbrown. I created a repo and uploaded the Dockerfile and its config files to it. You may check this branch, and build the Docker image yourself. Run:

1
2
3
git clone https://github.com/ichbinblau/ncsdk_container
cd ncsdk_container
sudo docker build -t the_image_name .

Note: The ncsdk installer currently does not honor any proxy setting options. Build the image without being behind a proxy or the build step may get stuck installing python dependencies from the internet.

Run ncsdk examples in Docker

The ncforum provided a way to run a Docker container which is accessible to the NCS. Host network mode is recommended to make the USB compute stick visible.

Some users have had USB related problems using the Intel NCS within a Docker environment. We have found that including the --net=host flag can help make the device manager events visible to libusb in a Docker environment.

Therefore, I used this command:

1
sudo docker run --rm --net=host -it --privileged -v /dev/bus/usb:/dev/bus/usb:shared -v /run/udev:/run/udev:ro -v /media/data2/NCS/:/media/data2/NCS/ the_image_name:the_image_tag /bin/bash

This leads to an interactive terminal in the container looking like this:

1
movidius@theresa-ubuntu:~/ncsdk$

Inside the container, you can run the examples to test access to the NCS.

1
2
3
4
cd examples/apps/hello_ncs_cpp/
make help
make hello_ncs_cpp
make run

Check the result by looking at the command outputs, such as this:

1
2
3
4
5
6
7
8
9
10
11
movidius@theresa-ubuntu:~/ncsdk/examples/apps/hello_ncs_cpp$ make run
making hello_ncs_cpp
g++ cpp/hello_ncs.cpp -o cpp/hello_ncs_cpp -lmvnc
Created cpp/hello_ncs_cpp executable
making run
cd cpp; ./hello_ncs_cpp; cd ..
Hello NCS! Device opened normally.
Goodbye NCS! Device Closed normally.
NCS device working.

You may continue to test the other model with different frameworks such as caffe and tensorflow under the examples folder.

Comments welcome

This is quick example of using Docker containers to access the NCS. I welcome your comments and corrections.


References:

  1. https://ncsforum.movidius.com/discussion/315/linux-virtual-environment-for-ncs
  2. https://github.com/hughdbrown/movidius/tree/master/docker