

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在清单文件中导入图像级标签
<a name="md-create-manifest-file-classification"></a>

要导入图像级标签（标有场景、概念或不需要本地化信息的对象的图像），可以将 SageMaker AI Ground Truth 分类[作业输出](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-data-output.html#sms-output-class)格式 JOB 行添加到清单文件中。清单文件由一个或多个 JSON 行组成，每个行对应一张您要导入的图像。

**提示**  
为了简化清单文件的创建，我们提供了从 CSV 文件创建清单文件的 Python 脚本。有关更多信息，请参阅 [从 CSV 文件创建清单文件](ex-csv-manifest.md)。

**创建图像级标签的清单文件**

1. 创建一个空文本文件。

1. 为要导入的每张图像各添加一个 JSON 行。每个 JSON 行应该与下面类似。

   ```
   {"source-ref":"s3://custom-labels-console-us-east-1-nnnnnnnnnn/gt-job/manifest/IMG_1133.png","TestCLConsoleBucket":0,"TestCLConsoleBucket-metadata":{"confidence":0.95,"job-name":"labeling-job/testclconsolebucket","class-name":"Echo Dot","human-annotated":"yes","creation-date":"2020-04-15T20:17:23.433061","type":"groundtruth/image-classification"}}
   ```

1. 保存该文件。您可以使用扩展名 `.manifest`，但不要求必须如此。

1. 使用您创建的清单文件，创建一个数据集。有关更多信息，请参阅 [使用 SageMaker AI Ground Truth 格式的清单文件创建数据集（控制台）](md-create-manifest-file.md#create-dataset-procedure-manifest-file)。

 

## 图像级 JSON 行
<a name="md-manifest-classification-json"></a>

在本部分中，我们将介绍如何为单张图像创建 JSON 行。请考虑以下图像。下图的场景可能叫做 *Sunrise*。

![落日时分的湖面，有一个码头和几艘小船，周围群山环绕。](http://docs.aws.amazon.com/zh_cn/rekognition/latest/customlabels-dg/images/sunrise.png)


上面这张包含 *Sunrise* 场景的图像的 JSON 行可能如下所示。

```
{
    "source-ref": "s3://bucket/images/sunrise.png",
    "testdataset-classification_Sunrise": 1,
    "testdataset-classification_Sunrise-metadata": {
        "confidence": 1,
        "job-name": "labeling-job/testdataset-classification_Sunrise",
        "class-name": "Sunrise",
        "human-annotated": "yes",
        "creation-date": "2020-03-06T17:46:39.176",
        "type": "groundtruth/image-classification"
    }
}
```

请注意以下信息。

### source-ref
<a name="w2aac20c17c25c27c19c11c13"></a>

（必需）图像的 Amazon S3 位置。格式为 `"s3://{{BUCKET}}/{{OBJECT_PATH}}"`。所导入数据集中的图像必须存储在同一 Amazon S3 存储桶中。

### {{testdataset-classification\_Sunrise}}
<a name="w2aac20c17c25c27c19c11c15"></a>

（必需）标签属性。您选择的字段名称。该字段的值（在前面的示例中为 1）是标签属性的标识符。Amazon Rekognition Custom Labels 不使用它，它可以是任何整数值。必须有相应的元数据，这些元数据通过字段名称进行标识，并附有 *-metadata*。例如 `"testdataset-classification_Sunrise-metadata"`。

### {{testdataset-classification\_Sunrise}}-元数据
<a name="w2aac20c17c25c27c19c11c17"></a>

（必需）与标签属性相关的元数据。该字段名称必须与标签属性附加 *-metadata* 之后相同。

*confidence*  
（必需）Amazon Rekognition Custom Labels 目前未使用该属性，但必须为其提供介于 0 和 1 之间的值。

*job-name*  
（可选）您为用于处理图像的作业选择的名称。

*class-name*  
（必需）您为适用于图像的场景或概念选择的类别名称。例如 `"Sunrise"`。

*human-annotated*  
（必需）如果注释由人工完成，请指定 `"yes"`。否则为 `"no"`。

*creation-date*   
（必需）创建标签的协调世界时 (UTC) 日期和时间。

*type*  
（必需）应该应用于图像的处理类型。对于图像级标签，该值为 `"groundtruth/image-classification"`。

### 为图像添加多个图像级标签
<a name="md-dataset-purpose-classification-multiple-labels"></a>

可以为图像添加多个标签。例如，以下 JSON 为单个图像添加两个标签：*football* 和 *ball*。

```
{
    "source-ref": "S3 bucket location", 
    "sport0":0, # FIRST label
    "sport0-metadata": { 
        "class-name": "football", 
        "confidence": 0.8, 
        "type":"groundtruth/image-classification", 
        "job-name": "identify-sport", 
        "human-annotated": "yes", 
        "creation-date": "2018-10-18T22:18:13.527256" 
    },
    "sport1":1, # SECOND label
    "sport1-metadata": { 
        "class-name": "ball", 
        "confidence": 0.8, 
        "type":"groundtruth/image-classification", 
        "job-name": "identify-sport", 
        "human-annotated": "yes", 
        "creation-date": "2018-10-18T22:18:13.527256" 
    }
}  # end of annotations for 1 image
```