• 沒有找到結果。

Assign image-level labels to training and test datasets

在文檔中 Custom Labels Guide Rekognition (頁 45-200)

To add a new label (console)

1. On the dataset gallery page, choose Start labeling to enter labeling mode.

2. In the Labels section of the dataset gallery, choose Edit labels to open the Manage labels dialog box.

3. In the edit box, enter a new label name.

4. Choose Add label.

5. Repeat steps 3 and 4 until you have created all the labels you need.

6. Choose Save to save the labels that you added.

Step 6: Assign image-level labels to training and test datasets

In this step you assign a single image level to each image in your training and test datasets. The image-level label is the class that each image represents.

To assign image-level labels to an image (console)

1. On the Datasets page, choose the Training tab.

2. Choose Start labeling to enter labeling mode.

3. Select one or more images that you want to add labels to. You can only select images on a single page at a time. To select a contiguous range of images on a page:

a. Select the first image.

b. Press and hold the shift key.

c. Select the second image. The images between the first and second image are also selected.

d. Release the shift key.

4. Choose Assign image-level labels.

Step 7: Train your model

5. In Assign image-level labels to selected images dialog box, select a label that you want to assign to the image or images.

6. Choose Assign to assign label to the image.

7. Repeat labeling until every image is annotated with the required labels.

8. Choose the Test tab.

9. Repeat steps to assign image level labels to the test dataset images.

Step 7: Train your model

Use the following steps to train your model. For more information, see Training an Amazon Rekognition Custom Labels model (p. 89).

To train your model (console)

1. On the Dataset page, choose Train model.

2. On the Train model page, choose Train model. The Amazon Resource Name (ARN) for your project is in the Choose project edit box.

Step 7: Train your model

3. In the Do you want to train your model? dialog box, choose Train model.

4. In the Models section of the project page, you can see that training is in progress. You can check the current status by viewing the Model Status column for the model version. Training a model takes a while to complete.

Step 7: Train your model

5. After training completes, choose the model name. Training is finished when the model status is TRAINING_COMPLETED.

6. Choose the Evaluate button to see the evaluation results. For information about evaluating a model, see Improving a trained Amazon Rekognition Custom Labels model (p. 135).

7. Choose View test results to see the results for individual test images. For more information, see Metrics for evaluating your model (p. 135).

8. After viewing the test results, choose the project name to return to the model page.

Step 8: Start your model

Step 8: Start your model

In this step you start your model. After your model starts, you can use it to analyze images.

You are charged for the amount of time that your model runs. Stop your model if you don't need to analyze images. You can restart your model at a later time. For more information, see Running a trained Amazon Rekognition Custom Labels model (p. 147).

To start your model

1. Choose the Use model tab on the model page.

2. In the Start or stop model section do the following:

a. Choose Start.

b. In the Start model dialog box, choose Start.

Step 9: Analyze an image with your model

3. Wait until the model is running. The model is running when the status in the Start or stop model section is Running.

Step 9: Analyze an image with your model

You analyze an image by calling the DetectCustomLabels API. In this step, you use the detect-custom-labels AWS Command Line Interface (AWS CLI) command to analyze an example image. You get the AWS CLI command from the Amazon Rekognition Custom Labels console. The console configures the AWS CLI command to use your model. You only need to supply an image that's stored in an Amazon S3 bucket.

Note

The console also provides Python example code.

The output from detect-custom-labels includes a list of labels found in the image, bounding boxes (if the model finds object locations), and the confidence that the model has in the accuracy of the predictions.

For more information, see Analyzing an image with a trained model (p. 162).

To analyze an image (console)

1. If you haven't already, set up the AWS CLI. For instructions, see the section called “Step 3: Set Up the AWS CLI and AWS SDKs” (p. 5).

2. Choose the Use Model tab and then choose API code.

Step 9: Analyze an image with your model

3. Choose AWS CLI command.

4. In the Analyze image section, copy the AWS CLI command that calls detect-custom-labels.

Step 9: Analyze an image with your model

5. Upload an image to an Amazon S3 bucket. For instructions, see Uploading Objects into Amazon S3 in the Amazon Simple Storage Service User Guide. If you're using images from the Rooms project, use one of the images you moved to a separate folder in Step 1: Collect your images (p. 34).

6. At the command prompt, enter the AWS CLI command that you copied in the previous step. It should look like the following example.

The value of --project-version-arn should be Amazon Resource Name (ARN) of your model.

The value of --region should be the AWS Region in which you created the model.

Change MY_BUCKET and PATH_TO_MY_IMAGE to the Amazon S3 bucket and image that you used in the previous step.

