

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

# 標籤影像
<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 SageMaker Ground Truth 邊界框標籤工作任務類型。在此情況下，區域化表示邊界框的像素位置。您可以使用 Amazon SageMaker AI 主控台的 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 提供與以下類似的工作者使用者介面以進行標籤任務。使用主控台建立標籤工作時，您可以指定指示以協助工作者完成工作，以及最多 50 個可供工作者選擇的標籤。

![\[Gif 顯示如何在類別的物件周圍繪製方塊。\]](http://docs.aws.amazon.com/zh_tw/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此操作。若要查看這項作業支援的特定語言 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-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 SageMaker Ground Truth 語意分割標籤任務。指派語意分割標籤工作時，工作者會將影像中的像素分類為一組預先定義的標籤或類別。Ground Truth 支援單一類別和多類別語意分割標籤工作。您可以使用 Amazon SageMaker AI 主控台的 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 提供類似下列標籤任務的工作者使用者介面。使用主控台建立標籤工作時，您可以指定指示以協助工作者完成工作，以及工作者可以選擇的標籤。

![\[顯示如何在 SageMaker AI 主控台建立語意分割標籤工作的 GIF。\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/semantic_segmentation_sample.gif)


## 建立語意分割標籤工作 (API)
<a name="sms-creating-ss-labeling-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-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>

當工作者獲派提供自動分割工具的標籤工作時，就會獲得有關如何使用此工具的詳細說明。例如，工作者可能會在工作者主控台中看到下列內容：

![\[UI 範例，說明如何在工作者主控台中使用工具。\]](http://docs.aws.amazon.com/zh_tw/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` 篩選條件的情況。如需 `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 SageMaker Ground Truth 影像分類標籤任務。系統會向工作者顯示影像，並要求工作者為各個影像逐一選擇標籤。您可以使用 Amazon SageMaker AI 主控台的 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 提供類似下列標籤任務的工作者使用者介面。使用主控台建立標籤工作時，您可以指定指示以協助工作者完成工作，以及工作者可以選擇的標籤。

![\[Ground Truth 提供用於標籤任務的工作者 UI 範例。\]](http://docs.aws.amazon.com/zh_tw/sagemaker/latest/dg/images/image-classification-example.png)


## 建立影像分類標籤工作 (API)
<a name="sms-creating-image-classification-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-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 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)。

# 影像標籤驗證
<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_tw/sagemaker/latest/dg/images/label-verification-example.png)


您可以使用 SageMaker AI 主控台或 API 來建立標籤驗證標籤工作。若要了解如何使用 Ground Truth API 作業 `CreateLabelingJob` 來建立標籤工作，請參閱[建立標籤工作 (API)](sms-create-labeling-job-api.md)。