This is a crash course in getting the Movidius NCS2 neural compute stick up and running with a benchmark application. Even though only the benchmark app is covered, the same steps can be used to compile any of the other apps included with the OpenVINO toolkit.
Privileged mode is required as the Movidius compute stick changes from USB2.0 to USB3.0 and is re-enumerated by the OS once the ML model is loaded into it. The container need to be able to access the “new” USB3.0 device once it appears.
sudo docker run -ti --privileged --net=host -v /dev:/dev jonaswerner/movidius_nc2_with_openvino:2018.5.455
Verify functionality and download sample code
From this point all commands are executed inside the container. It will carry the name of the host system (“octo” in my case) as it’s running in privileged mode.
[setupvars.sh] OpenVINO environment initialized
root@octo:/# cd /opt/intel/computer_vision_sdk/deployment_tools/demo/
root@octo:/opt/intel/computer_vision_sdk/deployment_tools/demo# ls -l
-rw-r--r-- 1 root root 2933 Feb 21 04:35 README.txt
-rw-r--r-- 1 root root 310725 Feb 21 04:35 car.png
-rw-r--r-- 1 root root 1432032 Feb 21 04:35 car_1.bmp
-rwxr-xr-x 1 root root 6472 Feb 21 04:35 demo_security_barrier_camera.sh
-rwxr-xr-x 1 root root 8605 Feb 21 04:35 demo_squeezenet_download_convert_run.sh
-rw-r--r-- 1 root root 21675 Feb 21 04:35 squeezenet1.1.labels
root@octo:/opt/intel/computer_vision_sdk/deployment_tools/demo# ./demo_squeezenet_download_convert_run.sh -d MYRIAD
target = MYRIAD
target_precision = FP16
Downloading the Caffe model and the prototxt
Output has been shortened for brevity. If all goes well it will finish with the following message:
Demo completed successfully.
This verifies that the Movidius NCS2 (referred to as “MYRIAD” in the command above) is working as expected. It will also have downloaded the sample code to multiple applications, including the benchmark_app we will build.
Download the Alexnet model
We now download the Alexnet model which will be used when executing the benchmark_app. Then we optimize it for FloatingPoint 16 (Movidius NCS2) and for FloatingPoint32 (CPU) so we can run benchmarks against both.
When we use the model optimizer (mo.py) to convert model to Inference Engine format we end up with a pair of files – one XML and one BIN.
Enter the correct directory and execute downloader.py
./downloader.py --name alexnet
Create directories where we can put the FP16 and FP32 files
Compile the benchmark app from the sample source code
Note that in this case we’re doing the benchmark app but there are many interesting application samples included in the same directory.
After compiling the resulting binary can be found here: ~/inference_engine_samples/intel64/Release/
Run benchmarks for MYRIAD and CPU for comparison
Note that even though we run the inferencing against the same image (“car.png”) we have to change the model optimizer between FP16 for MOVIDIUS and FP32 for CPU depending on which of the two we intend to benchmark.
./benchmark_app -d MYRIAD -i /opt/intel/computer_vision_sdk/deployment_tools/demo/car.png -m /opt/intel/computer_vision_sdk/deployment_tools/model_optimizer/alexnet/FP16/alexnet.xml
./benchmark_app -d CPU -i /opt/intel/computer_vision_sdk/deployment_tools/demo/car.png -m /opt/intel/computer_vision_sdk/deployment_tools/model_optimizer/alexnet/FP32/alexnet.xml
That is all for this blog post, but it should have provided the required information to compile any of the other sample applications as well as the necessary instructions for how to download and optimize models required for some of the apps.
A story of IoT and Octopods in the far-east (or, if preferred: How to leverage EdgeX Foundry for a successful customer demonstration).
Last autumn we had ongoing discussions with a customer regarding their IoT efforts. Primarily the discussions had been focused around deployment and management of the edge devices from an infrastructure standpoint. Working at Dell Technologies, that part comes naturally. However, once the discussion broadened it came across the data management side. How does one best deal with the data flow from a myriad IoT devices? How would that data be stored long-term and later used for analytics? Could data be intelligently acted upon in real-time based on alerts from a sensor cluster somewhere
As the hardware management had already been taken care of by EDM (Edge Device Manager) and Edge Gateway OS status and alerting covered by VMware Pulse, we found ourselves looking to a new solution for the data management side. At the back of the room the pre-sales manager said, “Maybe we should look into EdgeX Foundry?”. At that time nobody had much information about this open source, micro-service solution for IoT, but that was about to change.
I took it upon myself to do some research and get it going. It turned out to be exactly what we had been looking for all along.
What is EdgeX Foundry?
EdgeX Foundry functionality can (very simplified) be boiled down to the following:
Ingest data from a wide variety of IoT and M2M devices as well as control them (it speaks many languages!)
Act upon sensor data in real-time (it has a rules engine that can automate actions)
Format, compress & encrypt data prior to forwarding it for storage and analytics (for example Azure)
So, Receive, Process and Forward data with optional actions taken along the way. It’s essentially the glue that holds the world of IoT devices and both internal and external cloud services together. With all its flexibility, adaptability and far-reaching access to almost any IoT device or cloud service it is plain to see why it’s represented by an Octopus 🙂
It elegantly bridges the gap between the edge and the cloud and can reside anywhere along the data path. The preferred location is close to the edge, to minimize latency and network load, but as it’s based on micro-services running in Docker containers it can (and should) be spread out across the infrastructure layer so that each service can make itself useful when and where it’s needed the most.
EdgeX Foundry has two ends
Southbound: Where the IoT Edge is and the data is generated. Thanks to the many protocols it speaks it can interface with both old and new IoT devices.
Northbound: Where the external / internal cloud services reside. Where data warehousing can store the vast volumes of data created and where Machine Learning tools can be leveraged to gain insights from data over time.
In between these two the core and supporting services reside, with a temporary NoSQL data storage (30 min by default), the Scheduling service as well as the Rules Engine for actions and a command module to interface with machinery at the edge when action need to be taken in real-time.
To make it easy to add new IoT devices there are ready-made templates which help integrate sensors with EdgeX Foundry. These are made by Dell EMC or the respective manufacturer and can be downloaded from GitHub.
The device templates play an important role in identifying the types of data being sent to EdgeX Foundry. For example, when receiving a value like “51” from an IoT device it’s important to clarify to the system what that data represents. Is it 51 degrees C? Is it 51% humidity or is it 51 vibrations / sec?
The templates also allow for commands to be sent and status codes to be exchanged. Commands like setting the sensitivity of a camera or motion detector may be important to certain IoT devices and EdgeX Foundry device templates include the valid commands for each device.
Demonstrating the solution
So, as Octopods go this one is quite capable and a great fit for our customer! The next step is to showcase this as seeing is believing and we’re all about being hands-on. After all, it’s most interesting when the rubber hits the road (or when the tentacles grab the Edge Gateways as is the case for us). How do we get this going?
Explain what EdgeX Foundry all about and show how it can be leveraged to propel their IoT efforts
Have a real microservice environment going including all the EdgeX Foundry goodness
Show real-time data collection, processing and export to external cloud services
Keep it interesting and relevant for the customer
Getting the base system up and running is surprisingly easy. The EdgeX Foundry website has a happy “Get started” button and it links to a hands-on tutorial. All that’s needed is a system with Docker Compose. There’s a simple text file (yaml) which docker-compose will use to bootstrap all required Docker images and get them up and running on the same virtual network. Once that’s done the system can be interfaced with using REST clients like, for example, Postman. Most of the micro service comes with its own REST endpoint which can be interfaced with. Either to retrieve or send data as well as modifying settings.
The tutorial goes through a fictional scenario with a smart-camera along with simulated data generated. While this is nice, for our demo we want real data from real sensors. As such we take the example of the fictional smart camera and modify it to fit two scenarios:
Humidity and Temperature sensors (we have no IoT devices, so we build one using a Raspberry Pi)
Smart camera powered by machine learning (we use a simple webcam + a Python script from the Tensorflow tutorial for image recognition)
Providing a graphical interface
While we’re quite happy working on the command line, it doesn’t always make for a good customer demo to just show text on a screen. We need a GUI of some sort. After talking to the creator of EdgeX Foundry – Jim White, we get introduced to Keith from IOTech in the UK.
IOTech has just what we need – a GUI for EdgeX Foundry that can be used to, among other things, display sensor data and graph it. Much easier on the eyes for our customer, so we head over to IOTech’s GitHub page where we find a Docker file for their UI. It’s quick work to build a Docker image and subsequently add it to the docker-compose.yml file used to initiate all EdgeX Foundry services.
Now it starts up along with all other micro services and can communicate across the same network. We’re excited and we’re hopeful our customer will be as well once they get to see it.
Generating sensor data as input
Next, we need some data input. A Raspberry Pi + a breadboard and a DHT11 sensor will provide both Humidity and Temperature data. It’s interfacing with the Raspberry Pi using the GPIO pins and a little help of AdaFruit’s DHT library. We’re a big fan of Lady Ada and her libraries.
So, now we have sensor data. However, to get it sent to EdgeX Foundry we need to use one of the many protocols supported by the EdgeX Foundry device service. Since we’ve been working with Redfish and the REST protocol for server automation and since the Dell EMC GitHub page contains plenty of examples of this (courtesy of Texas Roemer) we pull down some Python files and borrow from there.
A little tweaking later our Raspberry Pi is humming along and sending sensor data via REST every 2 seconds to the EdgeX Foundry device service. To make it interface correctly with the device service we have modified the smart camera template provided in the initial EdgeX Foundry API tutorial to match the data sent by the Raspberry Pi. Instead of counting Humans and Dogs as in the original we’re now sending “Humidity in Percent” and “Temperature in C”.
Looking at the data through IOTech’s GUI we can easily graph the data and provide the customer with a visually pleasing representation of data that is generated in real-time right in front of them. This also has the added benefit that we can ask the customer to touch or breathe on the sensor to change temperature and / or humidity during the demo. This creates an impactful element which helps convey the realization that this system is live, right here, right now.
Exporting data to external cloud services
But wait. How about data export? Wasn’t EdgeX Foundry supposed to be able to export data to external services? Well, the tutorial also contains information on this topic. We create an account at CloudMQTT and configure EdgeX Foundry to export data there. CloudMQTT is essentially a MQTT broker with a live GUI where data can be seen entering the system as it happens. EdgeX Foundry authenticates with the CloudMQTT service and start forwarding on our data. We can view it as it comes in in XML format. This can easily be changed to JSON on the fly and we do this during the live demo later. Jim White provide helpful input on this topic to make sure it functions as expected.
Adding the smart camera
This is all good and well for simple sensor data. What about our ML powered smart camera? The Tensorflow tutorials come with a GitHub repository full of useful tools. Among them the classify_image.py script which takes an image as input and then tells you what it sees in plain text. We hook it up to a web camera, run it in a loop and export the top scoring items the Tensorflow script finds after running inferencing on our live camera input. The resulting data is streamed using REST, just like the Humidity and Temperature data from the Raspberry Pi earlier, to EdgeX Foundry device service and then onward to the public cloud over MQTT where it can be viewed entering the system live.
All preparation is done and we’re ready for our demo.
Customer feedback and next steps
So the day of the demonstration came and went. What was the customer’s impression of the solution? In short: They’re very excited about the capabilities, flexibility and potential of the EdgeX Foundry system. They’re now looking to get their own environment up and running to pursue further tests which will drive the integration of EdgeX Foundry into their IoT initiative. This is done alongside Dell EMC EDM and VMware Pulse as well as their home-grown orchestration platform.
Tips for a successful setup
While the process was made fairly straight forward by the online tutorials for both EdgeX Foundry and Tensorflow as well as the Dell EMC Redfish GitHub repository there were some areas which warranted more attention to get right.
The device templates
For the demo custom device templates were created for both the Smart Camera as well as the Raspberry Pi sensors. It can be challenging to create a device template which will be accepted by the system. If the fields don’t match the data already having been sent do the metadata subsystem an upload attempt will result in errors. Carefully compare the tutorial templates with the REST API calls to ensure the fields that need to be the same, actually match.
Running the REST API calls via Postman vs. Python
Personally, I found using Postman to be handy for troubleshooting or the occasional API call but gradually becoming tedious as more calls via REST were required. Instead I made a Python script which automates the process and can be run more easily from the command line. This may simply be a matter of preference though.
The IOTech GUI
If the IOTech GUI is desired the Dockerfile can be downloaded from here:
Photon OS is a VMware initiative to create a lightweight Linux based OS with container support. I have to admit my initial reaction to Photon OS was: “y tho?”
It’s a reasonable reaction. There are MANY Linux based OS options out there already and essentially all of them have container support. The reason for creating Photon OS would seem to be that VMware wants their own rubber-stamped Linux OS as part of an ecosystem under their control.
Photon OS’s redeeming feature is the fact that it’s really lightweight. Not as lightweight as Ubuntu Core though. Photon OS for Raspberry Pi weighs in at 512Mb while Ubuntu Core is 450Mb. Still, given the influence of VMware in virtualization and their (our) inroads into IoT / M2M with Pulse, it’s likely that Photon OS will take off eventually.
Currently the main barrier to widespread adoption of Photon OS is a lack of commercial support. At the moment it is simply available as an unsupported download from GitHub (here). This could change in the future though and in that case we may see it being utilized more broadly and also outside the lab environments it is currently inhabiting.
Note that unlike Raspbian, which is 32bit, Photon OS is a 64bit operating system. That too may be something that’ll help float the boat for some.
Getting started with Photon OS on the Raspberry Pi
Deflate the zx compressed image and save to a micro-SD card:
tar xf photon-rpi3-3.0-26156e2.tar.xz
sudo dd if=photon-rpi3-3.0-26156e2d.raw of=/dev/mmcblk0 bs=4M;sudo sync
In this example the SD card device is /dev/mmcblk0. This may differ on other systems of course. Please check with “lsblk” or so and please do be careful. Linux / Unix folks don’t refer to dd as “Disk Destroyer” for nothing.
Boot the Raspberry Pi and log in. The default credentials are: root / changeme
DHCP and SSH are both enabled by default and should make it possible to access the Pi across the network if using a wired connection (I haven’t tried though). With a Raspberry Pi it’s likely a wireless connection would be more convenient however. Configuring Wi-Fi is easy and is described in the section that follows.
Photon OS Wi-Fi configuration
There are a few steps to go through for Wi-Fi connectivity but it’s not difficult.
Start the wpa_supplicant service
systemctl start wpa_supplicant@wlan0
Enable the wpa_supplicant service (so it starts with the Pi)
systemctl enable wpa_supplicant@wlan0
Check the service status
systemctl status wpa_supplicant@wlan0
Edit the dhcp settings to get DHCP for wlan0 and not eth0
root@photon-rpi3 [ ~ ]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
3b4173355427: Pull complete
Status: Downloaded newer image for hello-world:latest
root@photon-rpi3 [ ~ ]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
For more examples and ideas, visit:
root@photon-rpi3 [ ~ ]#
That’s all! Photon OS is installed, Wi-Fi configured, Docker installed and verified. Ready to rock.