

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# COCO 데이터세트를 매니페스트 파일 형식으로 변환
<a name="md-transform-coco"></a>

[COCO](http://cocodataset.org/#home)는 대규모 객체 감지, 세분화, 캡션 데이터 세트를 지정하는 데 사용되는 형식입니다. 이 Python [예제](md-coco-transform-example.md)는 COCO 객체 감지 형식 데이터 세트를 Amazon Rekognition Custom Labels [경계 상자 형식 매니페스트 파일](md-create-manifest-file-object-detection.md)로 변환하는 방법을 보여줍니다. 이 항목에는 직접 코드를 작성하는 데 사용할 수 있는 정보도 포함되어 있습니다.

COCO 형식 JSON 파일은 전체 데이터 세트**에 대한 정보를 제공하는 5개 항목으로 구성되어 있습니다. 자세한 내용은 [COCO 데이터세트 형식](md-coco-overview.md) 단원을 참조하십시오.
+ `info`: 데이터 세트에 대한 일반 정보 
+ `licenses `: 데이터 세트의 이미지에 대한 라이선스 정보
+ [`images`](md-coco-overview.md#md-coco-images): 데이터 세트의 이미지 목록
+ [`annotations`](md-coco-overview.md#md-coco-annotations): 데이터 세트의 모든 이미지에 있는 주석 목록(테두리 상자 포함)
+ [`categories`](md-coco-overview.md#md-coco-categories): 레이블 카테고리 목록

Amazon Rekognition Custom Labels 매니페스트 파일을 생성하려면 `images`, `annotations` 및 `categories` 목록의 정보가 필요합니다.

Amazon Rekognition Custom Labels 매니페스트 파일은 JSON 라인 형식이며, 각 줄에는 이미지에 있는** 하나 이상의 객체에 대한 경계 상자와 레이블 정보가 있습니다. 자세한 내용은 [매니페스트 파일의 객체 위치 파악](md-create-manifest-file-object-detection.md) 단원을 참조하십시오.

## COCO 객체를 사용자 지정 레이블 JSON 라인에 매핑
<a name="md-mapping-coco"></a>

COCO 형식 데이터 세트를 변환하려면 객체 위치 파악을 위해 COCO 데이터 세트를 Amazon Rekognition Custom Labels 매니페스트 파일에 매핑하세요. 자세한 내용은 [매니페스트 파일의 객체 위치 파악](md-create-manifest-file-object-detection.md) 단원을 참조하십시오. 각 이미지에 대한 JSON 라인을 구축하려면 매니페스트 파일에 COCO 데이터 세트 `image`, `annotation`, `category` 객체 필드 ID를 매핑해야 합니다.

다음은 COCO 매니페스트 파일의 예제입니다. 자세한 내용은 [COCO 데이터세트 형식](md-coco-overview.md) 단원을 참조하십시오.

```
{
    "info": {
        "description": "COCO 2017 Dataset","url": "http://cocodataset.org","version": "1.0","year": 2017,"contributor": "COCO Consortium","date_created": "2017/09/01"
    },
    "licenses": [
        {"url": "http://creativecommons.org/licenses/by/2.0/","id": 4,"name": "Attribution License"}
    ],
    "images": [
        {"id": 242287, "license": 4, "coco_url": "http://images.cocodataset.org/val2017/xxxxxxxxxxxx.jpg", "flickr_url": "http://farm3.staticflickr.com/2626/xxxxxxxxxxxx.jpg", "width": 426, "height": 640, "file_name": "xxxxxxxxx.jpg", "date_captured": "2013-11-15 02:41:42"},
        {"id": 245915, "license": 4, "coco_url": "http://images.cocodataset.org/val2017/nnnnnnnnnnnn.jpg", "flickr_url": "http://farm1.staticflickr.com/88/xxxxxxxxxxxx.jpg", "width": 640, "height": 480, "file_name": "nnnnnnnnnn.jpg", "date_captured": "2013-11-18 02:53:27"}
    ],
    "annotations": [
        {"id": 125686, "category_id": 0, "iscrowd": 0, "segmentation": [[164.81, 417.51,......167.55, 410.64]], "image_id": 242287, "area": 42061.80340000001, "bbox": [19.23, 383.18, 314.5, 244.46]},
        {"id": 1409619, "category_id": 0, "iscrowd": 0, "segmentation": [[376.81, 238.8,........382.74, 241.17]], "image_id": 245915, "area": 3556.2197000000015, "bbox": [399, 251, 155, 101]},
        {"id": 1410165, "category_id": 1, "iscrowd": 0, "segmentation": [[486.34, 239.01,..........495.95, 244.39]], "image_id": 245915, "area": 1775.8932499999994, "bbox": [86, 65, 220, 334]}
    ],
    "categories": [
        {"supercategory": "speaker","id": 0,"name": "echo"},
        {"supercategory": "speaker","id": 1,"name": "echo dot"}
    ]
}
```

다음 다이어그램은 데이터 세트**의 COCO 데이터세트 목록이 Amazon Rekognition Custom Labels JSON 라인에 매핑되는 이미지**를 보여줍니다. 이미지의 모든 JSON 라인에는 소스 참조, 작업, 작업 메타데이터 필드가 있습니다. 일치하는 색상은 단일 이미지에 대한 정보를 나타냅니다. 매니페스트에서 각 이미지에 여러 주석과 메타데이터/범주가 있을 수 있습니다.

![\[이미지, 주석, 범주가 포함된 Coco 매니페스트의 구조를 보여주는 다이어그램입니다.\]](http://docs.aws.amazon.com/ko_kr/rekognition/latest/customlabels-dg/images/coco-transform.png)


**단일 JSON 라인에 대한 COCO 객체를 가져오려면**

1. 이미지 목록의 각 이미지에 대해 주석 필드 `image_id`의 값이 이미지 `id` 필드와 일치하는 주석 목록에서 주석을 가져옵니다.

1. 1단계에서 일치하는 각 주석에 대해 `categories` 목록을 읽고 `category` 필드 `id` 값이 `annotation` 객체 `category_id` 필드와 일치하는 `category`를 각각 가져옵니다.

1. 일치하는 `image`, `annotation`, `category` 객체를 사용하여 이미지의 JSON 라인을 생성합니다. 필드를 매핑하려면 [COCO 객체 필드를 사용자 지정 레이블 JSON 라인 객체 필드에 매핑하기](#md-mapping-fields-coco) 항목을 참조하세요.

1. `images` 목록의 각 `image` 객체에 대해 JSON 라인을 생성할 때까지 1\$13단계를 반복합니다.

예제 코드는 [COCO 데이터 세트 변환](md-coco-transform-example.md) 항목을 참조하세요.

## COCO 객체 필드를 사용자 지정 레이블 JSON 라인 객체 필드에 매핑하기
<a name="md-mapping-fields-coco"></a>

Amazon Rekognition Custom Labels JSON 라인의 COCO 객체를 식별한 후에는 COCO 객체 필드를 상응하는 Amazon Rekognition Custom Labels JSON 라인 객체 필드에 매핑해야 합니다. 다음 예제 Amazon Rekognition Custom Labels JSON 라인은 하나의 이미지(`id`=`000000245915`)를 위의 COCO JSON 예제에 매핑합니다. 다음 정보를 참고하세요.
+ `source-ref`는 Amazon S3 버킷의 이미지 위치입니다. Amazon S3 버킷에 COCO 이미지가 저장되지 않은 경우, 이미지를 Amazon S3 버킷으로 이동해야 합니다.
+ `annotations` 목록에는 이미지의 각 객체에 대해 `annotation` 객체가 포함되어 있습니다. `annotation` 객체에는 경계 상자 정보(`top`, `left`, `width`, `height`) 및 레이블 식별자(`class_id`)가 포함됩니다.
+ 레이블 식별자(`class_id`)는 메타데이터의 `class-map` 목록에 매핑됩니다. 그것은 이미지에 사용된 레이블을 나열합니다.

```
{
	"source-ref": "s3://custom-labels-bucket/images/000000245915.jpg",
	"bounding-box": {
		"image_size": {
			"width": 640,
			"height": 480,
			"depth": 3
		},
		"annotations": [{
			"class_id": 0,
			"top": 251,
			"left": 399,
			"width": 155,
			"height": 101
		}, {
			"class_id": 1,
			"top": 65,
			"left": 86,
			"width": 220,
			"height": 334
		}]
	},
	"bounding-box-metadata": {
		"objects": [{
			"confidence": 1
		}, {
			"confidence": 1
		}],
		"class-map": {
			"0": "Echo",
			"1": "Echo Dot"
		},
		"type": "groundtruth/object-detection",
		"human-annotated": "yes",
		"creation-date": "2018-10-18T22:18:13.527256",
		"job-name": "my job"
	}
}
```

다음 정보를 사용하여 Amazon Rekognition Custom Labels 매니페스트 파일 필드를 COCO 데이터 세트 JSON 필드에 매핑할 수 있습니다.

### source-ref
<a name="md-source-ref-coco"></a>

이미지 위치의 S3 형식 URL입니다. 이미지는 S3 버킷에 저장되어야 합니다. 자세한 내용은 [source-ref](md-create-manifest-file-object-detection.md#cd-manifest-source-ref) 단원을 참조하십시오. `coco_url` COCO 필드가 S3 버킷 위치를 가리키는 경우 `coco_url`의 값을 `source-ref`의 값으로 사용할 수 있습니다. 또는 `file_name`(COCO) 필드에 `source-ref`를 매핑하고, 변환 코드에서 이미지가 저장되는 위치에 필요한 S3 경로를 추가할 수 있습니다.

### *bounding-box*
<a name="md-label-attribute-id-coco"></a>

사용자가 선택한 레이블 속성 이름 자세한 내용은 [*bounding-box*](md-create-manifest-file-object-detection.md#md-manifest-source-bounding-box) 단원을 참조하십시오.

#### image\$1size
<a name="md-image-size-coco"></a>

이미지 크기(픽셀 단위) [이미지](md-coco-overview.md#md-coco-images) 목록의 `image` 객체에 매핑됩니다.
+ `height`-> `image.height`
+ `width`-> `image.width`
+ `depth`-> Amazon Rekognition Custom Labels에는 사용되지 않지만 값을 입력해야 합니다.

#### 주석
<a name="md-annotations-coco"></a>

`annotation` 객체의 목록. 이미지의 각 객체마다 `annotation`이 하나씩 있습니다.

#### annotation
<a name="md-annotation-coco"></a>

이미지에 있는 객체의 한 인스턴스에 대한 경계 상자 정보가 들어 있습니다.
+ `class_id` -> 사용자 지정 레이블의 `class-map` 목록에 매핑되는 숫자 ID
+ `top` -> `bbox[1]`
+ `left` -> `bbox[0]`
+ `width` -> `bbox[2]`
+ `height` -> `bbox[3]`

### *bounding-box*-metadata
<a name="md-metadata-coco"></a>

레이블 속성의 메타데이터 레이블 및 레이블 식별자를 포함합니다. 자세한 내용은 [*bounding-box*-metadata](md-create-manifest-file-object-detection.md#md-manifest-source-bounding-box-metadata) 단원을 참조하십시오.

#### Objects
<a name="cd-metadata-objects-coco"></a>

이미지에 있는 객체의 배열입니다. 인덱스를 기준으로 `annotations` 목록에 매핑됩니다.

##### 객체
<a name="cd-metadata-object-coco"></a>
+ `confidence`->Amazon Rekognition Custom Labels에는 사용되지 않지만 값(1)이 필요합니다.

#### class-map
<a name="md-metadata-class-map-coco"></a>

이미지에서 감지된 객체에 적용되는 레이블(클래스)의 맵입니다. [카테고리](md-coco-overview.md#md-coco-categories) 목록에 있는 카테고리 개체에 매핑됩니다.
+ `id` -> `category.id`
+ `id value` -> `category.name`

#### type
<a name="md-type-coco"></a>

`groundtruth/object-detection`이어야 합니다.

#### human-annotated
<a name="md-human-annotated-coco"></a>

`yes` 또는 `no`을 지정합니다. 자세한 내용은 [*bounding-box*-metadata](md-create-manifest-file-object-detection.md#md-manifest-source-bounding-box-metadata) 단원을 참조하십시오.

#### creation-date -> [image](md-coco-overview.md#md-coco-images).date\$1captured
<a name="md-creation-date-coco"></a>

이미지가 생성된 날짜 및 시간입니다. COCO 이미지 목록에 있는 이미지의 [image](md-coco-overview.md#md-coco-images).date\$1captured 필드에 매핑됩니다. Amazon Rekognition Custom Labels의 `creation-date`의 형식은 Y-M-DTH:MS:S**일 것으로 예상합니다.

#### job-name
<a name="md-job-name-coco"></a>

사용자가 선택한 직무 이름 

# COCO 데이터세트 형식
<a name="md-coco-overview"></a>

COCO 데이터 세트는 전체 데이터 세트에 대한 정보를 제공하는 다섯 개의 항목으로 구성됩니다. COCO 객체 감지 데이터 세트의 형식은 [COCO 데이터 형식](http://cocodataset.org/#format-data)에 문서화되어 있습니다.
+ 정보: 데이터 세트에 대한 일반 정보입니다.
+ 라이선스: 데이터 세트의 이미지에 대한 라이선스 정보입니다.
+ [이미지](#md-coco-images): 데이터 세트에 있는 이미지 목록
+ [주석](#md-coco-annotations): 데이터 세트의 모든 이미지에 있는 주석(경계 상자 포함)의 목록
+ [카테고리](#md-coco-categories): 레이블 카테고리 목록

사용자 지정 레이블 매니페스트를 만들려면 COCO 매니페스트 파일의 `images`, `annotations`, `categories` 목록을 사용하세요. 다른 항목(`info`, `licences`)은 필수가 아닙니다. 다음은 COCO 매니페스트 파일의 예제입니다.

```
{
    "info": {
        "description": "COCO 2017 Dataset","url": "http://cocodataset.org","version": "1.0","year": 2017,"contributor": "COCO Consortium","date_created": "2017/09/01"
    },
    "licenses": [
        {"url": "http://creativecommons.org/licenses/by/2.0/","id": 4,"name": "Attribution License"}
    ],
    "images": [
        {"id": 242287, "license": 4, "coco_url": "http://images.cocodataset.org/val2017/xxxxxxxxxxxx.jpg", "flickr_url": "http://farm3.staticflickr.com/2626/xxxxxxxxxxxx.jpg", "width": 426, "height": 640, "file_name": "xxxxxxxxx.jpg", "date_captured": "2013-11-15 02:41:42"},
        {"id": 245915, "license": 4, "coco_url": "http://images.cocodataset.org/val2017/nnnnnnnnnnnn.jpg", "flickr_url": "http://farm1.staticflickr.com/88/xxxxxxxxxxxx.jpg", "width": 640, "height": 480, "file_name": "nnnnnnnnnn.jpg", "date_captured": "2013-11-18 02:53:27"}
    ],
    "annotations": [
        {"id": 125686, "category_id": 0, "iscrowd": 0, "segmentation": [[164.81, 417.51,......167.55, 410.64]], "image_id": 242287, "area": 42061.80340000001, "bbox": [19.23, 383.18, 314.5, 244.46]},
        {"id": 1409619, "category_id": 0, "iscrowd": 0, "segmentation": [[376.81, 238.8,........382.74, 241.17]], "image_id": 245915, "area": 3556.2197000000015, "bbox": [399, 251, 155, 101]},
        {"id": 1410165, "category_id": 1, "iscrowd": 0, "segmentation": [[486.34, 239.01,..........495.95, 244.39]], "image_id": 245915, "area": 1775.8932499999994, "bbox": [86, 65, 220, 334]}
    ],
    "categories": [
        {"supercategory": "speaker","id": 0,"name": "echo"},
        {"supercategory": "speaker","id": 1,"name": "echo dot"}
    ]
}
```

## 이미지 목록
<a name="md-coco-images"></a>

COCO 데이터 세트에서 참조하는 이미지는 이미지 배열에 나열됩니다. 각 이미지 객체에는 이미지 파일 이름과 같은 이미지에 대한 정보가 들어 있습니다. 다음 예제 이미지 객체에서 다음 정보와 Amazon Rekognition Custom Labels 매니페스트 파일을 생성하는 데 필요한 필드를 기록해 둡니다.
+ `id`: (필수) 이미지의 고유 식별자 `id` 필드는 주석 배열(경계 상자 정보가 저장되는 위치)의 `id` 필드에 매핑됩니다.
+ `license`: (필수 아님) 라이선스 어레이에 매핑됩니다.
+ `coco_url`: (선택 사항) 이미지의 위치
+ `flickr_url`: (필수 아님) Flickr에서의 이미지 위치
+ `width`: (필수) 이미지의 너비
+ `height`: (필수) 이미지의 높이
+ `file_name`: (필수) 이미지 파일 이름 이 예제에서 `file_name`과 `id`는 일치하지만 COCO 데이터 세트의 요구 사항은 아닙니다.
+ `date_captured`: (필수) 이미지를 캡처한 날짜 및 시간 

```
{
    "id": 245915,
    "license": 4,
    "coco_url": "http://images.cocodataset.org/val2017/nnnnnnnnnnnn.jpg",
    "flickr_url": "http://farm1.staticflickr.com/88/nnnnnnnnnnnnnnnnnnn.jpg",
    "width": 640,
    "height": 480,
    "file_name": "000000245915.jpg",
    "date_captured": "2013-11-18 02:53:27"
}
```

## 주석(경계 상자) 목록
<a name="md-coco-annotations"></a>

모든 이미지에 있는 모든 객체의 경계 상자 정보는 주석 목록에 저장됩니다. 단일 주석 개체에는 단일 개체에 대한 경계 상자 정보와 이미지의 개체 레이블이 포함됩니다. 이미지에 있는 객체의 각 인스턴스에는 주석 개체가 있습니다.

다음 예제에서 다음 정보와 Amazon Rekognition Custom Labels 매니페스트 파일을 생성하는 데 필요한 필드를 기록해 둡니다.
+ `id`: (필수 아님) 주석의 식별자
+ `image_id`: (필수) 이미지 배열의 `id` 이미지에 대응합니다.
+ `category_id`: (필수) 경계 상자 내의 객체를 식별하는 레이블의 식별자입니다. 카테고리 배열의 `id` 필드에 매핑됩니다.
+ `iscrowd`: (필수 아님) 이미지에 많은 객체가 포함되어 있는지 여부를 지정합니다.
+ `segmentation`: (필수 아님) 이미지 상의 객체에 대한 세그멘트화 정보입니다. Amazon Rekognition Custom Labels는 세그멘트화를 지원하지 않습니다.
+ `area`: (필수 아님) 주석의 영역
+ `bbox`: (필수) 이미지에 있는 객체 주위의 경계 상자 좌표(픽셀 단위)를 포함합니다.

```
{
    "id": 1409619,
    "category_id": 1,
    "iscrowd": 0,
    "segmentation": [
        [86.0, 238.8,..........382.74, 241.17]
    ],
    "image_id": 245915,
    "area": 3556.2197000000015,
    "bbox": [86, 65, 220, 334]
}
```

## 카테고리 목록
<a name="md-coco-categories"></a>

레이블 정보는 카테고리 배열에 저장됩니다. 다음 예제 카테고리 객체에서 다음 정보와 Amazon Rekognition Custom Labels 매니페스트 파일을 생성하는 데 필요한 필드를 기록해 둡니다.
+ `supercategory`: (필수 아님) 레이블의 상위 카테고리 
+ `id`: (필수) 레이블 식별자 `id` 필드는 `annotation` 객체의 `category_id` 필드에 매핑됩니다. 다음 예제에서 에코 도트의 식별자는 2입니다.
+ `name`: (필수) 레이블 이름 

```
        {"supercategory": "speaker","id": 2,"name": "echo dot"}
```

# COCO 데이터 세트 변환
<a name="md-coco-transform-example"></a>

다음 Python 예제를 사용하여 COCO 형식 데이터 세트의 경계 상자 정보를 Amazon Rekognition Custom Labels 매니페스트 파일로 변환합니다. 해당 코드는 생성된 매니페스트 파일을 Amazon S3 버킷에 업로드합니다. 해당 코드는 이미지를 업로드하는 데 사용할 수 있는 AWS CLI 명령도 제공합니다.

**COCO 데이터 세트를 변환하려면(SDK)**

1. 아직 설정하지 않았다면 다음과 같이 하세요.

   1. `AmazonS3FullAccess` 권한이 있는지 확인합니다. 자세한 내용은 [SDK 권한 설정](su-sdk-permissions.md) 단원을 참조하십시오.

   1.  AWS CLI 및 AWS SDKs를 설치하고 구성합니다. 자세한 내용은 [4단계: AWS CLI 및 AWS SDKs 설정](su-awscli-sdk.md) 단원을 참조하십시오.

1. 다음 Python 코드를 사용하여 COCO 데이터 세트를 변환합니다. 다음 값을 설정하세요.
   + `s3_bucket`: 이미지 및 Amazon Rekognition Custom Labels 매니페스트 파일을 저장할 S3 버킷의 이름입니다.
   + `s3_key_path_images`: S3 버킷(`s3_bucket`) 내에서 이미지를 배치하려는 위치의 경로
   + `s3_key_path_manifest_file`: S3 버킷(`s3_bucket`) 내에서 사용자 지정 레이블 매니페스트 파일을 배치할 경로
   + `local_path`: 예제에서 입력 COCO 데이터 세트를 열고 새 사용자 지정 레이블 매니페스트 파일도 저장하는 로컬 경로
   + `local_images_path`: 훈련에 사용할 이미지의 로컬 경로
   + `coco_manifest`: 입력 COCO 데이터 세트 파일 이름
   + `cl_manifest_file`: 예제에서 만든 매니페스트 파일의 이름 `local_path`에서 지정한 위치에 파일이 저장됩니다. 일반적으로 파일에는 `.manifest` 확장자가 있지만 필수는 아닙니다.
   + `job_name`: 사용자 정의 레이블 작업의 이름

   ```
   import json
   import os
   import random
   import shutil
   import datetime
   import botocore
   import boto3
   import PIL.Image as Image
   import io
   
   #S3 location for images
   s3_bucket = 'bucket'
   s3_key_path_manifest_file = 'path to custom labels manifest file/'
   s3_key_path_images = 'path to images/'
   s3_path='s3://' + s3_bucket  + '/' + s3_key_path_images
   s3 = boto3.resource('s3')
   
   #Local file information
   local_path='path to input COCO dataset and output Custom Labels manifest/'
   local_images_path='path to COCO images/'
   coco_manifest = 'COCO dataset JSON file name'
   coco_json_file = local_path + coco_manifest
   job_name='Custom Labels job name'
   cl_manifest_file = 'custom_labels.manifest'
   
   label_attribute ='bounding-box'
   
   open(local_path + cl_manifest_file, 'w').close()
   
   # class representing a Custom Label JSON line for an image
   class cl_json_line:  
       def __init__(self,job, img):  
   
           #Get image info. Annotations are dealt with seperately
           sizes=[]
           image_size={}
           image_size["width"] = img["width"]
           image_size["depth"] = 3
           image_size["height"] = img["height"]
           sizes.append(image_size)
   
           bounding_box={}
           bounding_box["annotations"] = []
           bounding_box["image_size"] = sizes
   
           self.__dict__["source-ref"] = s3_path + img['file_name']
           self.__dict__[job] = bounding_box
   
           #get metadata
           metadata = {}
           metadata['job-name'] = job_name
           metadata['class-map'] = {}
           metadata['human-annotated']='yes'
           metadata['objects'] = [] 
           date_time_obj = datetime.datetime.strptime(img['date_captured'], '%Y-%m-%d %H:%M:%S')
           metadata['creation-date']= date_time_obj.strftime('%Y-%m-%dT%H:%M:%S') 
           metadata['type']='groundtruth/object-detection'
           
           self.__dict__[job + '-metadata'] = metadata
   
   
   print("Getting image, annotations, and categories from COCO file...")
   
   with open(coco_json_file) as f:
   
       #Get custom label compatible info    
       js = json.load(f)
       images = js['images']
       categories = js['categories']
       annotations = js['annotations']
   
       print('Images: ' + str(len(images)))
       print('annotations: ' + str(len(annotations)))
       print('categories: ' + str(len (categories)))
   
   
   print("Creating CL JSON lines...")
       
   images_dict = {image['id']: cl_json_line(label_attribute, image) for image in images}
   
   print('Parsing annotations...')
   for annotation in annotations:
   
       image=images_dict[annotation['image_id']]
   
       cl_annotation = {}
       cl_class_map={}
   
       # get bounding box information
       cl_bounding_box={}
       cl_bounding_box['left'] = annotation['bbox'][0]
       cl_bounding_box['top'] = annotation['bbox'][1]
    
       cl_bounding_box['width'] = annotation['bbox'][2]
       cl_bounding_box['height'] = annotation['bbox'][3]
       cl_bounding_box['class_id'] = annotation['category_id']
   
       getattr(image, label_attribute)['annotations'].append(cl_bounding_box)
   
   
       for category in categories:
            if annotation['category_id'] == category['id']:
               getattr(image, label_attribute + '-metadata')['class-map'][category['id']]=category['name']
           
       
       cl_object={}
       cl_object['confidence'] = int(1)  #not currently used by Custom Labels
       getattr(image, label_attribute + '-metadata')['objects'].append(cl_object)
   
   print('Done parsing annotations')
   
   # Create manifest file.
   print('Writing Custom Labels manifest...')
   
   for im in images_dict.values():
   
       with open(local_path+cl_manifest_file, 'a+') as outfile:
               json.dump(im.__dict__,outfile)
               outfile.write('\n')
               outfile.close()
   
   # Upload manifest file to S3 bucket.
   print ('Uploading Custom Labels manifest file to S3 bucket')
   print('Uploading'  + local_path + cl_manifest_file + ' to ' + s3_key_path_manifest_file)
   print(s3_bucket)
   s3 = boto3.resource('s3')
   s3.Bucket(s3_bucket).upload_file(local_path + cl_manifest_file, s3_key_path_manifest_file + cl_manifest_file)
   
   # Print S3 URL to manifest file,
   print ('S3 URL Path to manifest file. ')
   print('\033[1m s3://' + s3_bucket + '/' + s3_key_path_manifest_file + cl_manifest_file + '\033[0m') 
   
   # Display aws s3 sync command.
   print ('\nAWS CLI s3 sync command to upload your images to S3 bucket. ')
   print ('\033[1m aws s3 sync ' + local_images_path + ' ' + s3_path + '\033[0m')
   ```

1. 코드를 실행합니다.

1. 프로그램 출력에서 `s3 sync` 명령을 기록해 둡니다. 이 정보는 다음 단계에서 필요합니다.

1. 명령 프롬프트에서 `s3 sync` 명령을 실행합니다. 이미지는 S3 버킷에 업로드됩니다. 업로드 중에 명령이 실패하면 로컬 이미지가 S3 버킷과 동기화될 때까지 명령을 다시 실행하세요.

1. 프로그램 출력에서 매니페스트 파일의 S3 URL 경로를 기록해 둡니다. 이 정보는 다음 단계에서 필요합니다.

1. [SageMaker AI Ground Truth 매니페스트 파일을 사용하여 데이터 세트 생성(콘솔)](md-create-dataset-ground-truth.md#md-create-dataset-ground-truth-console)의 지침에 따라 업로드된 매니페스트 파일로 데이터 세트를 생성하세요. 8단계로 **.manifest 파일 위치**에 이전 단계에서 기록해 둔 Amazon S3 URL을 입력합니다. AWS SDK를 사용하고 있다면 [SageMaker AI Ground Truth 매니페스트 파일(SDK)을 사용하여 데이터 세트 생성](md-create-dataset-ground-truth.md#md-create-dataset-ground-truth-sdk) 항목을 수행하세요.