ML Fridays Rapidly build state of the art image classification and detection models

Sumir Kumar/Arun Lokanatha Kumar Solution Architects Date : 30-04-2021

© 2020, Web Services, Inc. or its Affiliates. Agenda

• A brief background of Computer Vision

• Introduction to Custom Labels

• Walkthrough of Rekognition Custom Labels workflow

• Demo with multiple use cases

• Evaluating improving model performance.

• Customer Examples

• Wrap-up and Q&A

© 2020, , Inc. or its Affiliates. The AWS ML stack Broadest and deepest set of capabilities

AI Services

VISION SPEECH LANGUAGE CHATBOTS FORECASTING RECOMMENDATIONS

AMAZON AMAZON AMAZON AMAZON AMAZON AMAZON AMAZON AMAZON AMAZON AMAZON REKOGNITION REKOGNITION TEXTRACT POLLY TRANSCRIBE TRANSLATE COMPREHEND LEX FORECAST PERSONALIZE IMAGE VIDEO & COMPREHEND MEDICAL ML Services

Amazon SageMaker Ground Truth Notebooks Algorithms + Marketplace Training Optimization Deployment Hosting

ML Frameworks + Infrastructure

FRAMEWORKS INTERFACES INFRASTRUCTURE

E C 2 P 3 E C 2 G 4 FPGAS D L E L A S T I C E L A S T I C GREENGRASS ELASTIC INFERENTIA & P 3 D N E C 2 C 5 CONTAINERS CONTAINER KUBERNETES INFERENCE & A M I s SERVICE SERVICE

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Image and video analysis

Labels (Object, Scenes Face Search and Activities)

Unsafe Image and Face Detection Video Detection and Analysis

Text in Image Celebrity Recognition

Person Pathing Real-time video analysis

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Objects and Scenes (Labels)

Helmet 97.4% Outdoors 99.7% Objects Nature 99.7% Scenes

Bounding boxes for common objects Person 99.6% Confidence and hierarchy Snowboarding returned per label 99.6% (e.g., Snow  Nature)

Snow 99.6%

© 2020, Amazon Web Services, Inc. or its Affiliates. Most common customer request

Customization “Amazon Rekognition Labels is not specific enough for what I need for my business”

Amazon Rekognition Machine Part Machine Part Machine Part Labels

Customer Need Turbocharger Torque Converter Crankshaft © 2020, Amazon Web Services, Inc. or its Affiliates. Customization requires expertise and resources DIY

Deep Machine Tens of thousands of Several weeks Learning Expertise labeled images to months to (hard to find) (expensive and time complete consuming)

© 2020, Amazon Web Services, Inc. or its Affiliates. Customization requires expertise and resources Human Labeling

$

Scaling to peak Error-prone and needs can be subjective leading to expensive inconsistencies

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Custom Labels

© 2020, Amazon Web Services, Inc. or its Affiliates. What is Amazon Rekognition Custom Labels?

Customized Image Analysis to easily detect objects and scenes you define as most relevant to your domain

© 2020, Amazon Web Services, Inc. or its Affiliates. What is Amazon Rekognition Custom Labels?

Customized Image Analysis to easily detect objects and scenes you define as most relevant to your domain

Guided Experience Train and evaluate Easy-to-use fully to create labeled with no coding and managed API images no ML experience

© 2020, Amazon Web Services, Inc. or its Affiliates. Benefits

Less training data Customized to your From tens to hundreds of images, business need instead of tens of thousands

Custom image analysis in hours Customize and use model in No ML expertise required hours, instead of several weeks or months

Business users create ML models Intuitive UI. Zero lines of code. Fully managed by AWS

© 2020, Amazon Web Services, Inc. or its Affiliates. Problems You Can Solve With A Custom Labels Model

Single Label Classification Multi-Label Classification Object detection “Which class of objects does “Which combination of classes “What object is present, this picture represent” are represented in this image” and where is it?”

“Premade foods” Buster Arthur

“Produce” “Mountains, Dusk”

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 13 Problems You Can Solve With A Custom Labels Model

Single Label Classification Multi-Label Classification Object detection “Which class of objects does “Which combination of classes “What object is present, this picture represent” are represented in this image” and where is it?”

“Premade foods” Buster Arthur

