

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

# 创建映像分类作业（多标签）
<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)。