

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 标注图像
<a name="sms-label-images"></a>

使用 Ground Truth 标注图像。选择以下内置任务类型之一以了解有关该任务类型的更多信息。每个页面都包含一些说明，有助于您使用该任务类型创建标注作业。

**提示**  
要进一步了解支持的文件类型和输入数据限额，请参阅[输入数据](sms-data-input.md)。

**Topics**
+ [使用边界框对映像对象进行分类](sms-bounding-box.md)
+ [利用语义分割识别映像内容](sms-semantic-segmentation.md)
+ [自动分割工具](sms-auto-segmentation.md)
+ [创建映像分类作业（单一标签）](sms-image-classification.md)
+ [创建映像分类作业（多标签）](sms-image-classification-multilabel.md)
+ [图像标签验证](sms-label-verification.md)

# 使用边界框对映像对象进行分类
<a name="sms-bounding-box"></a>

用于训练机器学习模型的图像通常包含多个对象。要对图像中的一个或多个对象进行分类和本地化，请使用 Amazon G SageMaker round Truth 边界框贴标任务类型。在这种情况下，本地化意味着边界框的像素位置。您可以使用 Amazon A SageMaker I 控制台的 Ground Truth 部分或[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)操作来创建定界箱贴标任务。

**重要**  
对于此任务类型，如果您创建自己的清单文件，请使用 `"source-ref"` 识别 Amazon S3 中您要标注的每个图像文件的位置。有关更多信息，请参阅 [输入数据](sms-data-input.md)。

## 创建边界框标注作业（控制台）
<a name="sms-creating-bounding-box-labeling-job-console"></a>

您可以按照说明学习[创建标注作业（控制台）](sms-create-labeling-job-console.md)如何在 SageMaker AI 控制台中创建边界框标签作业。在步骤 10 中，从**任务类别**下拉菜单中选择**图像**，然后选择**边界框**作为任务类型。

Ground Truth 为标注任务提供类似于以下内容的工作人员 UI。使用控制台创建标注作业时，需要指定有助于工作人员完成作业的说明，以及工作人员最多可以选择的 50 个标签。

