Skip to content

Commit b0be0fb

Browse files
committed
Add human sampling & standardize SNS messages
1 parent f631c2e commit b0be0fb

File tree

22 files changed

+910
-277
lines changed

22 files changed

+910
-277
lines changed

0-Prerequisites/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
- You need to initialize Rekognition Custom Labels for your selected Region before you can use Rekognition Custom Labels. On the Rekognition Custom Labels console, choose **Projects** in the navigation pane and take one of the following actions:
2121
- If you see the **Projects** page with or without projects, then your Region is initialized.
22-
- If you’re prompted with a message for first-time setup, follow the instructions to create the default [Amazon Simple Storage Service](http://aws.amazon.com/s3) (Amazon S3) bucket. We don’t use the default S3 bucket with this solution, but it’s part of the Rekognition Custom Labels initialization process.
22+
- If you’re prompted with a message for first-time setup, follow the instructions to create the default [Amazon Simple Storage Service](https://aws.amazon.com/s3) (Amazon S3) bucket. We don’t use the default S3 bucket with this solution, but it’s part of the Rekognition Custom Labels initialization process.
2323

2424
Next Step: [Deployment](../1-Deployment/)

2-Parameter-Store/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
Because model performance can change over inference results, you need to implement an automated ML workflow that can continuously retrain a model with newly captured and human-labeled images. In addition, you need to consider adding flexibility into the ML workflow to allow for change without requiring development rework as business objectives evolve over time. Developing a customizable ML workflow that behaves similar to a business rule engine requires significant upfront investment, which can be a resource challenge.
44

5-
In this demo, we provide a set of configurable parameters for you to use to customize the ML workflow. Go to [AWS Systems Manager Parameter Store](https://console.aws.amazon.com/systems-manager/parameters). You should see a list of 8 parameters as shown below:
5+
In this demo, we provide a set of configurable parameters for you to use to customize the ML workflow. Go to [AWS Systems Manager Parameter Store](https://console.aws.amazon.com/systems-manager/parameters). You should see a list of 11 parameters as shown below:
66

7-
- **Automatic-Training-Poll-Frequency** - This is the polling frequency (in integer minutes) on how often the [Amazon EventBridge](https://aws.amazon.com/eventbridge/) Schedule rule is triggered to initiate the check for automatic model training. As you update this value, the value is applied to the rule by an [AWS Lambda](http://aws.amazon.com/lambda) function.
7+
- **Automatic-Human-Sampling-Frequency** - This is the polling frequency (in integer minutes) on how often the [Amazon EventBridge](https://aws.amazon.com/eventbridge/) Schedule rule is triggered to initiate the check for human sampling. As you update this value, the value is applied to the rule by an [AWS Lambda](https://aws.amazon.com/lambda) function.
8+
- **Automatic-Training-Poll-Frequency** - This is the polling frequency (in integer minutes) on how often the [Amazon EventBridge](https://aws.amazon.com/eventbridge/) Schedule rule is triggered to initiate the check for automatic model training. As you update this value, the value is applied to the rule by an [AWS Lambda](https://aws.amazon.com/lambda) function.
89
- **Enable-A2I-Workflow** - This value (`true/false`) determines whether an [Amazon SageMaker](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-start-human-loop.html) Human Loop is created when the inference confidence level from the [Amazon Rekognition Custom Labels](https://aws.amazon.com/rekognition/custom-labels-features/) detection result is less than the [minimum confidence](https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/detecting-custom-labels.html) as set in the **Minimum-Label-Detection-Confidence** parameter.
10+
- **Enable-Automatic-Human-Sampling** - This value (`true/false`) determines whether automatic human sampling is `enabled/disabled`. When this value is updated to `true`, a Lambda function enables the EventBride Schedule rule. When the value is updated to `false`, a Lambda function disables the EventBride Schedule rule.
911
- **Enable-Automatic-Training** - This value (`true/false`) determines whether automatic model training is `enabled/disabled`. When this value is updated to `true`, a Lambda function enables the EventBride Schedule rule. When the value is updated to `false`, a Lambda function disables the EventBride Schedule rule.
1012
- **For-System-Use-Only** - Do **NOT** modify this value. This is a reserved parameter consisting of environmental variables and operation data. The value is used and updated by Lambda functions.
11-
- **Minimum-Label-Detection-Confidence** - Rekognition Custom Labels returns a **Confidence** between 0-100 on each detection. The **Minimum Confidence** (Float 0.00-100.00) determines whether a detection result is acceptable. If the detection **Confidence** is greater than or equal to the **Minimum Confidence**, then the detection is accepted. If not, the image is sent to [Amazon Augmented AI](https://aws.amazon.com/augmented-ai/) (Amazon A2I) human labeling process, provided that **Enable-A2I-Workflow** is `enabled`.
13+
- **Human-Sampling-Interval** - This value (Int) represents the minimum number of new Rekognition Custom Labelsdetections since the last human sampled detection before a new human sample is needed. If a new detection meets the interval requirement, it is marked for human sampling. An Amazon A2I human workflow is created, if a human workflow does not exist already.
1214
- **Minimum-F1-Score** - This value is the minimum [F1 score](https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/gs-step-evaluate-model.html) (Float 0.00-1.00) that determines whether a newly trained model is acceptable for deployment. If the **F1 score** of the trained Model is greater or equal to the **Minimum-F1-Score** value, the model will be deployed. If not, the model is marked as failed training.
13-
- **Minimum-Inference-Units** - This value (Int), with a minimum of `1`, is number of [inference unit](https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/rm-run-model.html) to use for the running Rekognition Customs Label model. A single inference unit represents 1 hour of processing and can support up to 5 Transaction Pers Second (TPS). Use a higher number to increase the TPS throughput of your model. You are charged for the number of inference units that you use.
15+
- **Minimum-Inference-Units** - This value (Int), with a minimum of `1`, is number of [inference unit](https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/rm-run-model.html) to use for the running Rekognition Customs Labelsmodel. A single inference unit represents 1 hour of processing and can support up to 5 Transaction Pers Second (TPS). Use a higher number to increase the TPS throughput of your model. You are charged for the number of inference units that you use.
16+
- **Minimum-Label-Detection-Confidence** - Rekognition Custom Labels returns a **Confidence** between 0-100 on each detection. The **Minimum Confidence** (Float 0.00-100.00) determines whether a detection result is acceptable. If the detection **Confidence** is greater than or equal to the **Minimum Confidence**, then the detection is accepted. If not, the image is sent to [Amazon Augmented AI](https://aws.amazon.com/augmented-ai/) (Amazon A2I) human labeling process, provided that **Enable-A2I-Workflow** is `enabled`.
1417
- **Minimum-Untrained-Images** - This value (Int) represents the minimum number of untrained or newly added images that will qualify the state machine to start a new model training process. At the instance the polled event is triggered, a Lambda function first determines the total number of training images in the designated S3 folder. Next it retrieves the value `previous_trained_images` from the parameter **For-System-Use-Only**. If the difference between the total number of images in S3 and the previous_trained_images is greater than or equal to minimum untrained images, then it will trigger a new model training. On a successful training, a Lambda function updates the `previous_trained_images` with the current total number of images trained.
1518

1619

3-Model-Training/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Rekognition Custom Labels supports two methods of labeling datasets: [object-lev
66

77
We use Amazon and AWS logos for our initial training images. The images are located in the `sample-images` folder. We use the folder name as the label such that images in the **amazon_logo** and **aws_logo** folders are labeled `amazon_log` and `aws_logo`, respectively.
88

9-
In this section, we walk you through the steps to add training images to [Amazon Simple Storage Service](http://aws.amazon.com/s3) (Amazon S3) and explain how the automatic model training process works.
9+
In this section, we walk you through the steps to add training images to [Amazon Simple Storage Service](https://aws.amazon.com/s3) (Amazon S3) and explain how the automatic model training process works.
1010

1111
1. On the [Amazon S3](https://s3.console.aws.amazon.com/s3/home) console, choose the bucket with the name similar to `yourstackname-s3bucket-esxhty0wyhqu`. and select the bucket with name similar to "yourstackname-s3bucket-esxhty0wyhqu". You should see 5 folders:
1212
- a2i-human-loop-data/

4-Custom-Labels-Detection/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ In this section, we walk you through the steps to detect custom logos and explai
55
1. Navigate to the [Amazon S3](https://s3.console.aws.amazon.com/s3/home) bucket and choose the `images_for_detection` folder.
66
2. Upload an image that you used previously for training.
77

8-
The upload process triggers an S3 `PutObject` event, which invokes an [AWS Lambda](http://aws.amazon.com/lambda) function to run the Rekognition Custom Labels detection process. You should receive an email with a detection result indicating a confidence score of at least 70, which is as expected because you’re using the same image you used for training.
8+
The upload process triggers an S3 `PutObject` event, which invokes an [AWS Lambda](https://aws.amazon.com/lambda) function to run the [Amazon Rekognition Custom Labels](https://aws.amazon.com/rekognition/custom-labels-features/) detection process. Upon successful completion of the detection event, the Lambda function performs additional tasks:
9+
- Log the image detection results to [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) table
10+
- Create an Amazon A2I human labeling task if the detection confidence level is less then the minimum confidence level and A2I workflow is enabled
11+
- Log the Amazon A2I request information to the DynamoDB table
12+
13+
You should receive an email with a detection result indicating a confidence score of at least 70, which is as expected because you’re using the same image you used for training.
914

1015
3. Upload all the images in the `inference_images` folder.
1116

1217
You should receive emails with detection results with varying confidence scores, and some should indicate that Amazon A2I human loops have been created. When a detection result has a confidence score less than the acceptance level, which is currently set at 70, a human labeling task is created to label that image.
1318

1419
4. Optionally, go to the [AWS Step Functions](https://console.aws.amazon.com/states/) console to review the state machine runs of the custom label detection events.
1520

21+
5. Optionally, go to the [Amazon DynamoDB](https://console.aws.amazon.com/dynamodb/) console to review the custom label detection and A2I event logs.
22+
1623

1724
Next Step: [5-A2I-Human-Loop](../5-A2I-Human-Loop/)

5-A2I-Human-Loop/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ If the private team was deployed for you, the username and temporary password ar
2929
9. For each image, review the image and choose the correct Amazon company logo or **None of the Above** to use as label.
3030
10. Keep a tally of the options you choose in each task.
3131
11. Choose **Submit** to advance to the next image until you have completed all the labeling tasks.
32-
12. Return to the i`mages_labeled_by_folder` folder and review the changes.
32+
12. Return to the `images_labeled_by_folder` folder and review the changes.
3333

34-
For each image you labeled, an [AWS Lambda](http://aws.amazon.com/lambda) function makes a copy of the original image, appends the prefix `humanLoopName` and an UUID to the original S3 object key, and adds it to the corresponding labeled folder. If the folder doesn’t exist, the Lambda function creates a corresponding labeled folder. For the `None of the Above` labels, nothing is done. This is how newly captured and labeled images are added to the training dataset.
34+
For each image you labeled, an [AWS Lambda](https://aws.amazon.com/lambda) function performs two tasks:
35+
- Make a copy of the original image, appends the prefix `humanLoopName` and an UUID to the original S3 object key, and adds it to the corresponding labeled folder. If the folder doesn’t exist, the Lambda function creates a corresponding labeled folder. For the `None of the Above` labels, nothing is done. This is how newly captured and labeled images are added to the training dataset.
36+
- Log the A2I results to the corresponding detection event for other downstream processes
3537

36-
Next Step: [6-Conclusions-Cleanup](../6-Conclusions-Cleanup/)
38+
Next Step: [6-Human-Sampling](../6-Human-Sampling/)

6-Human-Sampling/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## 6 Automatic human sampling
2+
3+
In this section, we explain the design principle and the processes behind the human sampling workflow.
4+
5+
**Design principle**
6+
The principle for the human-in-the-loop workflow is intended for model improvement by capturing inference images with [Amazon Rekognition Custom Labels](https://aws.amazon.com/rekognition/custom-labels-features/) with low confidence detection result and add them to the training dataset for new training. The principle for human sampling workflow is intended for business improvement. In human sampling, for every `nth` detection, the detection is flagged for human review and the human-labeled result is compared against the detected one, regardless of the original detection confidence level. The sampled detections can then used for qualify control, audit, analytics, etc. Although both workflows use the same [Amazon A2I](https://aws.amazon.com/augmented-ai/) process, inference images flagged as `sampled only` are **not** add to the training dataset.
7+
8+
**Workflow**
9+
The human sampling workflow is configurable by three [Amazon Parameter Store](https://console.aws.amazon.com/systems-manager/parameters) parameters as explained in [Section 2-Parameter Store](../2-Parameter-Store/). When **Enable-Automatic-Human-Sampling** is enabled, an [Amazon EventBridge](https://aws.amazon.com/eventbridge/) schedule rule is triggered every `nth` minutes as set in **Automatic-Human-Sampling-Frequency** to invoke the processes orchestrated by [AWS Step Functions](https://aws.amazon.com/step-functions/). The processes include:
10+
11+
1. Initialize the starting `query date` with the `Last modified date` of **Enable-Automatic-Human-Sampling**. The purpose is to sample forward instead retroactively finding historic samples.
12+
2. Query the minimum number (`limit`) of detection events as set in **Human-Sampling-Interval** forward from the `query date`
13+
3. If the query result count is less than the minimum number, then the process ends. Otherwise the last (`limit`) detection event is marked as sampled and the new `query date` is set to the detection event date.
14+
4. Next an A2I human labeling task is created if none exists from another process and the originating source is marked as `Human Sampling`.
15+
5. Repeat Steps 2 through 4.
16+
17+
Finally the labeling task is completed as explained in [Section 5-A2I Human Loop](../5-A2I-Human-Loop/).
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
Next Step: [7-Conclusions-Cleanup](../7-Conclusions-Cleanup/)

6-Conclusions-Cleanup/README.md renamed to 7-Conclusions-Cleanup/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## 6 Conclusion and cleanup resources
1+
## 7 Conclusion and cleanup resources
22

33
**Conclusions**
4-
In this demo we explained how to build an automated and configurable continuous model improvement workflow for [Amazon Rekognition Custom Labels](https://aws.amazon.com/rekognition/custom-labels-features/) and [Amazon Augmented AI](https://aws.amazon.com/augmented-ai/) (Amazon A2I). By incorporating [Amazon Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), we demonstrated how to use parameters as variables for [AWS Step Functions](https://aws.amazon.com/step-functions/) to customize the behaviors of the ML workflow without needing development rework. We walked through the steps to deploy the solution with [AWS CloudFormation](https://aws.amazon.com/cloudformation/) and completed an end-to-end process to train and deploy a Rekognition Custom Labels model, perform custom label detection, and create and complete Amazon A2I human labeling tasks.
4+
In this demo we explained how to build an automated and configurable continuous model improvement workflow for [Amazon Rekognition Custom Labels](https://aws.amazon.com/rekognition/custom-labels-features/) and [Amazon Augmented AI](https://aws.amazon.com/augmented-ai/) (Amazon A2I). By incorporating [Amazon Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), we demonstrated how to use parameters as variables for [AWS Step Functions](https://aws.amazon.com/step-functions/) to customize the behaviors of the ML workflow without needing development rework. We walked through the steps to deploy the solution with [AWS CloudFormation](https://aws.amazon.com/cloudformation/) and completed an end-to-end process to train and deploy a Rekognition Custom Labels model, perform custom label detection, create and complete Amazon A2I human labeling tasks, and generate human samples.
55

66
Things to consider to enhance this worfklow:
77
- Add additional parameters to control the behaviors of this workflow.
@@ -18,16 +18,19 @@ Complete the following steps to clean up the AWS resources that we created as pa
1818

1919
The following resources are not deleted by CloudFormation:
2020
- S3 bucket
21-
- Rekognition Custom Labels project
21+
- Rekognition Custom Labels project & models
22+
- DynamoDB table
2223
- [Amazon SageMaker Ground Truth](https://aws.amazon.com/sagemaker/groundtruth/) private workforce
2324

2425
3. On the S3 console, choose the bucket you used for this post.
2526
4. Choose **Empty**.
2627
5. Choose **Delete**
27-
6. On the Rekognition Custom Label console, choose the running model.
28+
6. On the Rekognition Custom Labelsconsole, choose the running model.
2829
7. On the **Evaluate and use model** tab, expand the **API Code** section.
29-
8. Run the [AWS Command Line Interface](http://aws.amazon.com/cli) (AWS CLI) stop model command.
30+
8. Run the [AWS Command Line Interface](https://aws.amazon.com/cli) (AWS CLI) stop model command.
3031
9. On the **Projects** page, select the project and choose **Delete**.
31-
10. To delete the private workforce, enter the following code (leave the workforce name as `default` and provide your Region):
32+
10. On the DyanmoDB console, select the table you used for this post.
33+
11. Choose **Delete**
34+
12. To delete the private workforce, enter the following code (leave the workforce name as `default` and provide your Region):
3235

3336
`aws sagemaker delete-workforce --workforce-name default --region your-region-x`

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ This project has adopted the [Amazon Open Source Code of Conduct](https://aws.gi
4949

5050
## Security issue notifications
5151

52-
If you discover a potential security issue, please notify AWS Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public issue on GitHub.
52+
If you discover a potential security issue, please notify AWS Security via our [vulnerability reporting page](https://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public issue on GitHub.
5353

5454
## Licensing
5555

0 commit comments

Comments
 (0)