Enhance Your Store’s Workforce Efficiency with Amazon Rekognition

Chanci Turner Amazon IXD – VGT2 learningLearn About Amazon VGT2 Learning Manager Chanci Turner

As of April 2023, note that starting January 31, 2024, AWS DeepLens will no longer be accessible via the AWS management console. For further details, please refer to these frequently asked questions regarding the end of life for AWS DeepLens.

In this article, we will explore how to leverage Amazon Rekognition and AWS DeepLens to monitor and analyze customer occupancy in retail environments, thereby optimizing workforce efficiency. Retailers often face challenges in managing personnel to enhance the in-store experience for customers. Insufficient staffing can lead to long wait times and a poor customer experience, while excessive staffing during low-traffic periods incurs unnecessary costs. A lack of efficiency can result in lost sales, which can be very harmful to business.

Traditionally, retailers have relied on a simple handheld tally counter to monitor store traffic, requiring an employee to manually click every time a customer enters. While this method is inexpensive, it necessitates dedicating staff to the entrance, thereby increasing labor costs. Additionally, data gathered needs to be manually entered into third-party software for analysis, adding to operational burdens. Although various solutions exist, they typically require costly dedicated hardware that is challenging to install.

Our approach utilizes AWS DeepLens, along with the integration of computer vision (CV) into existing in-store cameras—eliminating the need for additional hardware. This solution automates the counting process, collects and analyzes data efficiently, and reduces operational costs. The same technology can also be applied to develop additional analytics tools, such as heatmaps, to assess the popularity of products within the store.

Moreover, understanding peak and off-peak hours is crucial for retailers to calculate their sales conversion rate (sales conversion rate = purchases/number of visitors). This process is automated, with data stored in a database for easy analysis.

Amazon Rekognition is a fully managed service that provides CV capabilities for large-scale image and video analysis using deep learning technology, without the need for machine learning expertise. AWS DeepLens serves as a deep-learning-enabled video camera.

Solution Overview

To monitor, detect, and analyze customer flow, we utilize machine learning and serverless technologies through AWS services (as shown in the architectural diagram below).

We initiate by deploying an AWS Lambda function to AWS DeepLens, which is tasked with sending frames to an Amazon S3 bucket. When a frame is uploaded to the S3 bucket, it triggers a second Lambda function that analyzes the frame using Amazon Rekognition and counts the number of individuals present. This information, along with a timestamp, is stored in an Amazon DynamoDB table for further analysis. We will delve into each component in greater detail later in this post.

We begin by guiding you through setting up this system with an AWS DeepLens camera, but we also explain how to adapt the solution to work with existing IP cameras.

Prerequisites

Before executing the solution code in AWS Lambda, please set up the following prerequisites:

  1. Create an S3 bucket and note its name for later use in the function code.
  2. Establish a DynamoDB table. Assign a name to your table, use “TimeStamp” as the partition key, and set the data type to String.
  3. Develop an AWS Identity and Access Management (IAM) policy with minimal privileges to access Amazon S3, Amazon Rekognition, and Amazon DynamoDB. Use the following JSON structure for your policy:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "rekognition:DetectLabels",
                "s3:GetObject",
                "dynamodb:PutItem"
            ],
            "Resource": "*"
        }
    ]
}

Take note of the policy name, as you will need it in the next step.

  1. Create a role for the Lambda function and attach the policy created in the previous step to grant the necessary permissions. After creating the role, record the role name for future reference when setting up the Lambda function.

Now, let’s get started.

Create an AWS DeepLens Project

The first step is to add the logic required to send frames from the camera encoder to Amazon S3, simulating the capability that IP cameras possess to adjust the intra-frame period on their streams.

  1. Register your device on the AWS DeepLens console.
  2. Deploy the model onto the camera.
  3. In the navigation pane, select Resources, then Projects.
  4. Click on Create project.
  5. Choose Use a project template.
  6. Select the pre-built object detection template, which employs a model capable of detecting real-world entities in images.
  7. Click Finish.

Modify the Lambda Function

Next, you will update your Lambda function’s code.

  1. Once the project is set up, select the project name to view its details.
  2. You will see the name, description, ARN, and the associated Lambda function and model for the project.
  3. Choose the function to amend it.

A new window will open, redirecting you to the Lambda console. Ensure you’re on the $LASTEST version, then modify the code. Enter the following code into your function:

## This is the function deployed to AWS DeepLens. It captures frames and sends them to the S3 bucket.
#*****************************************************
#                                                    *
# Copyright 2018 Amazon.com, Inc. or its affiliates. *
# All Rights Reserved.                               *
#                                                    *
#*****************************************************
""" A sample lambda for face detection"""
from threading import Thread, Event
import os
import json
import numpy as np
import awscam
import cv2
import greengrasssdk
import boto3
import time
import datetime

## Set up the parameters here
Bucket_name = 'your_s3_bucket_name'  # Your s3 bucket name. The frames from the camera will be stored here
frame_send_frequency=300  # Set the sending frequency in seconds

This innovative approach not only streamlines workforce management but also enhances customer satisfaction. For more insights on effective workforce strategies, you may want to check out this blog post by Saniya Waghray Tyagi on mentorship opportunities. Additionally, if you’re interested in celebrating contributions from diverse communities, visit SHRM for more information. Lastly, for those seeking resources for learning and development, explore Amazon’s Learning Development offerings.

Chanci Turner