aws rekognition detect-custom-labels \ --project-version-arn "model_arn" \

--image "{"S3Object": {"Bucket": "MY_BUCKET","Name": "PATH_TO_MY_IMAGE"}}" \ --region us-east-1

The JSON output from the AWS CLI command should look similar to the following. Name is the name of the image-level label that the model found. Confidence (0-100) is the model's confidence in the accuracy of the prediction.

Step 10: Stop your model

{ "CustomLabels": [ {

"Name": "living_space",

"Confidence": 83.41299819946289 }

] }

7. Continue to use the model to analyze other images. Stop the model if you are no longer using it.

Step 10: Stop your model

In this step you stop running your model. You are charged for the amount of time your model is running.

If you have finished using the model, you should stop it.

To stop your model

1. In the Start or stop model section choose Stop.

2. In the Stop model dialog box, enter stop to confirm that you want to stop the model.

Step 10: Stop your model

3. Choose Stop to stop your model. The model has stopped when the status in the Start or stop model section is Stopped.

Creating a project

Creating an Amazon Rekognition Custom Labels model

A model is the software that you train to find the concepts, scenes, and objects that are unique to your business. You can create a model with the Amazon Rekognition Custom Labels console or with the AWS SDK. Before creating an Amazon Rekognition Custom Labels model, we recommend that you read Understanding Amazon Rekognition Custom Labels (p. 27).

This section provides console and SDK information about creating a project, creating training and test datasets for different model types, and training a model. Later sections show you how to improve and use your model. For a tutorial that shows you how to create and use a specific type of model with the console, see Tutorial: Classifying images (p. 34).

Topics

• Creating a project (p. 50)

• Creating training and test datasets (p. 54)

• Training an Amazon Rekognition Custom Labels model (p. 89)

• Debugging a failed model training (p. 99)

Creating a project

A project manages the model versions, training dataset, and test dataset for a model. You can create a project with the Amazon Rekognition Custom Labels console or with the API.

If you no longer need a project, you can delete it with the Amazon Rekognition Custom Labels console or with the API. For more information, see Deleting an Amazon Rekognition Custom Labels model (p. 252).

Topics

• Creating an Amazon Rekognition Custom Labels Project (Console) (p. 50)

• Creating an Amazon Rekognition Custom Labels project (SDK) (p. 51)

Creating an Amazon Rekognition Custom Labels Project (Console)

You can use the Amazon Rekognition Custom Labels console to create a project. The first time you use the console in a new AWS Region, Amazon Rekognition Custom Labels asks to create an Amazon S3 bucket (console bucket) in your account. The bucket is used to store project files. You can't use the Amazon Rekognition Custom Labels console unless the console bucket is created.

You can use the Amazon Rekognition Custom Labels console to create a project.

To create a project (console)

1. Sign in to the AWS Management Console and open the Amazon Rekognition console at https://

console.aws.amazon.com/rekognition/.

2. In the left pane, choose Use Custom Labels. The Amazon Rekognition Custom Labels landing page is shown.

3. The Amazon Rekognition Custom Labels landing page, choose Get started.

Creating a project (SDK)

4. In the left pane, Choose Projects.

5. Choose Create Project.

6. In Project name, enter a name for your project.

7. Choose Create project to create your project.

8. Follow the steps in Creating training and test datasets (p. 54) to create the training and test datasets for your project.

Creating an Amazon Rekognition Custom Labels project (SDK)

You create an Amazon Rekognition Custom Labels project by calling CreateProject. The response is an Amazon Resource Name (ARN) that identifies the project. After you create a project, you create datasets for training and testing a model. For more information, see Creating training and test datasets (Console) (p. 59).

To create a project (SDK)

1. If you haven't already:

a. Create or update an IAM user with AmazonRekognitionFullAccess permissions. For more information, see Step 2: Create an IAM administrator user and group (p. 4).

b. Install and configure the AWS CLI and the AWS SDKs. For more information, see Step 3: Set Up the AWS CLI and AWS SDKs (p. 5).

2. Use the following code to create a project.

AWS CLI

The following example creates a project and displays its ARN.

Change the value of project-name to the name of the project that you want to create.

aws rekognition create-project --project-name my_project Python

The following example creates a project and displays its ARN. Supply the following command line arguments:

• project_name – the name of the project you want to create.

#Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

#PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-custom-labels-developer-guide/blob/master/LICENSE-SAMPLECODE.)

import boto3 import argparse import logging

from botocore.exceptions import ClientError logger = logging.getLogger(__name__)

def create_project(rek_client, project_name):