“Produce” “Mountains, Dusk”

Required Resources (Time, Compute, Data)

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 14 How are Customers using it:-

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 15 Long tail of computer vision problems

DetectLabels recognizes common classes of objects and scenes. Other Amazon Rekognition APIs offer specialized capability for content moderation, faces, or text Custom Labels provides scalable API to custom models that recognizes specific objects and scenes, each potentially different Picture by Hay Kranen / PD, Wikipedia

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Custom Labels under the hood

Model generalization: Pre-trained models that transfer to new tasks

Model selection: Train a set of models, choose best performing model

Specific use case Train and Choose best Custom (objects, scenes) Optimize performing model model

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Custom Labels under the hood

© 2020, Amazon Web Services, Inc. or its Affiliates. Options for Creating a Dataset

• Label data by hand in the Amazon Rekognition Custom Label Console • Add images by dragging and dropping them into your dataset gallery view. • You’re limited to uploading 30 images at one time.

• Import images from bucket • Use images from an existing S3 bucket by entering the S3 folder location. • Automatically add labels based on your folder names.

• Import images labeled by Amazon SageMaker Ground Truth • Provide the location of your .manifest file. • Also supports other .manifest files not created in Ground Truth, as long as they are formatted properly.

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 19 Amazon Rekognition Custom Labels workflow

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Custom Labels console

© 2020, Amazon Web Services, Inc. or its Affiliates. Create project

© 2020, Amazon Web Services, Inc. or its Affiliates. Projects

© 2020, Amazon Web Services, Inc. or its Affiliates. Datasets

© 2020, Amazon Web Services, Inc. or its Affiliates. Create dataset

© 2020, Amazon Web Services, Inc. or its Affiliates. Labeling images

© 2020, Amazon Web Services, Inc. or its Affiliates. Train model

© 2020, Amazon Web Services, Inc. or its Affiliates. Demo

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Rekognition Custom Labels API reference

APIs Description

CreateProject Creates your project Create your Model CreateProjectVersion Trains your model

StartProjectVersion Starts your inference end point

Using your model DetectCustomLabels Calls your custom model

StopProjectVersion Stops your inference end point

DescribeProjects Describes your project Control Plane APIs DescribeProjectVersions Describes your model

© 2020, Amazon Web Services, Inc. or its Affiliates. API Reference

CreateProjectVersion (Train Custom Labels)

Where your output goes Specify your model

