mirror of
https://github.com/clearlinux/clear-linux-documentation.git
synced 2026-07-11 15:15:54 +00:00
Merge pull request #292 from mvincerx/mv-edits-greengrass-openvino-01
Applies corrections to links and rewording.
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
.. _greengrass:
|
||||
|
||||
How to enable Greengrass and OpenVINO on |CL-ATTR|
|
||||
##################################################
|
||||
|
||||
Introduction
|
||||
************
|
||||
Enable Greengrass and OpenVINO on |CL-ATTR|
|
||||
###########################################
|
||||
|
||||
Hardware accelerated Function-as-a-Service (FaaS) enables cloud developers
|
||||
to deploy inference functionalities [1] on Intel IoT edge devices with
|
||||
@@ -26,8 +23,8 @@ options to consume the inference output.
|
||||
Supported Platforms
|
||||
*******************
|
||||
|
||||
* Operating System: Clear Linux Build 25930+
|
||||
* Hardware: Intel core platforms (Release supports inference on CPU only)
|
||||
* Operating System: |CL-ATTR| latest release
|
||||
* Hardware: Intel core platforms (Tutorial supports inference on CPU only)
|
||||
|
||||
Description of Samples
|
||||
**********************
|
||||
@@ -36,13 +33,12 @@ The Greengrass samples are located at the `Edge-Analytics-FaaS`_.
|
||||
|
||||
We provide the following Greengrass samples:
|
||||
|
||||
* greengrass_classification_sample.py
|
||||
* :file:`greengrass_classification_sample.py`
|
||||
|
||||
This Greengrass sample classifies a video stream using classification
|
||||
networks such as AlexNet and GoogLeNet and publishes top-10 results on AWS
|
||||
IoT Cloud every second.
|
||||
networks such as AlexNet and GoogLeNet and publishes top-10 results on AWS IoT Cloud every second.
|
||||
|
||||
* greengrass_object_detection_sample_ssd.py
|
||||
* :file:`greengrass_object_detection_sample_ssd.py`
|
||||
|
||||
This Greengrass sample detects objects in a video stream and classifies
|
||||
them using single-shot multi-box detection (SSD) networks such as SSD
|
||||
@@ -53,67 +49,63 @@ We provide the following Greengrass samples:
|
||||
Converting Deep Learning Models
|
||||
*******************************
|
||||
|
||||
This tutorial provides intermediate representation for edge-optimized models
|
||||
in the FP32 directory for each model, accessible via the
|
||||
`Edge-optmized models repository`_.
|
||||
|
||||
Sample Models
|
||||
=============
|
||||
|
||||
For classification, download the BVLC `Alexnet model`_ as an example from
|
||||
`caffe`_. Any custom pre-trained classification models can be used with the
|
||||
For classification, `download the BVLC Alexnet model`_ as an example.
|
||||
Any custom pre-trained classification models can be used with the
|
||||
classification sample.
|
||||
|
||||
For object detection, the sample models optimized for Intel edge platforms
|
||||
are present at <model location>. These models are provided as an example,
|
||||
but any custom pre-trained SSD models can be used with the object detection
|
||||
sample.
|
||||
are present at :file:`/usr/share/openvino/models'. These models are provided
|
||||
as an example, but any custom pre-trained SSD models can be used with the
|
||||
object detection sample.
|
||||
|
||||
Running Model Optimizer
|
||||
=======================
|
||||
|
||||
Follow these instructions for converting deep learning models to
|
||||
Intermediate Representation (IR) `using Model Optimizer`_. instructions. For
|
||||
example, for above models use the following commands.
|
||||
Intermediate Representation (IR) `using Model Optimizer`_. For
|
||||
example, for above models, use the following commands.
|
||||
|
||||
For classification using BVLC Alexnet model:
|
||||
|
||||
code-block:: console
|
||||
.. code-block:: bash
|
||||
|
||||
python3 mo.py --framework caffe --input_model <
|
||||
model_location>/bvlc_alexnet.caffemodel --input_proto <
|
||||
model_location>/deploy.prototxt --data_type <data_type> --output_dir <
|
||||
output_dir> --input_shape [1,3,227,227]
|
||||
python3 mo.py --framework caffe --input_model <
|
||||
model_location>/bvlc_alexnet.caffemodel --input_proto <
|
||||
model_location>/deploy.prototxt --data_type <data_type> --output_dir <
|
||||
output_dir> --input_shape [1,3,227,227]
|
||||
|
||||
For object detection using SqueezeNetSSD-5Class model,
|
||||
|
||||
code-block:: console
|
||||
.. code-block:: bash
|
||||
|
||||
python3 mo.py --framework caffe --input_model
|
||||
SqueezeNetSSD-5Class.caffemodel --input_proto SqueezeNetSSD-5Class.prototxt
|
||||
--data_type <data_type> --output_dir <output_dir>
|
||||
python3 mo.py --framework caffe --input_model
|
||||
SqueezeNetSSD-5Class.caffemodel --input_proto SqueezeNetSSD-5Class.prototxt
|
||||
--data_type <data_type> --output_dir <output_dir>
|
||||
|
||||
where <model_location> is the location where the user downloaded the models,
|
||||
<data_type> is FP32 or FP16 depending on target device, and <output_dir> is
|
||||
the directory where the user wants to store the IR. IR contains .xml format
|
||||
corresponding to the network structure and .bin format corresponding to
|
||||
weights. This .xml should be passed to <PARAM_MODEL_XML>. In the BVLC
|
||||
Alexnet model, the prototxt defines the input shape with batch size 10 by
|
||||
default. In order to use any other batch size, the entire input shape needs
|
||||
to be provided as an argument to the model optimizer. For example, if you
|
||||
want to use batch size 1, you can provide “--input_shape [1,3,227,227]”.
|
||||
.. note::
|
||||
|
||||
where :file:`/usr/share/openvino/models is the location where the user installed the models, <data_type> is FP32 or FP16 depending on target device, and <output_dir> is the directory where the user wants to store the IR. IR contains .xml format corresponding to the network structure and .bin format corresponding to weights. This .xml should be passed to <PARAM_MODEL_XML>. In the BVLC Alexnet model, the prototxt defines the input shape with batch size 10 by default. In order to use any other batch size, the entire input shape needs to be provided as an argument to the model optimizer. For example, if you want to use batch size 1, you can provide “--input_shape [1,3,227,227]”.
|
||||
|
||||
Installing |CL| on the edge device
|
||||
**********************************
|
||||
|
||||
Start with a clean installation of |CL| on a new system, using the :ref:`bare-metal-install` getting started guide
|
||||
Start with a clean installation of |CL| on a new system, using the
|
||||
:ref:`bare-metal-install`, found in :ref:`get-started`.
|
||||
|
||||
Create user accounts
|
||||
====================
|
||||
|
||||
After the core OS is installed, create two user accounts. To create a new
|
||||
user and set a password for that user, enter the following
|
||||
user and set a password for that user, enter the following commands as a root user:
|
||||
|
||||
commands as a root user:
|
||||
|
||||
.. code-block:: console
|
||||
.. code-block:: bash
|
||||
|
||||
useradd <userid>
|
||||
passwd <userid>
|
||||
@@ -125,8 +117,7 @@ account just created.
|
||||
|
||||
Next, enable the :command:`sudo` command for your new `<userid>`.
|
||||
|
||||
To be able to execute all applications with root privileges, add the
|
||||
`<userid>` to the `wheel group`_.
|
||||
To be able to execute all applications with root privileges:
|
||||
|
||||
#. Add `<userid>` to the `wheel` group:
|
||||
|
||||
@@ -134,70 +125,90 @@ To be able to execute all applications with root privileges, add the
|
||||
|
||||
usermod -G wheel -a <userid>
|
||||
|
||||
#. Create the user and group account for the Greengrass daemon:
|
||||
|
||||
Create the user and group account for the Greengrass daemon:
|
||||
.. code-block:: console
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
useradd ggc_user
|
||||
groupadd ggc_group
|
||||
useradd ggc_user
|
||||
groupadd ggc_group
|
||||
|
||||
Add required bundles
|
||||
====================
|
||||
|
||||
Use the `swupd` software updater utility to add the following bundles to enable the OpenVINO software stack:
|
||||
Use the `swupd` software updater utility to add the following bundles to
|
||||
enable the OpenVINO software stack:
|
||||
|
||||
.. code-block:: console
|
||||
.. code-block:: bash
|
||||
|
||||
swupd bundle-add os-clr-on-clear desktop-autostart computer-vision-basic
|
||||
|
||||
The `computer-vision-basic` bundle will install the OpenVINO software, along with the edge device models needed.
|
||||
|
||||
.. note::
|
||||
|
||||
Learn more about how to :ref:`swupd-guide`.
|
||||
|
||||
The ``computer-vision-basic`` bundle will install the OpenVINO software,
|
||||
along with the edge device models needed.
|
||||
|
||||
Configuring a Greengrass group
|
||||
==============================
|
||||
|
||||
For each Intel edge platform, we need to create a new Greengrass group and
|
||||
install Greengrass core software to establish the connection between cloud and edge.
|
||||
• To create a Greengrass group, follow the instructions in the AWS Greengrass
|
||||
developer guide at:
|
||||
https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-config.html
|
||||
install Greengrass core software to establish the connection between cloud
|
||||
and edge.
|
||||
|
||||
• To install and configure Greengrass core on edge platform, follow the
|
||||
instructions at https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-device-start.html
|
||||
* To create a Greengrass group, follow the `AWS Greengrass developer guide`_
|
||||
|
||||
* To install and configure Greengrass core on edge platform, follow
|
||||
the instructions at `Start AWS Greengrass`_.
|
||||
|
||||
.. note::
|
||||
You will not need to run the `cgroupfs-mount.sh` script in step #6 of
|
||||
Module 1 of the the AWS Greengrass developer guide, as this is enabled
|
||||
already in |CL|. You will need to create an file: `/etc/fstab` file, as |
|
||||
CL| does not create one by default. To do so, use the command: `sudo
|
||||
touch /etc/fstab`
|
||||
.. TODO: Step 6? Make general reference; BD advise.
|
||||
|
||||
.. note::
|
||||
|
||||
You will not need to run the ``cgroupfs-mount.sh`` script in step #6 of
|
||||
Module 1 of the `AWS Greengrass developer guide`_, as this is enabled
|
||||
already in |CL|. You must create a :file:`/etc/fstab` file .
|
||||
|CL| does not create one by default. To do so, use the
|
||||
:command:`sudo touch /etc/fstab`.
|
||||
|
||||
Creating and Packaging Lambda Functions
|
||||
=======================================
|
||||
|
||||
* To download the AWS Greengrass Core SDK for python 2.7, follow the steps
|
||||
1-4 at: https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html
|
||||
#. To download the `AWS Greengrass Core SDK`_ for python 2.7, follow steps
|
||||
1-4.
|
||||
|
||||
* Replace greengrassHelloWorld.py with Greengrass sample
|
||||
(greengrass_classification_sample.py/greengrass_object_detection_sample_ssd.py) and zip it with extracted Greengrass SDK folders from the previous step into greengrass_sample_python_lambda.zip. The zip should contain:
|
||||
#. Replace greengrassHelloWorld.py with Greengrass samples:
|
||||
- greengrass_classification_sample.py
|
||||
- greengrass_object_detection_sample_ssd.py
|
||||
|
||||
- greengrasssdk
|
||||
- greengrass sample(greengrass_classification_sample.py or greengrass_object_detection_sample_ssd.py)
|
||||
#. Zip these files with extracted Greengrass SDK folders from the previous
|
||||
step into greengrass_sample_python_lambda.zip.
|
||||
|
||||
For example,
|
||||
The zip should contain:
|
||||
|
||||
* greengrasssdk
|
||||
* greengrass sample
|
||||
|
||||
code-block:: console
|
||||
Choose one of the following:
|
||||
|
||||
zip -r greengrass_lambda.zip greengrasssdk greengrass_object_detection_sample_ssd.py
|
||||
- greengrass_classification_sample.py
|
||||
- greengrass_object_detection_sample_ssd.py
|
||||
|
||||
* To complete creating lambdas, follow steps 6-11 at:
|
||||
https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html
|
||||
For example:
|
||||
|
||||
* In step 9(a), while uploading the zip file, make sure to name the handler
|
||||
as below depending on the Greengrass sample you are using:
|
||||
greengrass_object_detection_sample_ssd.function_handler (or)
|
||||
greengrass_classification_sample.function_handler
|
||||
.. code-block:: bash
|
||||
|
||||
zip -r greengrass_lambda.zip greengrasssdk greengrass_object_detection_sample_ssd.py
|
||||
|
||||
#. Follow steps 6-11 to `complete creating lambdas`_.
|
||||
|
||||
.. note::
|
||||
|
||||
In the AWS dcoumentation, step 9(a), while uploading the zip file, make sure to name the handler as below depending on the Greengrass sample you are using:
|
||||
|
||||
greengrass_object_detection_sample_ssd.function_handler (or)
|
||||
greengrass_classification_sample.function_handler
|
||||
|
||||
Deploying Lambdas
|
||||
==================
|
||||
@@ -205,58 +216,118 @@ Deploying Lambdas
|
||||
Configuring the Lambda function
|
||||
-------------------------------
|
||||
|
||||
* After creating the Greengrass group and the lambda function, start configuring the lambda function for AWS Greengrass by following the steps 1-8 in AWS Greengrass developer guide at: https://docs.aws.amazon.com/greengrass/latest/developerguide/config-lambda.html
|
||||
After creating the Greengrass group and the lambda function, start
|
||||
configuring the lambda function for AWS Greengrass.
|
||||
|
||||
* In addition to the details mentioned in step 8 of the AWS Greengrass developer guide, change the Memory limit to 2048MB to accommodate large input video streams.
|
||||
#. Follow steps 1-8 in the AWS documentation `Configure the Lambda Function`_.
|
||||
|
||||
* Add the following environment variables as key-value pair when editing the lambda configuration and click on update:
|
||||
Key Value
|
||||
PARAM_MODEL_XML <MODEL_DIR>/<IR.xml>, where <MODEL_DIR> is user specified and contains IR.xml, the Intermediate Representation file from Intel Model Optimizer
|
||||
#. In addition to the details mentioned in step 8, change the Memory limit
|
||||
to 2048MB to accommodate large input video streams.
|
||||
|
||||
PARAM_INPUT_SOURCE <DATA_DIR>/input.webm to be specified by user. Holds both input and output data. For webcam, set PARAM_INPUT_SOURCE to ‘/dev/video0’
|
||||
PARAM_DEVICE For CPU, specify "CPU"
|
||||
PARAM_CPU_EXTENSION_PATH /usr/lib64/libcpu_extension.so
|
||||
PARAM_OUTPUT_DIRECTORY <DATA_DIR> to be specified by user. Holds both input and output data
|
||||
PARAM_NUM_TOP_RESULTS User specified for classification sample.(e.g. 1 for top-1 result, 5 for top-5 results)
|
||||
#. Add the following environment variables as key-value pair when editing
|
||||
the lambda configuration and click on update:
|
||||
|
||||
|
||||
* Add subscription to subscribe or publish messages from Greengrass lambda function by following the steps 10-14 in AWS Greengrass developer guide at: https://docs.aws.amazon.com/greengrass/latest/developerguide/config-lambda.html. The “Optional topic filter” field should be the topic mentioned inside the lambda function.
|
||||
.. list-table:: **Table 1. Environment Variables: Lambda Configuration**
|
||||
:widths: 20 80
|
||||
:header-rows: 1
|
||||
|
||||
* - Key
|
||||
- Value
|
||||
* - PARAM_MODEL_XML
|
||||
- <MODEL_DIR>/<IR.xml>, where <MODEL_DIR> is user specified and
|
||||
contains IR.xml, the Intermediate Representation file from Intel Model Optimizer
|
||||
* - PARAM_INPUT_SOURCE
|
||||
- <DATA_DIR>/input.webm to be specified by user. Holds both input and
|
||||
output data. For webcam, set PARAM_INPUT_SOURCE to ‘/dev/video0’
|
||||
* - PARAM_DEVICE
|
||||
- For CPU, specify "CPU"
|
||||
* - PARAM_CPU_EXTENSION_PATH
|
||||
- /usr/lib64/libcpu_extension.so
|
||||
* - PARAM_OUTPUT_DIRECTORY
|
||||
- <DATA_DIR> to be specified by user. Holds both input and output data
|
||||
* - PARAM_NUM_TOP_RESULTS
|
||||
- User specified for classification sample.
|
||||
(e.g. 1 for top-1 result, 5 for top-5 results)
|
||||
|
||||
#. Add subscription to subscribe, or publish messages from Greengrass lambda
|
||||
function by following the steps 10-14 in `Configure the Lambda Function`_
|
||||
|
||||
.. note::
|
||||
|
||||
The “Optional topic filter” field should be the topic
|
||||
mentioned inside the lambda function.
|
||||
|
||||
For example, openvino/ssd or openvino/classification
|
||||
|
||||
.. TODO: Restart here. 10.31.2018
|
||||
|
||||
Local Resources
|
||||
---------------
|
||||
* Add local resources and access privileges by following the instructions https://docs.aws.amazon.com/greengrass/latest/developerguide/access-local-resources.html.
|
||||
#. `Add local resources and access privileges` by selecting this link.
|
||||
|
||||
Following are the local resources needed for
|
||||
Following are the local resources needed for CPU:
|
||||
|
||||
CPU:
|
||||
Name Resource
|
||||
Type Local path Access
|
||||
ModelDir Volume <MODEL_DIR> to be specified by user Read-Only
|
||||
Webcam Device /dev/video0
|
||||
Read-Only
|
||||
DataDir Volume <DATA_DIR> to be specified by user. Holds both input and output data. Read and Write
|
||||
::
|
||||
Name Resource
|
||||
Type Local path Access
|
||||
ModelDir Volume <MODEL_DIR> to be specified by user Read-Only
|
||||
Webcam Device /dev/video0
|
||||
Read-Only
|
||||
DataDir Volume <DATA_DIR> to be specified by user. Holds both input
|
||||
and output data. Read and Write
|
||||
|
||||
|
||||
Deploy
|
||||
------
|
||||
|
||||
* To deploy the lambda function to AWS Greengrass core device, select “Deployments” on group page and follow the instructions at: https://docs.aws.amazon.com/greengrass/latest/developerguide/configs-core.html
|
||||
To `deploy the lambda function to AWS Greengrass core device`_, select
|
||||
“Deployments” on group page and follow the instructions
|
||||
|
||||
|
||||
Output Consumption
|
||||
------------------
|
||||
|
||||
There are four options available for output consumption. These options are used to report/stream/upload/store inference output at an interval defined by the variable ‘reporting_interval’ in the Greengrass samples.
|
||||
a. IoT Cloud Output:
|
||||
This option is enabled by default in the Greengrass samples using a variable ‘enable_iot_cloud_output’. We can use it to verify the lambda running on the edge device. It enables publishing messages to IoT cloud using the subscription topic specified in the lambda (For example, ‘openvino/classification’ for classification and ‘openvino/ssd’ for object detection samples). For classification, top-1 result with class label are published to IoT cloud. For SSD object detection, detection results such as bounding box co-ordinates of objects, class label, and class confidence are published. To view the output on IoT cloud, follow the instructions at https://docs.aws.amazon.com/greengrass/latest/developerguide/lambda-check.html
|
||||
There are four options available for output consumption. These options are
|
||||
used to report/stream/upload/store inference output at an interval defined
|
||||
by the variable ‘reporting_interval’ in the Greengrass samples.
|
||||
|
||||
b. Kinesis Streaming:
|
||||
This option enables inference output to be streamed from the edge device to cloud using Kinesis [3] streams when ‘enable_kinesis_output’ is set to True. The edge devices act as data producers and continually push processed data to the cloud. The users need to set up and specify Kinesis stream name, Kinesis shard, and AWS region in the Greengrass samples.
|
||||
a. IoT Cloud Output:
|
||||
This option is enabled by default in the Greengrass samples using a
|
||||
variable ‘enable_iot_cloud_output’. We can use it to verify the lambda
|
||||
running on the edge device. It enables publishing messages to IoT cloud
|
||||
using the subscription topic specified in the lambda (For example,
|
||||
‘openvino/classification’ for classification and ‘openvino/ssd’ for
|
||||
object detection samples). For classification, top-1 result with class
|
||||
label are published to IoT cloud. For SSD object detection, detection
|
||||
results such as bounding box co-ordinates of objects, class label, and
|
||||
class confidence are published. To view the output on IoT cloud, follow
|
||||
the instructions at https://docs.aws.amazon.com/greengrass/latest/
|
||||
developerguide/lambda-check.html
|
||||
|
||||
c. Cloud Storage using AWS S3 Bucket:
|
||||
This option enables uploading and storing processed frames (in JPEG format) in an AWS S3 bucket when ‘enable_s3_jpeg_output’ variable is set to True. The users need to set up and specify the S3 bucket name in the Greengrass samples to store the JPEG images. The images are named using the timestamp and uploaded to S3.
|
||||
b. Kinesis Streaming:
|
||||
|
||||
This option enables inference output to be streamed from the edge device
|
||||
to cloud using Kinesis [3] streams when ‘enable_kinesis_output’ is set
|
||||
to True. The edge devices act as data producers and continually push
|
||||
processed data to the cloud. The users need to set up and specify
|
||||
Kinesis stream name, Kinesis shard, and AWS region in the Greengrass
|
||||
samples.
|
||||
|
||||
d. Local Storage:
|
||||
This option enables storing processed frames (in JPEG format) on the edge device when ‘enable_s3_jpeg_output’ variable is set to True. The images are named using the timestamp and stored in a directory specified by ‘PARAM_OUTPUT_DIRECTORY’.
|
||||
c. Cloud Storage using AWS S3 Bucket:
|
||||
|
||||
This option enables uploading and storing processed frames (in JPEG
|
||||
format) in an AWS S3 bucket when ‘enable_s3_jpeg_output’ variable is set
|
||||
to True. The users need to set up and specify the S3 bucket name in the
|
||||
Greengrass samples to store the JPEG images. The images are named using
|
||||
the timestamp and uploaded to S3.
|
||||
|
||||
d. Local Storage:
|
||||
|
||||
This option enables storing processed frames (in JPEG format) on the
|
||||
edge device when ‘enable_s3_jpeg_output’ variable is set to True. The
|
||||
images are named using the timestamp and stored in a directory specified
|
||||
by ‘PARAM_OUTPUT_DIRECTORY’.
|
||||
|
||||
References
|
||||
-----------
|
||||
@@ -268,8 +339,23 @@ References
|
||||
|
||||
.. _Edge-Analytics-FaaS: https://github.com/intel/Edge-Analytics-FaaS/tree/master/AWS%20Greengrass
|
||||
|
||||
.. _Alexnet model: deploy.prototxt and bvlc_alexnet.caffemodel
|
||||
.. _download the BVLC Alexnet model: https://github.com/BVLC/caffe/tree/master/models/bvlc_alexnet
|
||||
|
||||
.. _using Model Optimizer: https://software.intel.com/en-us/articles/OpenVINO-ModelOptimizer
|
||||
|
||||
.. _caffe: https://github.com/BVLC/caffe/tree/master/models/bvlc_alexnet
|
||||
.. _AWS Greengrass developer guide: https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-config.html
|
||||
|
||||
.. _Start AWS Greengrass: https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-device-start.html
|
||||
|
||||
.. _AWS Greengrass Core SDK: https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html
|
||||
|
||||
.. _complete creating lambda: https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html
|
||||
|
||||
.. _Configure the Lambda Function: https://docs.aws.amazon.com/greengrass/latest/developerguide/config-lambda.html
|
||||
|
||||
.. _Add local resources and access privileges: https://docs.aws.amazon.com/greengrass/latest/developerguide/access-local-resources.html
|
||||
|
||||
|
||||
.. _deploy the lambda function to AWS Greengrass core device: https://docs.aws.amazon.com/greengrass/latest/developerguide/configs-core.html
|
||||
|
||||
.. _Edge-optmized models repository: https://github.com/intel/Edge-optimized-models
|
||||
|
||||
Reference in New Issue
Block a user