0% found this document useful (0 votes)
35 views12 pages

621cef65577a2946040180bc - IoT Gets An ML Boost From Edge To Cloud

This document discusses how machine learning models can be trained on edge devices like the Raspberry Pi and deployed both locally on the edge device and in the cloud using platforms like Microsoft Azure. It provides steps to set up a Raspberry Pi with Edge Impulse and collect image data to train a model to detect lug nuts. The trained model can then be deployed locally on the Pi and integrated with an Azure IoT Hub to send detections to the cloud.

Uploaded by

Mohamed Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views12 pages

621cef65577a2946040180bc - IoT Gets An ML Boost From Edge To Cloud

This document discusses how machine learning models can be trained on edge devices like the Raspberry Pi and deployed both locally on the edge device and in the cloud using platforms like Microsoft Azure. It provides steps to set up a Raspberry Pi with Edge Impulse and collect image data to train a model to detect lug nuts. The trained model can then be deployed locally on the Pi and integrated with an Azure IoT Hub to send detections to the cloud.

Uploaded by

Mohamed Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

IoT Gets an ML
Boost, From
Edge to Cloud
Today, It’s Easy to Run Edge Impulse Machine
Learning on Any OS, Like The Linux-Powered
Raspberry Pi, And On Every Cloud, Like
Microsoft’s Azure IoT.

2021

1
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

Today, It’s Easy To Run Building enterprise-grade IoT hosted solution backend to

Edge Impulse Machine solutions takes a lot of practical connect virtually any device. For
effort and a healthy dose of our hardware, we selected the
Learning on Any
imagination. As a foundation, ubiquitous Raspberry Pi 4, and of
OS, Like The Linux-
you start with a highly secure course Edge Impulse, which will
Powered Raspberry Pi,
and reliable communication connect to both platforms and
And On Every Cloud, between your IoT application extend our showcased solution
Like Microsoft’s Azure and the devices it manages. We from cloud to edge, including
IoT picked our favorite integration, device authentication, out-of-box
the Microsoft Azure IoT Hub, device management, and model
- Evan Rust that provides us with a cloud- provisioning.

FROM EDGE TO have cloud connectivity. The devices directly from the Azure

CLOUD - GETTING second group is often expensive IoT Hub, and run - fast.

STARTED to develop and maintain, as


training and deploying models This reference project will serve
Edge machine learning devices can be an arduous process. That’s you as a guide for quickly
fall into two categories: some are where Edge Impulse comes in to getting started with Edge Impulse
able to run very simple models help to simplify the pipeline, as on a Raspberry Pi 4 and Azure
locally, and others have more data can be gathered remotely, IoT, to train a model that detects
advanced capabilities that allow used effortlessly to train models, lug nuts on a wheel and sends
them to be more powerful and and then downloaded to the alerts to the cloud.

2
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

SETTING UP up the board. Once you’ve successfully SSH’d into the


device with
THE HARDWARE
`$ ssh pi@<IP_ADDRESS>`
To begin, you’ll need a Raspberry Pi 4 with an up-to-
and the password `raspberry`, it’s time to install the
date Raspberry Pi OS image that can be found here.
dependencies for the Edge Impulse Linux SDK. Simply
After flashing this image to an SD card and adding a
run the next three commands to set up the NodeJS
file named `wpa_supplicant.conf`:
environment and everything else that’s required for the
edge-impulse-linux wizard:
```ctrl_interface=DIR=/var/run/wpa_supplicant
GROUP=netdev
```
update_config=1
$ curl -sL https://deb.nodesource.com/setup_12.x |
country=<Insert 2 letter ISO 3166-1 country code here>
sudo bash -
$ sudo apt install -y gcc g++ make build-essential
network={
nodejs sox gstreamer1.0-tools gstreamer1.0-plugins-
ssid=”<Name of your wireless LAN>”
good gstreamer1.0-plugins-base gstreamer1.0-plugins-
psk=”<Password for your wireless LAN>”
base-apps
}```
$ npm config set user root && sudo npm install edge-
along with an empty file named `ssh` (both within impulse-linux -g --unsafe-perm
the `/boot` directory), you can go ahead and power ```

3
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

Since this project deals with images, we’ll need some the Edge Impulse Studio and create a new project,
way to capture them. The wizard supports both the then run the wizard with
Pi Camera modules and standard USB webcams, so `$ edge-impulse-linux`
make sure to enable the camera module first with and make sure your device appears within the Edge
`$ sudo raspi-config` Impulse Studio’s device section after logging in and
If you plan on using one. With that completed, go to selecting your project.

CAPTURING
YOUR DATA
Training accurate machine learning
models requires feeding plenty of
varied data, which means a lot of
images are required. For this use
case, I captured around 50 images of
a wheel that had lug nuts on it. After
I was done, I headed to the Labeling
queue in the Data Acquisition page
and added bounding boxes around
each lug nut within every image, along
with every wheel.

