

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 境界ボックスを使用してイメージオブジェクトを分類する
<a name="sms-bounding-box"></a>

通常、機械学習モデルのトレーニングに使用するイメージ内には複数のオブジェクトがあります。イメージ内の 1 つ以上のオブジェクトを分類およびローカライズするには、タスクタイプとして 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>

SageMaker AI コンソールで境界ボックスラベルリングジョブを作成する方法については、「[ラベル付けジョブの作成 (コンソール)](sms-create-labeling-job-console.md)」で手順を説明しています。ステップ 10 で、**[Task category]** (タスクカテゴリ) ドロップダウンメニューから **[Image]** (イメージ) を選択し、**[Boundary box]** (境界ボックス) タスクタイプを選択します。

Ground Truth には、ラベル付けタスク用の次のようなワーカー UI が用意されています。コンソールでラベル付けジョブを作成するときは、ワーカーがジョブを実行できる手順と、ワーカーが選択できるラベルを最大 50 個指定します。

![\[カテゴリのオブジェクトの周りにボックスを描画する画面の GIF。\]](http://docs.aws.amazon.com/ja_jp/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 にアップロードし、このファイルの S3 URI を `UiTemplateS3Uri` で指定します。

```
<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 バケット、またはコンソールの **[Job overview]** (ジョブの概要) セクションの **[Output dataset location]** (出力データセットの場所) フィールドに配置されます。

例えば、正常に完了した単一クラスの境界ボックスタスクの出力マニフェストファイルには、次のものが含まれます。

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

`boundingBoxes` パラメータは、「bird」として識別されたオブジェクトを囲むように描画した境界ボックスの位置を特定します。これは、イメージの左上隅のピクセル座標 (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)」を参照してください。