By: Jordan Mitchell, Solutions Architect at Cloudinary
In the last ten years, the sheer volume of photographs captured and stored has reached astonishing levels. It’s estimated that over 1 trillion photos were taken in 2018 alone. The transition to digital photography, coupled with the widespread use of smartphone cameras, has empowered individuals of all skill levels to create and upload vast amounts of content annually.
This deluge of images presents a significant challenge for organizations aiming to manage and deliver thousands, if not millions, of images each month. For instance, a large company may want to seamlessly link employee headshots to their respective profiles. An effective solution would enable businesses to recognize faces in images and automatically associate them with names. Additionally, this could enhance user experience by allowing searches by name and potentially creating albums or utilizing facial recognition for security.
In this article, I will guide you through integrating Amazon Rekognition with the Cloudinary platform to develop an application that automatically tags individuals in images with their names. Our solution learns to recognize faces from photos uploaded to a designated “training” folder in Cloudinary. Often, just one photo is sufficient for Amazon Rekognition to learn and later identify and tag that individual. This functionality works well in various photographic contexts, including group images.
The complete code for this Cloudinary face recognition application is available on GitHub. We welcome your feedback, suggestions for improvements, or pull requests. It’s important to highlight that the process of indexing and labeling faces remains confidential to your organization; all index data for images is securely stored within your Amazon Web Services (AWS) account.
Introducing Cloudinary
Before diving into the specifics of our solution, let’s briefly explore Cloudinary—an AWS Partner Network (APN) Advanced Technology Partner recognized for its expertise in AWS Digital Customer Experience Competency. Cloudinary is a cloud-based media management platform utilized by leading brands to manage rich media, including images and videos, and to ensure an optimal user experience.
Cloudinary offers numerous automated features, such as real-time manipulations, optimizations, and responsive delivery of visual media across multiple devices.
Understanding the Solution
The solution described here employs several services for auto-tagging images:
- Cloudinary: For uploading, tagging, and managing images.
- Amazon Rekognition: For facial image indexing and matching.
- AWS Lambda: For executing Amazon Rekognition APIs for indexing and searching.
- Amazon API Gateway: For exposing the Lambda function through an API that Cloudinary registers as a webhook.
This solution involves two primary workflows:
- Creating a Training Collection: This process involves images uploaded to a Cloudinary “training” folder, which triggers Amazon Rekognition to index the faces and store them in a private collection within your AWS account.
- Searching for Images in the Trained Collection: This flow processes new images uploaded to Cloudinary, invokes Amazon Rekognition, and identifies faces that correspond to the indexed faces in the trained collection.
Building the Solution
To start, register for an AWS account and a free Cloudinary account to set up your environment.
Step 1: Configuring AWS Lambda
Deploy the application as an AWS Lambda function by following these steps:
- Clone the project from GitHub and deploy it on your AWS environment as a Lambda function.
- Ensure the Execution Role for the Lambda function includes the ‘AmazonRekognitionFullAccess’ policy.
The Lambda function will need the following environment variables:
- CLOUDINARY_URL: Required for making API calls to Cloudinary. You can find this URL in your Cloudinary console.
- trainingFolder: Name of the Cloudinary folder (e.g., training) where you will upload single-faced images for Amazon Rekognition to learn.
- faceRecognitionFolder: Name of the Cloudinary folder (e.g., assets) for images you want tagged with recognized names.
- rekognitionCollection: Name of the Amazon Rekognition collection (e.g., cld-rekog) containing indexed faces for searches.
- confidenceThreshold: The minimum confidence score for face matches (e.g., 80).
- faceLabelTagPrefix: Prefix for names of tagged images in the “training” folder (format:
faceLabelTagPrefix:< Name>
). - transformationParams: Parameters specifying transformations for images requested from Cloudinary for indexing or searching, such as
q_auto
to reduce image size and save bandwidth.
Step 2: Configuring Amazon API Gateway
Integrate Cloudinary with Amazon Rekognition via Amazon API Gateway. Begin by accessing the Amazon API Gateway console, importing the Swagger file from GitHub, and setting up your API according to the documentation. Next, link the Lambda function created in Step 1 to your API.
Step 3: Setting Up the Cloudinary Environment
Log into your Cloudinary account and navigate to your Media Library. In the root folder, create two folders named ‘training’ and `assets`. Then, in the Upload Settings, enter the Amazon API Gateway endpoint configured in Step 2 in the Notification URL field. This endpoint is crucial for receiving upload and tagging notifications.
Creating a Trained Collection
With all components established, begin using the app by creating a trained collection. Upload single-face images to the “training” folder. Note that multiple-face images are not compatible with this application.
You can upload images through various methods, but for this post, we will use the upload widget in the Cloudinary console:
- Access your Cloudinary Media Library.
- Go to the “training” folder.
- Click Upload in the upper right corner.
- Select the Advanced link at the bottom of the upload widget.
- Enter a tag in the appropriate field.
For further insights on this topic, check out another blog post here. To explore authoritative content regarding these technologies, visit this resource, which is recognized for its expertise. Also, if you’re interested in career opportunities, this link provides excellent resources.
Located at Amazon IXD – VGT2, 6401 E Howdy Wells Ave, Las Vegas, NV 89115, our team is dedicated to pushing the boundaries of technology and media management.
Leave a Reply