Announcing the launch of the model copy feature for Amazon Rekognition Custom Labels
Amazon Rekognition Custom Labels is a fully managed computer vision service that allows developers to build custom models to classify and identify objects in images that are specific and unique to your business. Rekognition Custom Labels doesn’t require you to have any prior computer vision expertise. For example, you can find your logo in social media posts, identify your products on store shelves, classify machine parts in an assembly line, distinguish healthy and infected plants, or detect animated characters in videos.
Developing a custom model to analyze images is a significant undertaking that requires time, expertise, and resources, often taking months to complete. Additionally, it often requires thousands or tens of thousands of hand-labeled images to provide the model with enough data to accurately make decisions. Generating this data can take months to gather and requires large teams of labelers to prepare it for use in machine learning (ML).
Rekognition Custom Labels builds off of the existing capabilities of Amazon Rekognition, which are already trained on tens of millions of images across many categories. Instead of thousands of images, you simply need to upload a small set of training images (typically a few hundred images or less) that are specific to your use case using the Amazon Rekognition console. If the images are already labeled, you can begin training a model in just a few clicks. If not, you can label them directly on the Rekognition Custom Labels console, or use Amazon SageMaker Ground Truth to label them. Rekognition Custom Labels uses transfer learning to automatically inspect the training data, select the right model framework and algorithm, optimize the hyperparameters, and train the model. When you’re satisfied with the model accuracy, you can start hosting the trained model with just one click.
Today we’re happy to announce the launch of the Rekognition Custom Labels model copy feature. This feature allows you to copy your Rekognition Custom Labels models across projects, which can be in the same AWS account or across AWS accounts in the same AWS Region, without retraining the models from scratch. This new capability makes it easier for you to move Rekognition Custom Labels models through various environments such as development, quality assurance, integration, and production without needing to copy the original training and test datasets and retraining the model. You can use the AWS Command Line Interface (AWS CLI) to copy trained models across projects, which can be in the same AWS account or across AWS accounts.
In this post, we show you how to copy models between different AWS accounts in the same AWS Region.
Benefits of the model copy feature
This new feature has the following benefits:
Multi-account ML-Ops best practices – You can train a model one time and ensure predictable deployment with consistent results across multiple accounts mapped to various environments such as development, quality assurance, integration, and production allowing you to follow ML-Ops best practices within your organization.
Cost savings and faster deployment – You can quickly copy a trained model between accounts, avoiding the time taken to retrain in every account and saving on the model retraining cost.
Protect sensitive datasets – You no longer need to share the datasets between different AWS accounts or users. The training data needs to be available only on the AWS account where model training is done. This is very important for certain industries, where data isolation is essential to meet business or regulatory requirements.
Easy collaboration – Partners or vendors can now easily train Amazon Rekognition Custom Labels model in their own AWS account and share the models with users across AWS accounts.
Consistent performance – Model performance is now consistent across different AWS accounts. Model training is generally non-deterministic and two models trained with the same dataset does not guarantee the same performance scores and the same predictions. Copying the model helps make sure that the behavior of the copied model is consistent with the source model eliminating the need to re-test the model.
The following diagram illustrates our solution architecture.
This post assumes you have a trained a Rekognition Custom Labels model in your source account. For instructions, refer to Training a custom single class object detection model with Amazon Rekognition Custom Labels. In this post, we used the image classification “Rooms” project from the Rekognition Custom Labels sample projects list and trained a room classification model in the source account to classify images of kitchens, bathrooms, living rooms, and more.
To demonstrate the functionality of the model copy feature, we go through the following steps in the source account:
Start the model and run inferences on sample images.
Define a resource-based policy to allow cross-account access to copy the Rekognition Custom Labels model.
Then we copy the source model to the target account.
Create an Amazon Simple Storage Service (Amazon S3) bucket, which serves as a container for the model evaluation and performance statistics.
Create a project.
Copy the trained model from the source account to the target account.
Start the model and run inference on the sample images.
Verify the inference results match the results of the source account model.
In addition to having a trained model in your source account, make sure you complete the following prerequisite steps:
Install the AWS CLI V2.
Configure your AWS CLI with the following code and enter your Region:
Run the following commands to ensure you have AWS CLI version 2.xx installed on your local host:
Update the AWS credentials file under $HOME/.aws/credentials with the following entry:
Get the ProjectArn and ProjectVersionArn for the source AWS account.ProjectArn is the project associated with your source model. ProjectVersionArn is the version of the model you’re interested in copying to the target account.You can find the SourceProjectArn using the following command:
If you see multiple lines of output, pick the ProjectArn associated with the model you’re going to copy.
You can find the SourceProjectVersionArn for the model you trained using the SourceProjectArn (the preceding output). Replace the SourceProjectArn in the following command:
The command returns the SourceProjectVersionArn. If you see multiple lines of output, pick the ProjectVersionArn of interest.
You’re now ready to run the steps to implement the solution. Replace the values of SourceProjectArn and SourceProjectVersionArn in the following commands with the values you generated.
1. Start the model and run inference on sample images
In the source account, enter the following code to start the model:
After the model is hosted and in the running state, you can run inference.
We used the following images (demo1.jpeg and demo2.jpeg) to run inference. These images are located in our local file system in the same directory where the AWS CLI commands are being run from.
The following image is demo1.jpeg, which shows a backyard.
See the following inference code and output:
The following image is demo2.jpeg, which shows a bedroom.
See the following inference code and output:
The inference results show the image belongs to the classes backyard and bedroom, with a confidence score of 45.77 and 61.84, respectively.
2. Define the IAM resource policy for the trained model to allow cross-account access
To create your resource-based IAM policy, complete the following steps in the source account:
Allow your specific AWS account to access resources using the provided IAM resource policy (for more information, refer to Creating a project policy document. Replace the values for TargetAWSAccountId and SourceProjectVersionArn in the following policy:
Attach the policy to the project in the source account by calling the following command.
Replace SourceProjectArn, PolicyName, TargetAWSAccountId, and SourceProjectVersionArn.
The output shows the policy revision ID created:
Now we’re ready to copy the trained model from the source account to the target account.
3. Create an S3 bucket in the target account
You can use an existing S3 bucket in your account or create a new S3 bucket. For this post, we call this S3 bucket DestinationS3Bucket.
4. Create a new Rekognition Custom Labels project
Create a new project with the following code:
This creates a TargetProjectArn in the target account:
Note the value of the destination project ProjectArn field. We use this value in the following copy model command.
5. Copy the model from the source account to the target account
Supply the source and target ProjectArn, source ProjectVersionArn, and target S3 bucket and S3 key prefix in the following code:
This creates a copied model TargetProjectVersionArn in the target account. The TargetVersionName in our case has been named copy_rooms_1:
Check the status of the model copy process:
The model copy from the source account to the target account is complete when the Status changes to COPYING_COMPLETED:
6. Start the model and run inference
Enter the following code to start the model in the target account:
Check the status of the model:
The model is now hosted and running:
Run inference with the following code:
7. Verify the inference results match
The classes and the confidence scores for the images demo1.jpg and demo2.jpg in the target account should match the results in the source account.
In this post, we demonstrated the Rekognition Custom Label model copy feature. This feature enables you to train a classification or object detection model in one account and then share the model with another account in the same Region. This simplifies the multi-account strategy where the model can be trained one time and shared between accounts within the same Region without having to retrain or share the training datasets. This allows for a predicable deployment in every account as part of your MLOps workflow. For more information, refer to Copying an Amazon Rekognition Custom Labels model, or try out the walkthrough in this post using a cloud shell with the AWS CLI.
As of this writing, the model copy feature in Amazon Rekognition Custom Labels is available in the following Regions:
US East (Ohio)
US East (N. Virginia)
US West (Oregon)
Asia Pacific (Mumbai)
Asia Pacific (Seoul)
Asia Pacific (Singapore)
Asia Pacific (Sydney)
Asia Pacific (Tokyo)
Give the feature a try, and please send us feedback either via the AWS forum for Amazon Rekognition or through your AWS support contacts.
About the authors
Yogesh Chaturvedi is a Solutions Architect at AWS with a focus in computer vision. He works with customers to address their business challenges using cloud technologies. Outside of work, he enjoys hiking, traveling, and watching sports.