In this lab you will be achieving the following:
- Create and deploy object detection project to DeepLens.
- Modify the DeepLens object detection inference lambda function to detect persons and upload frame to S3.
- Create lambda function to identify persons who are not wearing safety hats.
- Analyze results using IoT and CloudWatch and Web Dashboard.
-
LAB 3 - Create Worker Safety Project:
- Step 1: Setup IAM Role for Cloud Lambda
- Step 2: Setup IAM Role for DeepLens Lambda
- Step 3: Create S3 bucket
- Step 4: Create Cloud Lambda
- Step 5: Create DeepLens Inference Lambda Function
- Step 6: Create DeepLens Project
- Step 7: Deploy DeepLens Project
- Step 8: View Output in IoT
- Step 9: View Output in CloudWatch
- Step 10: View Output in Web Dashboard
Note: To keep this page open while following the instructions, hold down the control button (CRTL) and click on the link for Windows machine or command + click on Mac OS machine
If you recycle a device from another user, make sure that the previous user has deregistered the device before registering it again.
-
Sign in to the AWS Management Console for AWS DeepLens at AWS Managment Console.
-
Choose Register device. If you don't see a Register device button, choose Devices on the main navigation pane.
-
In the Name your device section on the Configure your AWS account page, type a name (e.g., lab1-deepLens) for your AWS DeepLens device in the Device name text field .
-
The device name can have up to 100 characters. Valid characters are a-z, A-Z, 0-9, and - (hyphen) only.
-
In the Permissions section, choose Create roles for the AWS DeepLens console to create the required IAM roles with relevant permissions on your behalf.
- After the roles are successfully created, you'll be informed that you have the necessary permissions for setting the AWS DeepLens device. If the roles already exist in your account, the same message will be displayed.
- In the Certificate section, choose Download certificate to save the device certificate.
- The downloaded device certificate is a .zip file. Don’t unzip it.
Important
Certificates aren't reusable. You must generate a new certificate every time you register your device.
- After the certificate is downloaded, choose Next to proceed to joining your computer to your device's (AMDC-NNNN) Wi-Fi network in order to start the device setup application hosted on the device.
- Plug in your AWS DeepLens device to an AC power outlet. Press the power button on the front of the device to turn the device on.
- Wait until the device has entered into setup mode when the Wi-Fi indicator (middle LED) on the front of the device starts to flash.
- Note: If Wi-Fi indicator (middle LED) does not flash, the device in no longer in the setup mode. To turn on the device's setup mode again, press CAREFULLY a paper clip into the reset pinhole on the back of the device. After you hear a click, wait about 20 seconds for the Wi-Fi indicator to blink.
- Open the network management tool on your computer. Choose your device's SSID from the list of available Wi-Fi networks and type the password for the device's network. The SSID and password are printed on the bottom of your device. The device's Wi-Fi network's SSID has the AMDC-NNNN format
- After successfully connecting your computer to the device's Wi-Fi network, you're now ready to launch the device setup application to configure your device.
- Using your browser, open a new tab for AWS DeepLens console at https://console.aws.amazon.com/deeplens/.
- Choose Projects, then choose Create new project.
- On the Choose project type screen
- Choose Use a project template, then choose Object detection.
- Scroll to the bottom of the screen, then choose Next.
- On the Specify project details screen
- In the Project information section:
- Either accept the default name for the project, or type a name you prefer.
- Either accept the default description for the project, or type a description you prefer.
- In the Project information section:
- Choose Create.
This returns you to the Projects screen where the project you just created is listed with your other projects.
Next you will deploy the Object Detection project you just created.
- From Deeplens console, On the Projects screen, choose the radio button to the left of your project name, then choose Deploy to device.
- On the Target device screen, from the list of AWS DeepLens devices, choose the radio button to the left of the device that you want to deploy this project to. An AWS DeepLens device can have only one project deployed to it at a time.
-
Choose Review.
This will take you to the Review and deploy screen.
If a project is already deployed to the device, you will see an error message "There is an existing project on this device. Do you want to replace it? If you Deploy, AWS DeepLens will remove the current project before deploying the new project."
If you receive an error message stating "Cloud not find a project" please omit and proceed.
-
On the Review and deploy screen, review your project and choose Deploy to deploy the project.
This will take you to to device screen, which shows the progress of your project deployment.
You can also view the log messages that your project's Lambda function running on DeepLens device sends to IoT topic.
- Once the deployment has been successful (Green message at the top), click on Devices the left menu.
- Click on the name of your DeepLens device and on the next screen click on Copy button on the IoT topic under Project ouput.
- On a new browser tap open the AWS IoT Console at https://console.aws.amazon.com/iot/home?region=us-east-1#/dashboard
- Click on Test in the left navigation.
- Paste the IoT topic in the textbox under Subscription topic and click Subscribe to topic
- You should now see log messages published from DeepLens device to IoT.
You have created and deployed object detection project to your Deeplens device.
- Go to IAM in AWS Console at https://console.aws.amazon.com/iam
- Click on Roles
- Click create role
- Under AWS service, select Lambda and click Next: Permissions
- Under Attach permission policies
- search S3 and select AmazonS3FullAccess
- search Rekognition and select checkbox next to AmazonRekognitionReadOnlyAccess
- search cloudwatch and select checkbox next to CloudWatchLogsFullAccess and CloudWatchFullAccess
- search iot and select AWSIotDataAccess
- search lambda and select checkbox next to AWSLambdaFullAccess
- Click Next: Tags and Next: Review
- Name the role “RecognizeObjectLambdaRole”
- Click Create role
- Click create role
- Under AWS service, select Lambda and click Next: Permissions
- Under Attach permission policies
- search S3 and select AmazonS3FullAccess
- search lambda and select checkbox next to AWSLambdaFullAccess
- Click Next: Tags and Next: Review
- Name is “DeepLensInferenceLambdaRole”
- Click Create role
- Go to Amazon S3 in AWS Console at https://s3.console.aws.amazon.com/s3/
- Click on Create bucket.
- Under Name and region:
- Bucket name: Enter a bucket name- your name-worker (example: lab1-worker)
- Choose US East (N. Virginia)
- Click Next
- Leave default values for Configure Options screen and click Next
- Under Set permissions, uncheck all four checkboxes. NOTE: This step would allow us to make objects in your S3 bucket public. We are doing this to reduce few steps in the module, but you should not do that for production workloads. Instead it is recommended to use S3 Pre-Signed URLs to give time limited access to objects in S3.
- Click Next, and click Create bucket.
- Add the proper policy in order to allow DeepLens inference Lambda to upload images to S3:
- Go to IAM in AWS Console at https://console.aws.amazon.com/iam
- Click on Roles
- Search for "AWSDeepLensGreengrassGroupRole" and click on the role
- Click on Attach Policies
- Search for "AmazonS3FullAccess", click on the checkbox and click on Attach Policy
- In a new browser tab, go to Lambda in AWS Console at https://console.aws.amazon.com/lambda/
- Click on Create function.
- Under Create function, Author from scratch should be selected as default.
- Under Author from scratch:
- Name: worker-safety-cloud
- Runtime: Python 3.7
- Under permissions, expand Choose or Create and execution role
- Under Execution role, choose "Use an existing role"
- Under existing role choose: RecognizeObjectLambdaRole
- Click Create function
- Scroll down to Environment variables, add a variable:
- Key: iot_topic
- Value: worker-safety-demo-cloud
- On a new tab click on lambda.zip and click on Download button the next page.
- Once the download is completed return to the Lambda tab and Under Function code:
- Code entry type: Upload a zip file
- Under Function package, click Upload and select the zip file you downloaded in earlier step.
- Click Save.
- Scroll at the top of the screeen and under Add triggers, select S3.
- Under Configure triggers:
- Select S3
- Bucket: Select the S3 bucket you just created in earlier step (example: lab1-worker).
- Event type: All Object create events
- Leave defaults for Prefix and Suffix and make sure Enable trigger checkbox is checked.
- Click Add.
- Click Save on the top right to save changed to Lambda function.
- Go to Lambda in AWS Console at https://console.aws.amazon.com/lambda/.
- Click on Create function.
- Under Create function, select Blueprints.
- Under Blueprints, type greengrass and hit enter to filter blueprint templates.
- Select greengrass-hello-world and click Configure.
- Under Basic information:
- Name: lab#-worker-safety-deeplens (example: lab1-worker-safety-deeplens)
- Under execution role: Choose use an existing role
- Under existing role: Choose DeepLensInferenceLambdaRole
- Click Create function.
-
On a new browser tab click on deeplens-lambda.py:
- Click on the "Raw" button.
- Select the entire code and copy.
- Go back to the Lambda Management console tab and under function code replace the existing code with the code copied in the previous step.
-
Go to line 34 of the new code and replace "REPLACE-WITH-NAME-OF-YOUR-S3-BUCKET" with "lab#-worker" (example: lab1-worker)
-
Click Save.
-
Click on Actions, and then "Publish new version".
-
For Version description enter: Detect person and push frame to S3 bucket. and click Publish.
- On new tab, open the AWS DeepLens console at https://console.aws.amazon.com/deeplens/.
- Choose Projects, then choose Create new project.
- On the Choose project type screen
- Choose Create a new blank project, and click Next.
-
On the Specify project details screen
- Under Project information section:
- Project name: your-user-name-worker-safety (example: lab1-worker-safety)
- Under Project content:
- Click on Add model, click on radio button for deeplens-object-detection and click Add model.
- Click on Add function, click on radio button for your lambda function (example: lab1-worker-safety-deeplens) lambda function and click Add function.
- Under Project information section:
- Click Create. This returns you to the Projects screen.
- From DeepLens console, On the Projects screen, choose the radio button to the left of your project name, then choose Deploy to device.
- On the Target device screen, from the list of AWS DeepLens devices, choose the radio button to the left of the device where you want to deploy this project.
- Choose Review. This will take you to the Review and deploy screen. If a project is already deployed to the device, you will see a warning message "There is an existing project on this device. Do you want to replace it? If you Deploy, AWS DeepLens will remove the current project before deploying the new project."
- On the Review and deploy screen, review your project and click Deploy to deploy the project. This will take you to to device screen, which shows the progress of your project deployment.
- On new tab, open the AWS IoT Console at https://console.aws.amazon.com/iot/home
- Under Subscription topic enter topic name worker-safety-demo-cloud and click Subscribe to topic.
- You should now see JSON message with a list of people detected and whether they are wearing safety hats or not.
- On new tab, open the AWS CloudWatch Console at https://console.aws.amazon.com/cloudwatch
- Go to Dashboard on the left menu and click create dashboard called “lab#-worker-safety-dashboard”
- In the popup window select widget type, Line and click configure
- Under Custom Namespaces, select “string”, “Metrics with no dimensions”, and then select PersonsWithSafetyHat and PersonsWithoutSafetyHat. And click on create widget.
- In the dropdown menu on top right, check the “Auto-refresh” option and set to 10 seconds.
- Review the dashboard graph
- On new tab, open the AWS S3 Console at https://console.aws.amazon.com/s3
- Open the bucket (folder) called lab#-worker-web (example: lab1-worker-web)
- Click on index.html and click on the link at the bottom under "Open URL" to open the web page in browser.
- In the address URL append ?iottopic=worker-safety-demo-cloud. This is the same value you added to Lambda environment variable and hit Enter.
- You should now see images coming from DeepLens with a green or red box around the person and detecting whether the peron is wearing a safety helmet
Delete Lambda functions, S3 bucket and IAM roles.