"OutputConfig": "ProjectArn": "string" { "S3Bucket": "string", "S3KeyPrefix": "string” }

Training Dataset Details Testing Dataset Details

"TrainingData": { "TestingData": { "Assets": [ "Assets": [ { { "GroundTruthManifest": { "GroundTruthManifest": { "S3Object": { "S3Object": { "Bucket": "string", "Bucket": "string", "Name": "string", "Name": "string", "Version": "string”}}}]} "Version": "string" }}}]}

© 2020, Amazon Web Services, Inc. or its Affiliates. API Reference – AWS CLI

• DetectCustomLabels aws rekognition detect-custom-labels --project-version-arn "model_arn"\ --image '{"S3Object":{"Bucket":"bucket","Name":"image"}}'\ --min-confidence 70

© 2020, Amazon Web Services, Inc. or its Affiliates. DetectCustomLabels API

{ "ProjectVersionArn": "string", "Image":{ "S3Object":{ "Bucket":"string", "Name":"string", { "Version":"string" "CustomLabels": [ } { }, "Name": "MyLogo", "MinConfidence": 90, "Confidence": 77.7729721069336, "MaxLabels": 10, "Geometry": { } "BoundingBox": { "Width": 0.198987677693367, "Height": 0.31296101212501526, "Left": 0.07924537360668182, DetectCustomLabels "Top": 0.4037395715713501 } } } ] }

© 2020, Amazon Web Services, Inc. or its Affiliates. Deploying the model

Start and stop the model endpoint

Assign inference units • Priced at inference unit per hour • Supports 5 transactions per second (TPS)

© 2020, Amazon Web Services, Inc. or its Affiliates. Use case 1: Exemplar-based detection

“We need to find the oral history interviews we have, which were shot with golden record awards in the background”

© 2020, Amazon Web Services, Inc. or its Affiliates. Use case 2: Classification

Damaged Infected Healthy cucumber leaves cucumber leaf cucumber leaf

© 2020, Amazon Web Services, Inc. or its Affiliates. Use case 3: Localization

“Find Arthur and his friends in every video and image”

Arthur Buster Buster

© 2020, Amazon Web Services, Inc. or its Affiliates. Building a high-performing model

• Train models with only bounding box or image-level labels for best performance • Increase train and test samples as variability of your object and images increases

• Ensure label quality is high • Use feedback as new training data to improve your model © 2020, Amazon Web Services, Inc. or its Affiliates. Understanding Model Metrics:-

Precision is the fraction of correct predictions (true positives) over all model predictions (true and false positives) at the assumed threshold for an individual label.

Recall is the fraction of your test set labels that were predicted correctly above the assumed threshold.

Model performance is an aggregate measure that takes into account both precision and recall over all labels (for example, F1 score or average precision)

The assumed threshold for each label is the value above which a prediction is counted as a true or false positive. It is set based on your test dataset.

Source - https://en.wikipedia.org/wiki/Precision_and_recall © 2020, Amazon Web Services, Inc. or its Affiliates. F1 Score, Precision, and Recall

It is important to note that Rekognition Custom Labels does not return “accuracy”

• It instead displays F1 score • F1 score is calculated as the average of precision and recall

• Models with high precision will report a low number of false positives • You want your home security system to be very precise; when in doubt assume ‘no’ • If it is unsure, it will chose not to apply any label

• Models with high recall will report a low number of false negatives • You want your COVID-19 test to have high recall; when in doubt assume ‘yes’ • If it is unsure, it will chose not to apply too many labels

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 39 Tips for improving your model:

Increase Accuracy Increase throughput Decrease Cost

• Balance your dataset better • Shrink the size of your images • Don’t reinvent the wheel (if Rekognition labels already • Increase resolution of training • Use classification model instead does something, use that images of detection model instead)

• Increase number of training • Consider using raw bytes instead • Consider batching images if you images of S3 cannot use one full inference unit • Try classification model versus detection model • Increase throughput of model to require less • Ensure bounding boxes are drawn inference units precisely

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 40 Custom Labels Use Cases Gaining Traction

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 41 Example Use cases for Rekognition Custom Labels:

• Smart Camera Tagging • Identify specific items of interest in a camera feed, like a vehicle or animal • Detect items or patterns (like downed power lines) from satellite imagery

• Document Classification • Particularly helpful in cases where images are visually rich and text light (think ID documents)

• Logo/Character Recognition In Media & Social Media • Identify logos or characters in media for easy searching and tagging

• Manufacturing Automation • Uses Rekognition Custom Labels to detect defects • Also utilize Amazon Rekognition DetectText to identify serial numbers

© 2020, Amazon© 2020, Web AmazonServices, WebInc. or Services, its Affiliates. Inc. or its affiliates. All rights reserved. 42 Benefits

Less training data Customized to your From tens to hundreds of images, business need instead of tens of thousands

Custom image analysis in hours Customize and use model in No ML expertise required hours, instead of several weeks or months

Business users create ML models Intuitive UI. Zero lines of code. Fully managed by AWS

© 2020, Amazon Web Services, Inc. or its Affiliates. Next steps

© 2020, Amazon Web Services, Inc. or its Affiliates. © 2020 Amazon Web Services, Inc. or its affiliates. All rights reserved | 44 Getting Started https://rekognition-immersionday.workshop.aws/custom_labels.html

To start and stop and test from webapp use below solution:- https://github.com/aws-samples/amazon-rekognition-custom-labels- demo

Create larger model datasets using model assistance:- https://github.com/aws-samples/amazon-rekognition-custom-labels- feedback-solution

Continuous model improvement workflow:- https://github.com/aws-samples/amazon-rekognition-custom-labels- a2i-automated-continuous-model-improvement

© 2020, Amazon Web Services, Inc. or its Affiliates. Q&A

© 2020, Amazon Web Services, Inc. or its Affiliates. Support for your POCs

Can contact: [email protected]

© 2020, Amazon Web Services, Inc. or its Affiliates. © 2020 Amazon Web Services, Inc. or its affiliates. All rights reserved | 47 Thank You

© 2020, Amazon Web Services, Inc. or its Affiliates.