"""

Creates an Amazon Rekognition Custom Labels project

:param rek_client: The Amazon Rekognition Custom Labels Boto3 client.

Creating a project (SDK)

:param project_name: A name for the new prooject.

"""

try:

#Create the project

logger.info(f"Creating project: {project_name}")

response=rek_client.create_project(ProjectName=project_name)

logger.info(f"project ARN: {response['ProjectArn']}") return response['ProjectArn']

except ClientError as err:

logger.exception(f"Couldn't create project - {project_name}:

{err.response['Error']['Message']}") raise

def add_arguments(parser):

"""

Adds command line arguments to the parser.

:param parser: The command line parser.

"""

parser.add_argument(

"project_name", help="A name for the new project."

)

def main():

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") try:

#get command line arguments

parser = argparse.ArgumentParser(usage=argparse.SUPPRESS) add_arguments(parser)

args = parser.parse_args()

print(f"Creating project: {args.project_name}") #Create the project

rek_client=boto3.client('rekognition') project_arn=create_project(rek_client, args.project_name)

print(f"Finished creating project: {args.project_name}") print(f"ARN: {project_arn}")

except ClientError as err:

logger.exception(f"Problem creating project: {err}") print(f"Problem creating project: {err}")

if __name__ == "__main__":

main()

Java V2

The following example creates a project and displays its ARN.

Creating a project (SDK)

Supply the following command line argument:

• project_name – the name of the project you want to create.

//Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

//PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/

amazon-rekognition-custom-labels-developer-guide/blob/master/LICENSE-SAMPLECODE.) import software.amazon.awssdk.services.rekognition.RekognitionClient;

import software.amazon.awssdk.services.rekognition.model.CreateProjectRequest;

import software.amazon.awssdk.services.rekognition.model.CreateProjectResponse;

import software.amazon.awssdk.services.rekognition.model.RekognitionException;

import java.net.URI;

import java.util.logging.Level;

import java.util.logging.Logger;

