

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

# COCO 資料集格式
<a name="md-coco-overview"></a>

COCO 資料集由五個區段的資訊組成，可提供整個資料集的資訊。COCO 物件偵測資料集的格式會以 [COCO 資料格式](http://cocodataset.org/#format-data)記錄。
+ info — 有關資料集的一般資訊。
+ licenses — 資料集中影像的授權資訊。
+ [images](#md-coco-images) — 資料集中的影像清單。
+ [annotations](#md-coco-annotations) — 資料集中所有影像中出現的註釋清單 (包括週框方塊)。
+ [categories](#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 自訂標籤清單檔案所需的欄位。
+ `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 自訂標籤清單檔案所需的欄位。
+ `id` — (非必要) 註釋的識別碼。
+ `image_id` — (必要) 對應於影像陣列中的影像 `id`。
+ `category_id` — (必要) 標籤的識別碼，可識別週框方塊內的物件。它會對應至類別陣列的 `id` 欄位。
+ `iscrowd` — (非必要) 指定影像是否包含一群物件。
+ `segmentation` — (非必要) 影像上物件的分割資訊。Amazon Rekognition 自訂標籤不支援分割。
+ `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 自訂標籤清單檔案所需的欄位。
+ `supercategory` — (非必要) 標籤的父類別。
+ `id` — (必要) 標籤識別碼。`id` 欄位會對應至 `annotation` 物件中的 `category_id` 欄位。在下列範例中，Echo Dot 的識別碼為 2。
+ `name` — (必要) 標籤名稱。

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