

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立影像分類標籤工作 (多標籤)
<a name="sms-image-classification-multilabel"></a>

當您需要工作者來分類影像中的多個物件時，請使用 Amazon SageMaker Ground Truth 多標籤影像分類標籤任務。例如，下列影像含有狗和貓。您可以使用多標籤影像分類，將 “狗” 和 “貓” 標籤與此影像建立關聯。以下頁面說明建立影像分類任務的相關資訊。

![\[Unsplash 上由 Anusha Barwa 拍攝的照片\]](http://docs.aws.amazon.com/zh_tw/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 提供類似下列標籤任務的工作者使用者介面。在主控台中建立標籤工作時，您可以指定協助工作者完成工作的指示，以及工作者可以選擇的標籤。

![\[Ground Truth 提供用於標籤工作的工作者 UI 範例。\]](http://docs.aws.amazon.com/zh_tw/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此操作。若要查看這項作業支援的特定語言 SDK 清單，請參閱 [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)。