public class CreateProject {

public static final Logger logger =

Logger.getLogger(CreateProject.class.getName());

public static String createMyProject(RekognitionClient rekClient, String projectName) {

try {

logger.log(Level.INFO, "Creating project: {0}", projectName);

CreateProjectRequest createProjectRequest =

CreateProjectRequest.builder().projectName(projectName).build();

CreateProjectResponse response = rekClient.createProject(createProjectRequest);

logger.log(Level.INFO, "Project ARN: {0} ", response.projectArn());

return response.projectArn();

} catch (RekognitionException e) {

logger.log(Level.SEVERE, "Could not create project: {0}", e.getMessage());

throw e;

} }

public static void main(String args[]) {

final String USAGE = "\n" + "Usage: " + "<project_name> <bucket> <image>\n

\n" + "Where:\n"

+ " project_name - A name for the new project\n\n";

if (args.length != 1) { System.out.println(USAGE);

System.exit(1);

}

String projectName = args[0];

String projectArn = null;

; try {

Creating datasets

// Get the Rekognition client

RekognitionClient rekClient = RekognitionClient.builder().build();

// Create the project

projectArn = createMyProject(rekClient, projectName);

System.out.println(String.format("Created project: %s %nProject ARN:

%s", projectName, projectArn));

rekClient.close();

} catch (RekognitionException rekError) {

logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage());

System.exit(1);

} } }

3. Note the name of the project ARN that's displayed in the response. You'll need it to create a model.

4. Follow the steps in Create training and test datasets (SDK) (p. 65) to create the training and test datasets for your project.

Creating training and test datasets

A dataset is a set of images and labels that describe those images. Your project needs a training dataset and a test dataset. Amazon Rekognition Custom Labels uses the training dataset to train your model.

After training, Amazon Rekognition Custom Labels uses the test dataset to verify how well the trained model predicts the correct labels.

You can create datasets with the Amazon Rekognition Custom Labels console or with the AWS SDK.

Before creating a dataset, we recommend reading Understanding Amazon Rekognition Custom Labels (p. 27).

The steps creating training and tests datasets for a project are:

To create training and test datasets for your project

1. Determine how you need to label your training and test datasets. For more information, Purposing datasets (p. 55).

2. Collect the images for your training and test datasets. For more information, see the section called

“Preparing images” (p. 58).

3. Create the training and test datasets. For more information, see Creating training and test datasets (Console) (p. 59). If you're using the AWS SDK, see Create training and test datasets (SDK)

(p. 65).

4. If necesessary, add image-level labels or bounding boxes to your dataset images. For more information, see Labeling images (p. 82).

Topics

• Purposing datasets (p. 55)

• Preparing images (p. 58)

• Creating training and test datasets (Console) (p. 59)

Purposing datasets

• Create training and test datasets (SDK) (p. 65)

• Debugging datasets (p. 77)

• Labeling images (p. 82)

Purposing datasets

How you label the training and test datasets in your project determines the type of model that you create. With Amazon Rekognition Custom Labels you can create models that do the following.

• Find objects, scenes, and concepts (p. 55)

• Find object locations (p. 56)

• Find brand locations (p. 56)

Find objects, scenes, and concepts

The model classifies the objects, scenes, and concepts that are associated with an entire image.

You can create two types of classification model, image classification and multi-label classification. For both types of classification model, the model finds one or more matching labels from the complete set of labels used for training. The training and test datasets both require at least two labels.

Image classification

The model classifies images as belonging to a set of predefined labels. For example, you might want a model that determines if an image contains a living space. The following image might have a living_space image-level label.

For this type of model, add a single image-level label to each of the training and test dataset images. For an example project, see Image classification (p. 12).

Multi-label classification

The model classifies images into multiple categories, such as the type of flower and whether it has leaves, or not. For example, the following image might have mediterranean_spurge and no_leaves image level labels.

Purposing datasets

For this type of model assign image-level labels for each category to the training and test dataset images. For an example project, see Multi-label image classification (p. 12).

Assigning image-level labels

If your images are stored in an Amazon S3 bucket, you can use folder names (p. 59) to automatically add image-level labels. For more information, see Amazon S3 bucket (p. 59). You can also add image-level labels to images after you create a dataset, For more information, see the section called

“Assigning image-level labels to an image” (p. 85). You can add new labels as you need them. For more information, see Managing labels (p. 83).

Find object locations

To create a model that predicts the location of objects in your images, you define object location

bounding boxes and labels for the images in your training and test datasets. A bounding box is a box that tightly surrounds an object. For example, the following image shows bounding boxes around an Amazon Echo and an Amazon Echo Dot. Each bounding box has an assigned label (Amazon Echo or Amazon Echo Dot).

To find object locations, your datasets needs at least one label. During model training, a further label is automatically created that represents the area outside of the bounding boxes on an image.

Assigning bounding boxes

When you create your dataset, you can include bounding box information for your images. For example, you can import a SageMaker Ground Truth format manifest file (p. 226) that contains bounding boxes.

You can also add bounding boxes after you create a dataset. For more information, see Locating objects with bounding boxes (p. 87). You can add new labels as you need them. For more information, see Managing labels (p. 83).

Find brand locations

If you want to find the location of brands, such as logos and animated characters, you can use two different types of images for your training dataset images.

Purposing datasets

• Images that are of the logo only. Each image needs a single image-level label that represents the logo name. For example, the image-level label for the following image could be Lambda.

• Images that contain the logo in natural locations, such as a football game or an architectual diagram.

Each training image needs bounding boxes that surround each instance of the logo. For example, the following image shows an architectural diagram with labeled bounding boxes surrounding the AWS Lambda and Amazon Pinpoint logos.

We recommend that you don't mix image-level labels and bounding boxes in your training images.

The test images must have bounding boxes around instances of the brand that you want to find. You can split the training dataset to create the test dataset, only if the training images include labeled bounding boxes. If the training images only have image-level labels, you must create a test dataset set that includes images with labeled bounding boxes. If you train a model to find brand locations, do Locating objects with bounding boxes (p. 87) and Assigning image-level labels to an image (p. 85) according to how you label your images.

The Brand detection (p. 12) example project shows how Amazon Rekognition Custom Labels uses labeled bounding boxes to train a model that finds object locations.

Label requirements for model types

Use the following table to determine how to label your images.

Preparing images

You can combine image-level labels and bounding box labeled images in a single dataset. In this case, Amazon Rekognition Custom Labels chooses whether to create an image-level model or an object location model.

Example Training images Test images

Image classification (p. 55) 1 Image-level label per image 1 Image-level label per image Multi-label classification

(p. 55) Multiple image-level labels per

image Multiple image-level labels per

image Find brand locations (p. 56) image level-labels (you can also

use Labeled bounding boxes) Labeled bounding boxes Find object locations (p. 56) Labeled bounding boxes Labeled bounding boxes

Preparing images

The images in your training and test dataset contain the objects, scenes, or concepts that you want your model to find.

The content of images should be in a variety of backgrounds and lighting that represent the images that

The content of images should be in a variety of backgrounds and lighting that represent the images that

在文檔中 Custom Labels Guide Rekognition (頁 45-200)

相關文件