To add some test data, I went back to


the main Dashboard page and clicked
the `Rebalance dataset` button that
moves 20% of the training data to the
test data bin.

4
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

TRAINING The first block in the impulse is an Image Data


block, and it scales each image to a size of `320` by
YOUR MODELS
`320` pixels. Next, image data is fed to the Image
So now that we have plenty of training data, it’s time processing block that takes the raw RGB data and
to do something with it, namely train a model. derives features from it.

TESTING AND DEPLOYING Edge Impulse CLI, as all we have to do is run


`$ edge-impulse-linux-runner`
YOUR MODELS which downloads the model and creates a local
webserver. From here, we can open a browser tab
In order to verify that the model works correctly and visit the address listed after we run the command
in the real world, we’ll need to deploy it to the to see a live camera feed and any objects that are
Raspberry Pi 4. This is a simple task thanks to the currently detected.

5
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

INTEGRATING YOUR MODELS make sure you’ve installed the Azure CLI and have
signed in using `az login`. Then get the name of the
WITH MICROSOFT AZURE IOT resource group you’ll be using for the project. If you
don’t have one, you can follow this guide on how to
With the model working locally on the device, let’s create a new resource group. After that, return to the
add an integration with an Azure IoT Hub that will terminal and run the following commands to create a
allow the Pi to send messages to the cloud. First, new IoT Hub:

and register a new device ID: $ az extension add --name azure-iot


``` $ az iot hub device-identity create --hub-name <your
$ az iot hub create --resource-group <your resource IoT Hub name> --device-id <your device id>
group> --name <your IoT Hub name> ```

6
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

Retrieve the connection string with --device-id <your device id> --hub-name <your IoT
`$ az iot hub device-identity connection-string show Hub name>`

and set it as an environment variable with program will not work!) The connection string contains
`$ export IOTHUB_DEVICE_CONNECTION_ the information required for the device to establish a
STRING=”<your connection string here>”` connection with the IoT Hub service and communicate
in the Pi’s SSH session, as well as with it. You can then monitor output in the Hub with
`$ pip install azure-iot-device` `$ az iot hub monitor-events --hub-name <your IoT Hub
to add the necessary libraries. (Note: if you do not set name> --output table`
the environment variable or pass it in as an argument the or in the Azure Portal.

7
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

To make sure it works, download and run this libportaudio2 libportaudiocpp0 portaudio19-dev
example to make sure you can see the test message. $ pip3 install edge_impulse_linux -i https://pypi.
For the second half of deployment, we’ll need a way python.org/simple
to customize how our model is used within the code.
```
Thankfully, Edge Impulse provides a Python SDK for
There’s some simple code that can be found here on
this purpose. Install it with
Github, and it works by setting up a connection to
```
$ sudo apt-get install libatlas-base-dev libportaudio0 the Azure IoT Hub and then running the model.

Once you’ve either downloaded the zip file or `modelfile.eim`. Now, run the Python program with
cloned the repo into a folder, get the model file by `$ python lug_nut_counter.py ./modelfile.eim -c
running <LUG_NUT_COUNT>`
`$ edge-impulse-linux-runner --download modelfile. where `<LUG_NUT_COUNT>` is the correct number
eim` of lug nuts that should be attached to the wheel
inside of the folder you just created from the (you might have to use `python3` if both Python 2
cloning process. This will download a file called and 3 are installed).

8
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

Now whenever a wheel is detected the number short of the target, a message is sent to the
of lug nuts is calculated. If this number falls Azure IoT Hub.

9
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

And by only sending messages when there’s amount of bandwidth from being taken due to
something wrong, we can prevent an excess empty payloads.

The Possibilities to help retain the confidentiality of both cloud-

Are Endless to-device and device-to-cloud messages, revoke


access rights for specific devices, transmit code

Imagine utilizing object detection for an industrial and services between the cloud and the edge, and

task such as quality control on an assembly line, benefit from advanced analytics on devices running

or detecting ripe fruit amongst rows of crops, offline or with intermittent connectivity. And if

machinery malfunction and remote, battery- you’re really looking to scale your operation and

powered inferencing devices. Between Edge enjoy a complete dashboard view of the device

Impulse, hardware like Raspberry Pi, and the fleets you manage, it is also possible to receive IoT

Microsoft Azure IoT Hub, you can design endless alerts in Microsoft’s Connected Field Service from

models and deploy them on every device, while Azure IoT Central - directly.

authenticating each and every device with built-in


security. You can set up individual identities and Feel free to take the code for this project hosted

credentials for each of your connected devices here on GitHub and create a fork or add to it.

10
IOT GETS AN ML BOOST, FROM EDGE TO CLOUD

The complete project is available here. Let us know your thoughts at [email protected].
There are no limits, just your imagination at work.

11
[email protected]

Edge Impulse
3031 Tisch Way
110 Plaza West
San Jose, CA 95128
USA

You might also like