![\[Gif 显示了如何在对象周围为类别画一个框。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/sms/gifs/bb-sample.gif)


## 创建边界框标注作业 (API)
<a name="sms-creating-bounding-box-labeling-job-api"></a>

要创建边界框标签作业，请使用 SageMaker API 操作`CreateLabelingJob`。此 API 为所有人定义了此操作 AWS SDKs。要查看此操作 SDKs 支持的特定语言列表，请查看的 “**另请参阅**” 部分。[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)

请按照[创建标注作业 (API)](sms-create-labeling-job-api.md)中的说明进行操作，并在配置请求时执行以下操作：
+ 此任务类型的注释前 Lambda 函数以 `PRE-BoundingBox` 结尾。要查找您所在地区的预注释 Lambda ARN，请参阅。[PreHumanTaskLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_HumanTaskConfig.html#SageMaker-Type-HumanTaskConfig-PreHumanTaskLambdaArn)
+ 此任务类型的注释合并 Lambda 函数以 `ACS-BoundingBox` 结尾。要查找您所在地区的注释合并 Lambda ARN，请参阅。[AnnotationConsolidationLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_AnnotationConsolidationConfig.html#SageMaker-Type-AnnotationConsolidationConfig-AnnotationConsolidationLambdaArn)

以下是一个 [AWS Python SDK (Boto3) 请求](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_labeling_job)示例，该请求在美国东部（弗吉尼亚州北部）区域中创建标注作业。所有红色参数都应替换为您的规范和资源。

```
response = client.create_labeling_job(
    LabelingJobName='example-bounding-box-labeling-job,
    LabelAttributeName='label',
    InputConfig={
        'DataSource': {
            'S3DataSource': {
                'ManifestS3Uri': 's3://bucket/path/manifest-with-input-data.json'
            }
        },
        'DataAttributes': {
            'ContentClassifiers': [
                'FreeOfPersonallyIdentifiableInformation'|'FreeOfAdultContent',
            ]
        }
    },
    OutputConfig={
        'S3OutputPath': 's3://bucket/path/file-to-store-output-data',
        'KmsKeyId': 'string'
    },
    RoleArn='arn:aws:iam::*:role/*,
    LabelCategoryConfigS3Uri='s3://bucket/path/label-categories.json',
    StoppingConditions={
        'MaxHumanLabeledObjectCount': 123,
        'MaxPercentageOfInputDatasetLabeled': 123
    },
    HumanTaskConfig={
        'WorkteamArn': 'arn:aws:sagemaker:region:*:workteam/private-crowd/*',
        'UiConfig': {
            'UiTemplateS3Uri': 's3://bucket/path/worker-task-template.html'
        },
        'PreHumanTaskLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:PRE-BoundingBox',
        'TaskKeywords': [
            'Bounding Box',
        ],
        'TaskTitle': 'Bounding Box task',
        'TaskDescription': 'Draw bounding boxes around objects in an image',
        'NumberOfHumanWorkersPerDataObject': 123,
        'TaskTimeLimitInSeconds': 123,
        'TaskAvailabilityLifetimeInSeconds': 123,
        'MaxConcurrentTaskCount': 123,
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:ACS-BoundingBox'
          }
        },
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ]
)
```

### 为边界框标注作业提供模板
<a name="sms-create-labeling-job-bounding-box-api-template"></a>

如果要使用 API 创建标注作业，必须在 `UiTemplateS3Uri` 中提供工作人员任务模板。复制并修改以下模板。仅修改 [https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions)、[https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions) 和 `header`。将此模板上传到 S3，并在 `UiTemplateS3Uri` 中为此文件提供 S3 URI。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-bounding-box
    name="boundingBox"
    src="{{ task.input.taskObject | grant_read_access }}"
    header="please draw box"
    labels="{{ task.input.labels | to_json | escape }}"
  >

    <full-instructions header="Bounding box instructions">
      <ol><li><strong>Inspect</strong> the image</li><li><strong>Determine</strong> 
      if the specified label is/are visible in the picture.</li>
      <li><strong>Outline</strong> each instance of the specified label in the image using the provided “Box” tool.</li></ol>
      <ul><li>Boxes should fit tight around each object</li>
      <li>Do not include parts of the object are overlapping or that cannot be seen, even though you think you can interpolate the whole shape.</li>
      <li>Avoid including shadows.</li>
      <li>If the target is off screen, draw the box up to the edge of the image.</li>    
    </full-instructions>
  
    <short-instructions>
      <h3><span style="color: rgb(0, 138, 0);">Good example</span></h3>
      <p>Enter description of a correct bounding box label and add images</p>
      <h3><span style="color: rgb(230, 0, 0);">Bad example</span></h3>
      <p>Enter description of an incorrect bounding box label and add images</p>
    </short-instructions>
  
  </crowd-bounding-box>
</crowd-form>
```

## 边界框输出数据
<a name="sms-bounding-box-output-data"></a>

创建边界框标注作业后，输出数据将位于使用 API 时在 `S3OutputPath` 参数中指定的 Amazon S3 存储桶中，或控制台的**作业概览**部分的**输出数据集位置**字段中。

例如，成功完成的单类边界框任务的输出清单文件将包含以下内容：

```
[
  {
    "boundingBox": {
      "boundingBoxes": [
        {
          "height": 2832,
          "label": "bird",
          "left": 681,
          "top": 599,
          "width": 1364
        }
      ],
      "inputImageProperties": {
        "height": 3726,
        "width": 2662
      }
    }
  }
]
```

`boundingBoxes` 参数标识围绕标识为“鸟”的对象绘制的边界框相对于图像左上角的位置，该位置被认为是 (0,0) 像素坐标。在上一个示例中，**`left`** 和 **`top`** 确定边界框左上角的像素相对于图像左上角的位置。边界框的尺寸使用 **`height`** 和 **`width`** 进行标识。`inputImageProperties` 参数给出原始输入图像的像素尺寸。

当您使用边界框任务类型时，您可以创建单类和多类边界框标注作业。成功完成的多类边界框的输出清单文件将包含以下内容：

```
[
  {
    "boundingBox": {
      "boundingBoxes": [
        {
          "height": 938,
          "label": "squirrel",
          "left": 316,
          "top": 218,
          "width": 785
        },
        {
          "height": 825,
          "label": "rabbit",
          "left": 1930,
          "top": 2265,
          "width": 540
        },
        {
          "height": 1174,
          "label": "bird",
          "left": 748,
          "top": 2113,
          "width": 927
        },
        {
          "height": 893,
          "label": "bird",
          "left": 1333,
          "top": 847,
          "width": 736
        }
      ],
      "inputImageProperties": {
        "height": 3726,
        "width": 2662
      }
    }
  }
]
```

要了解有关边界框标注作业产生的输出清单文件的更多信息，请参阅[边界框作业输出](sms-data-output.md#sms-output-box)。

要了解有关 Ground Truth 生成的输出清单文件以及 Ground Truth 用来存储输出数据的文件结构的更多信息，请参阅[标注作业输出数据](sms-data-output.md)。

# 利用语义分割识别映像内容
<a name="sms-semantic-segmentation"></a>

要在像素级别识别图像内容，请使用 Amazon G SageMaker round Truth 语义分割标签任务。在分配语义分割标注作业时，工作人员会将图像中的像素分类为一组预定义的标签或类。Ground Truth 支持单类和多类语义分割标注作业。您可以使用 Amazon A SageMaker I 控制台的 Ground Truth 部分或[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)操作创建语义分段标签作业。

包含大量需要分割的对象的图像需要更多时间。为有助于工作人员（来自私有人力或供应商人力）在更短的时间更准确地标注这些对象，Ground Truth 提供了一个 AI 辅助自动分割工具。有关信息，请参阅[自动分割工具](sms-auto-segmentation.md)。

**重要**  
对于此任务类型，如果您创建自己的清单文件，请使用 `"source-ref"` 识别 Amazon S3 中您要标注的每个图像文件的位置。有关更多信息，请参阅 [输入数据](sms-data-input.md)。

## 创建语义分割标注作业（控制台）
<a name="sms-creating-ss-labeling-job-console"></a>

您可以按照说明学习[创建标注作业（控制台）](sms-create-labeling-job-console.md)如何在 SageMaker AI 控制台中创建语义分段标注作业。在步骤 10 中，从**任务类别**下拉菜单中选择**图像**，然后选择**语义分割**作为任务类型。

Ground Truth 为标注任务提供类似于以下内容的工作人员 UI。使用控制台创建标注作业时，需要指定说明，以便于工作人员完成工作人员可以从中选择的作业和标签。

![\[Gif 显示了如何在 SageMaker AI 控制台中创建语义分段标签作业的示例。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/semantic_segmentation_sample.gif)


## 创建语义分割标注作业 (API)
<a name="sms-creating-ss-labeling-job-api"></a>

要创建语义分割标注作业，请使用 SageMaker API 操作`CreateLabelingJob`。此 API 为所有人定义了此操作 AWS SDKs。要查看此操作 SDKs 支持的特定语言列表，请查看的 “**另请参阅**” 部分。[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)

请按照[创建标注作业 (API)](sms-create-labeling-job-api.md)中的说明进行操作，并在配置请求时执行以下操作：
+ 此任务类型的注释前 Lambda 函数以 `PRE-SemanticSegmentation` 结尾。要查找您所在地区的预注释 Lambda ARN，请参阅。[PreHumanTaskLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_HumanTaskConfig.html#SageMaker-Type-HumanTaskConfig-PreHumanTaskLambdaArn)
+ 此任务类型的注释合并 Lambda 函数以 `ACS-SemanticSegmentation` 结尾。要查找您所在地区的注释合并 Lambda ARN，请参阅。[AnnotationConsolidationLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_AnnotationConsolidationConfig.html#SageMaker-Type-AnnotationConsolidationConfig-AnnotationConsolidationLambdaArn)

以下是一个 [AWS Python SDK (Boto3) 请求](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_labeling_job)示例，该请求在美国东部（弗吉尼亚州北部）区域中创建标注作业。所有红色参数都应替换为您的规范和资源。

```
response = client.create_labeling_job(
    LabelingJobName='example-semantic-segmentation-labeling-job,
    LabelAttributeName='label',
    InputConfig={
        'DataSource': {
            'S3DataSource': {
                'ManifestS3Uri': 's3://bucket/path/manifest-with-input-data.json'
            }
        },
        'DataAttributes': {
            'ContentClassifiers': [
                'FreeOfPersonallyIdentifiableInformation'|'FreeOfAdultContent',
            ]
        }
    },
    OutputConfig={
        'S3OutputPath': 's3://bucket/path/file-to-store-output-data',
        'KmsKeyId': 'string'
    },
    RoleArn='arn:aws:iam::*:role/*,
    LabelCategoryConfigS3Uri='s3://bucket/path/label-categories.json',
    StoppingConditions={
        'MaxHumanLabeledObjectCount': 123,
        'MaxPercentageOfInputDatasetLabeled': 123
    },
    HumanTaskConfig={
        'WorkteamArn': 'arn:aws:sagemaker:region:*:workteam/private-crowd/*',
        'UiConfig': {
            'UiTemplateS3Uri': 's3://bucket/path/worker-task-template.html'
        },
        'PreHumanTaskLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:PRE-SemanticSegmentation,
        'TaskKeywords': [
            'Semantic Segmentation',
        ],
        'TaskTitle': 'Semantic segmentation task',
        'TaskDescription': 'For each category provided, segment out each relevant object using the color associated with that category',
        'NumberOfHumanWorkersPerDataObject': 123,
        'TaskTimeLimitInSeconds': 123,
        'TaskAvailabilityLifetimeInSeconds': 123,
        'MaxConcurrentTaskCount': 123,
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:ACS-SemanticSegmentation'
        },
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ]
)
```

### 为语义分割标注作业提供模板
<a name="sms-create-labeling-job-ss-api-template"></a>

如果要使用 API 创建标注作业，必须在 `UiTemplateS3Uri` 中提供工作人员任务模板。复制并修改以下模板。仅修改 [https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions)、[https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions) 和 `header`。

将此模板上传到 S3，并在 `UiTemplateS3Uri` 中为此文件提供 S3 URI。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-semantic-segmentation
    name="crowd-semantic-segmentation"
    src="{{ task.input.taskObject | grant_read_access }}"
    header="Please segment out all pedestrians."
    labels="{{ task.input.labels | to_json | escape }}"
  >
    <full-instructions header="Segmentation instructions">
      <ol><li><strong>Read</strong> the task carefully and inspect the image.</li>
      <li><strong>Read</strong> the options and review the examples provided to understand more about the labels.</li>
      <li><strong>Choose</strong> the appropriate label that best suits an object and paint that object using the tools provided.</li></ol>
    </full-instructions>
    <short-instructions>
      <h2><span style="color: rgb(0, 138, 0);">Good example</span></h2>
      <p>Enter description to explain a correctly done segmentation</p>
      <p><br></p><h2><span style="color: rgb(230, 0, 0);">Bad example</span></h2>
      <p>Enter description of an incorrectly done segmentation</p>
    </short-instructions>
  </crowd-semantic-segmentation>
</crowd-form>
```

## 语义分割输出数据
<a name="sms-ss-ouput-data"></a>

创建语义分割标注作业后，输出数据将位于使用 API 时在 `S3OutputPath` 参数中指定的 Amazon S3 存储桶中，或控制台的**作业概览**部分的**输出数据集位置**字段中。

要了解有关 Ground Truth 生成的输出清单文件以及 Ground Truth 用来存储输出数据的文件结构的更多信息，请参阅[标注作业输出数据](sms-data-output.md)。

要查看语义分割标注作业的输出清单文件示例，请参阅[3D 点云语义分割输出](sms-data-output.md#sms-output-point-cloud-segmentation)。

# 自动分割工具
<a name="sms-auto-segmentation"></a>

图像分割是将图像分成多个片段或一组标注像素的过程。在 Amazon SageMaker Ground Truth 中，识别给定标签下所有像素的过程包含在这些像素上应用彩色填充内容或“遮罩”。某些标注作业任务包含带有需要分割的大量对象的图像。为有助于工作人员在更短的时间更准确地标注这些对象，Ground Truth 提供了一个自动分割工具，专门用于分配给私有人力和供应商人力的分割任务。此工具使用机器学习模型以最少的工作人员输入对图像中的各个对象进行自动分割。工作人员可以使用工作人员控制台中的其他工具优化由自动分割工具生成的遮罩。这有助于工作人员更快、更准确地完成图像分割任务，从而降低成本并提高标注质量。下一页将介绍此工具及其可用性。

**注意**  
自动分割工具适用于发送给私有人力或供应商人力的分割任务。该工具不适用于发送给公有人力 (Amazon Mechanical Turk) 的任务。

## 工具预览
<a name="sms-auto-segment-tool-preview"></a>

当为工作人员分配提供自动分割工具的标注作业时，将向他们提供有关如何使用该工具的详细说明。例如，工作人员可能会在工作人员控制台中看到以下内容：

![\[用户界面示例，其中说明如何在工作器管理控制台中使用此工具。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/sms/gifs/semantic-segmentation.gif)


工作人员可以使用**查看完整说明**了解如何使用该工具。工作人员需要在相关对象的四个极点（最上面、最下面、最左侧和最右侧）上放置一个点，该工具将自动为对象生成遮罩。工作人员可以通过使用提供的其他工具或通过在缺少的对象的较小部分上使用自动分割工具，进一步优化遮罩。

## 工具可用性
<a name="sms-auto-segment-tool-availability"></a>

如果使用 Amazon SageMaker AI 控制台创建语义分割标注作业，自动分割工具将自动显示在工作人员的控制台中。在 SageMaker AI 控制台中创建语义分割作业时，您可以在创建工作人员说明时预览该工具。要了解如何在 SageMaker AI 控制台中创建语义分割标注作业，请参阅[入门：使用 Ground Truth 创建边界框标注作业](sms-getting-started.md)。

如果要在 SageMaker AI 控制台中创建自定义实例分割标注作业，或者使用 Ground Truth API 创建实例或语义分割标注作业，您需要创建一个自定义任务模板，以便设计工作人员控制台和说明。要在工作人员控制台中包含自动分割工具，请确保自定义任务模板中满足以下条件：
+ 对于使用 API 创建的语义分割标注作业，`<crowd-semantic-segmentation>` 位于任务模板中。对于自定义实例分割标注作业，`<crowd-instance-segmentation>` 标记位于任务模板中。
+ 任务分配给私有人力或供应商人力。
+ 要标注的图像是已针对工作人员进行预签名以便访问的 Amazon Simple Storage Service Amazon S3) 对象。如果任务模板包含 `grant_read_access` 筛选器，则为 true。有关 `grant_read_access` 筛选器的信息，请参阅[使用 Liquid 添加自动化](sms-custom-templates-step2-automate.md)。

以下是自定义实例分割标注作业的自定义任务模板示例，其中包括 `<crowd-instance-segmentation/>` 标签和 `grant_read_access` Liquid 筛选器。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-instance-segmentation
    name="crowd-instance-segmentation"
    src="{{ task.input.taskObject | grant_read_access }}"
    labels="['Car','Road']"
   <full-instructions header="Segmentation instructions">
      Segment each instance of each class of objects in the image. 
    </full-instructions>

    <short-instructions>
      <p>Segment each instance of each class of objects in the image.</p>

      <h3 style="color: green">GOOD EXAMPLES</h3>
      <img src="path/to/image.jpg" style="width: 100%">
      <p>Good because A, B, C.</p>

      <h3 style="color: red">BAD EXAMPLES</h3>
      <img src="path/to/image.jpg" style="width: 100%">
      <p>Bad because X, Y, Z.</p>
    </short-instructions>
  </crowd-instance-segmentation>
</crowd-form>
```

# 创建映像分类作业（单一标签）
<a name="sms-image-classification"></a>

如果您需要工作人员使用您指定的预定义标签对图像进行分类，请使用 Amazon G SageMaker round Truth 图像分类标注任务。将向工作人员显示图像，并要求工作人员为每个图像选择一个标签。您可以使用 Amazon A SageMaker I 控制台的 Ground Truth 部分或[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)操作创建图像分类标签任务。

**重要**  
对于此任务类型，如果您创建自己的清单文件，请使用 `"source-ref"` 识别 Amazon S3 中您要标注的每个图像文件的位置。有关更多信息，请参阅 [输入数据](sms-data-input.md)。

## 创建图像分类标注作业（控制台）
<a name="sms-creating-image-classification-console"></a>

您可以按照说明学习[创建标注作业（控制台）](sms-create-labeling-job-console.md)如何在 SageMaker AI 控制台中创建图像分类标注作业。在第 10 步中，从**任务类别**下拉菜单中选择**图像**，并选择**图像分类（单标签）**作为任务类型。

Ground Truth 为标注任务提供类似于以下内容的工作人员 UI。使用控制台创建标注作业时，需要指定说明，以便于工作人员完成工作人员可以从中选择的作业和标签。

![\[由 Ground Truth 提供的用于标记任务的工作人员用户界面示例。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/image-classification-example.png)


## 创建图像分类标注作业 (API)
<a name="sms-creating-image-classification-api"></a>

要创建图像分类标注任务，请使用 SageMaker API 操作`CreateLabelingJob`。此 API 为所有人定义了此操作 AWS SDKs。要查看此操作 SDKs 支持的特定语言列表，请查看的 “**另请参阅**” 部分。[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)

请按照[创建标注作业 (API)](sms-create-labeling-job-api.md)中的说明进行操作，并在配置请求时执行以下操作：
+ 此任务类型的注释前 Lambda 函数以 `PRE-ImageMultiClass` 结尾。要查找您所在地区的预注释 Lambda ARN，请参阅。[PreHumanTaskLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_HumanTaskConfig.html#SageMaker-Type-HumanTaskConfig-PreHumanTaskLambdaArn)
+ 此任务类型的注释合并 Lambda 函数以 `ACS-ImageMultiClass` 结尾。要查找您所在地区的注释合并 Lambda ARN，请参阅。[AnnotationConsolidationLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_AnnotationConsolidationConfig.html#SageMaker-Type-AnnotationConsolidationConfig-AnnotationConsolidationLambdaArn)

以下是一个 [AWS Python SDK (Boto3) 请求](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_labeling_job)示例，该请求在美国东部（弗吉尼亚州北部）区域中创建标注作业。所有红色参数都应替换为您的规范和资源。

```
response = client.create_labeling_job(
    LabelingJobName='example-image-classification-labeling-job',
    LabelAttributeName='label',
    InputConfig={
        'DataSource': {
            'S3DataSource': {
                'ManifestS3Uri': 's3://bucket/path/manifest-with-input-data.json'
            }
        },
        'DataAttributes': {
            'ContentClassifiers': [
                'FreeOfPersonallyIdentifiableInformation'|'FreeOfAdultContent',
            ]
        }
    },
    OutputConfig={
        'S3OutputPath': 's3://bucket/path/file-to-store-output-data',
        'KmsKeyId': 'string'
    },
    RoleArn='arn:aws:iam::*:role/*,
    LabelCategoryConfigS3Uri='s3://bucket/path/label-categories.json',
    StoppingConditions={
        'MaxHumanLabeledObjectCount': 123,
        'MaxPercentageOfInputDatasetLabeled': 123
    },
    HumanTaskConfig={
        'WorkteamArn': 'arn:aws:sagemaker:region:*:workteam/private-crowd/*',
        'UiConfig': {
            'UiTemplateS3Uri': 's3://bucket/path/worker-task-template.html'
        },
        'PreHumanTaskLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:PRE-ImageMultiClass,
        'TaskKeywords': [
            Image classification',
        ],
        'TaskTitle': Image classification task',
        'TaskDescription': 'Carefully inspect the image and classify it by selecting one label from the categories provided.',
        'NumberOfHumanWorkersPerDataObject': 123,
        'TaskTimeLimitInSeconds': 123,
        'TaskAvailabilityLifetimeInSeconds': 123,
        'MaxConcurrentTaskCount': 123,
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:ACS-ImageMultiClass'
        },
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ]
)
```

### 为图像分类标注作业提供模板
<a name="worker-template-image-classification"></a>

如果要使用 API 创建标注作业，必须在 `UiTemplateS3Uri` 中提供工作人员任务模板。复制并修改以下模板。仅修改 [https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions)、[https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions) 和 `header`。

将此模板上传到 S3，并在 `UiTemplateS3Uri` 中为此文件提供 S3 URI。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-image-classifier
    name="crowd-image-classifier"
    src="{{ task.input.taskObject | grant_read_access }}"
    header="please classify"
    categories="{{ task.input.labels | to_json | escape }}"
  >
    <full-instructions header="Image classification instructions">
      <ol><li><strong>Read</strong> the task carefully and inspect the image.</li>
      <li><strong>Read</strong> the options and review the examples provided to understand more about the labels.</li>
      <li><strong>Choose</strong> the appropriate label that best suits the image.</li></ol>
    </full-instructions>
    <short-instructions>
      <h3><span style="color: rgb(0, 138, 0);">Good example</span></h3>
      <p>Enter description to explain the correct label to the workers</p>
      <h3><span style="color: rgb(230, 0, 0);">Bad example</span></h3><p>Enter description of an incorrect label</p>
    </short-instructions>
  </crowd-image-classifier>
</crowd-form>
```

## 图像分类输出数据
<a name="sms-image-classification-output-data"></a>

创建图像分类标注作业后，输出数据将位于使用 API 时在 `S3OutputPath` 参数中指定的 Amazon S3 存储桶中，或者位于控制台的**作业概览**部分的**输出数据集位置**字段中。

要了解有关 Ground Truth 生成的输出清单文件以及 Ground Truth 用来存储输出数据的文件结构的更多信息，请参阅[标注作业输出数据](sms-data-output.md)。

要查看来自图像分类标注作业的输出清单文件示例，请参阅[分类作业输出](sms-data-output.md#sms-output-class)。

# 创建映像分类作业（多标签）
<a name="sms-image-classification-multilabel"></a>

当您需要工作人员对图像中的多个对象进行分类时，可以使用 Amazon G SageMaker round Truth 多标签图像分类标注任务。例如，下图显示了一只狗和一只猫。您可以使用多标签图像分类将标签“dog”和“cat”与此图像相关联。下一页提供了有关创建映像分类作业的信息。

![\[照片由 Anusha Barwa 在 Unsplash 上发布\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/dog-cat-photo.jpg)


在处理多标签图像分类任务时，工作人员应选择所有适用的标签，且必须选择至少一个标签。使用此任务类型创建作业时，您最多可提供 50 个标签类别。

在控制台中创建标注作业时，Ground Truth 不会针对未向图像应用标签的情况提供“无”类别。要向工作人员提供此选项，请在创建多标签图像分类作业时，包含类似于“无”或“其他”的标签。

要限制工作人员为每个图像选择单个标签，请使用 [创建映像分类作业（单一标签）](sms-image-classification.md) 任务类型。

**重要**  
对于此任务类型，如果您创建自己的清单文件，请使用 `"source-ref"` 识别 Amazon S3 中您要标注的每个图像文件的位置。有关更多信息，请参阅 [输入数据](sms-data-input.md)。

## 创建多标签图像分类标注作业（控制台）
<a name="sms-creating-multilabel-image-classification-console"></a>

您可以按照说明学习[创建标注作业（控制台）](sms-create-labeling-job-console.md)如何在 SageMaker AI 控制台中创建多标签图像分类标注作业。在第 10 步中，从**任务类别**下拉菜单中选择**图像**，并选择**图像分类（多标签）**作为任务类型。

Ground Truth 为标注任务提供类似于以下内容的工作人员 UI。在控制台中创建标注作业时，需要指定说明，以便于工作人员完成工作人员可以从中选择的作业和标签。

![\[由 Ground Truth 提供的用于标记任务的工作人员用户界面示例。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/image-classification-multilabel-example.png)


## 创建多标签图像分类标注作业 (API)
<a name="sms-create-multi-select-image-classification-job-api"></a>

要创建多标签图像分类标注作业，请使用 SageMaker API 操作`CreateLabelingJob`。此 API 为所有人定义了此操作 AWS SDKs。要查看此操作 SDKs 支持的特定语言列表，请查看的 “**另请参阅**” 部分。[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)

请按照[创建标注作业 (API)](sms-create-labeling-job-api.md)中的说明进行操作，并在配置请求时执行以下操作：
+ 此任务类型的注释前 Lambda 函数以 `PRE-ImageMultiClassMultiLabel` 结尾。要查找您所在地区的预注释 Lambda ARN，请参阅。[PreHumanTaskLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_HumanTaskConfig.html#SageMaker-Type-HumanTaskConfig-PreHumanTaskLambdaArn)
+ 此任务类型的注释合并 Lambda 函数以 `ACS-ImageMultiClassMultiLabel` 结尾。要查找您所在地区的注释合并 Lambda ARN，请参阅。[AnnotationConsolidationLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_AnnotationConsolidationConfig.html#SageMaker-Type-AnnotationConsolidationConfig-AnnotationConsolidationLambdaArn)

以下是一个 [AWS Python SDK (Boto3) 请求](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_labeling_job)示例，该请求在美国东部（弗吉尼亚州北部）区域中创建标注作业。所有红色参数都应替换为您的规范和资源。

```
response = client.create_labeling_job(
    LabelingJobName='example-multi-label-image-classification-labeling-job,
    LabelAttributeName='label',
    InputConfig={
        'DataSource': {
            'S3DataSource': {
                'ManifestS3Uri': 's3://bucket/path/manifest-with-input-data.json'
            }
        },
        'DataAttributes': {
            'ContentClassifiers': [
                'FreeOfPersonallyIdentifiableInformation'|'FreeOfAdultContent',
            ]
        }
    },
    OutputConfig={
        'S3OutputPath': 's3://bucket/path/file-to-store-output-data',
        'KmsKeyId': 'string'
    },
    RoleArn='arn:aws:iam::*:role/*,
    LabelCategoryConfigS3Uri='s3://bucket/path/label-categories.json',
    StoppingConditions={
        'MaxHumanLabeledObjectCount': 123,
        'MaxPercentageOfInputDatasetLabeled': 123
    },
    HumanTaskConfig={
        'WorkteamArn': 'arn:aws:sagemaker:region:*:workteam/private-crowd/*',
        'UiConfig': {
            'UiTemplateS3Uri': 's3://bucket/path/worker-task-template.html'
        },
        'PreHumanTaskLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:PRE-ImageMultiClassMultiLabel',
        'TaskKeywords': [
            'Image Classification',
        ],
        'TaskTitle': 'Multi-label image classification task',
        'TaskDescription': 'Select all labels that apply to the images shown',
        'NumberOfHumanWorkersPerDataObject': 123,
        'TaskTimeLimitInSeconds': 123,
        'TaskAvailabilityLifetimeInSeconds': 123,
        'MaxConcurrentTaskCount': 123,
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:ACS-ImageMultiClassMultiLabel'
        },
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ]
)
```

### 为多标签图像分类提供模板
<a name="sms-custom-template-multi-image-label-classification"></a>

如果要使用 API 创建标注作业，必须在 `UiTemplateS3Uri` 中提供工作人员任务模板。复制并修改以下模板。仅修改 [https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions)、[https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions) 和 `header`。

将此模板上传到 S3，并在 `UiTemplateS3Uri` 中为此文件提供 S3 URI。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-image-classifier-multi-select
    name="crowd-image-classifier-multi-select"
    src="{{ task.input.taskObject | grant_read_access }}"
    header="Please identify all classes in image"
    categories="{{ task.input.labels | to_json | escape }}"
  >
    <full-instructions header="Multi Label Image classification instructions">
      <ol><li><strong>Read</strong> the task carefully and inspect the image.</li>
      <li><strong>Read</strong> the options and review the examples provided to understand more about the labels.</li>
       <li><strong>Choose</strong> the appropriate labels that best suit the image.</li></ol>
    </full-instructions>
    <short-instructions>
      <h3><span style="color: rgb(0, 138, 0);">Good example</span></h3>
      <p>Enter description to explain the correct label to the workers</p>
      <h3><span style="color: rgb(230, 0, 0);">Bad example</span></h3>
      <p>Enter description of an incorrect label</p>
   </short-instructions>
  </crowd-image-classifier-multi-select>
</crowd-form>
```

## 多标签图像分类输出数据
<a name="sms-image-classification-multi-output-data"></a>

创建多标签图像分类标注作业后，输出数据将位于使用 API 时在 `S3OutputPath` 参数中指定的 Amazon S3 存储桶中，或者位于控制台的**作业概览**部分的**输出数据集位置**字段中。

要了解有关 Ground Truth 生成的输出清单文件以及 Ground Truth 用来存储输出数据的文件结构的更多信息，请参阅[标注作业输出数据](sms-data-output.md)。

要查看多标签图像分类标注作业的输出清单文件示例，请参阅[多标签分类作业输出](sms-data-output.md#sms-output-multi-label-classification)。

# 图像标签验证
<a name="sms-label-verification"></a>

为机器学习 (ML) 算法构建高度精确的训练数据集是一个迭代过程。通常情况下，您应当查看并持续调整标签，直到您满意它们准确表示基本实际情况或可在现实世界中直接观察到的内容为止。您可以使用 Amazon SageMaker Ground Truth 图像标签验证任务来指示工作人员查看数据集标签并提高标签准确性。工作人员可以指示现有标签是否正确或评估标签质量。他们还可以添加注释来解释他们的推理。Amazon SageMaker Ground Truth 支持[使用边界框对映像对象进行分类](sms-bounding-box.md)和[利用语义分割识别映像内容](sms-semantic-segmentation.md)标签的标签验证。您可以使用 Amazon SageMaker AI 控制台的 Ground Truth 部分或 [CreateLabelingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html) 操作创建图像标签验证标注作业。

Ground Truth 为标注任务提供类似于以下内容的工作人员控制台。使用控制台创建标注作业时，可以修改显示的图像和内容。要了解如何使用 Ground Truth 控制台创建标注作业，请参阅[创建标注作业（控制台）](sms-create-labeling-job-console.md)。

![\[由 Ground Truth 提供的用于标记任务的工作人员管理控制台示例。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/label-verification-example.png)


您可以使用 SageMaker AI 控制台或 API 创建标签验证标注作业。要了解如何使用 Ground Truth API 操作 `CreateLabelingJob` 创建标注作业，请参阅[创建标注作业 (API)](sms-create-labeling-job-api.md)。