本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Bounding Box
用于训练机器学习模型的映像通常包含多个对象。要对图像中的一个或多个对象进行分类和本地化,请使用 Amazon SageMaker Ground Truth 边界框标记作业任务类型。在这种情况下,本地化意味着边界框的像素位置。
您可以使用 Ground Truth 控制台的 Amazon SageMaker 部分或 CreateLabelingJob
操作创建边界框标记作业。
对于此任务类型,如果您创建自己的清单文件,请使用 "source-ref"
识别 Amazon S3 中您要标记的每个图像文件的位置。有关更多信息,请参阅输入数据。
创建边界框标记作业(控制台)
您可以按照 创建标记作业(控制台)中的说明进行操作,以了解如何在 SageMaker 控制台中创建边界框标记作业。在步骤 10 中,从 Task category (任务类别) 下拉菜单中选择 Image (映像),然后选择 Bounding (边界) 框作为任务类型。
Ground Truth 为标记任务提供类似于以下内容的工作人员 UI。使用 控制台创建标记作业时,您可以指定说明以帮助工作人员完成作业,并提供最多 50 个可供工作人员选择的标签。

创建边界框标记作业 (API)
要创建边界框标记作业,请使用 SageMaker API 操作 CreateLabelingJob
。该 API 为所有 AWS 开发工具包定义了该操作。要查看此操作支持的语言特定的SDKs列表,请查看 的另请参阅部分CreateLabelingJob
。
请按照创建标记作业 (API)中的说明进行操作,并在配置请求时执行以下操作:
-
此任务类型的注释前 Lambda 函数以
PRE-BoundingBox
结尾。要查找您的区域的注释前 Lambda ARN,请参阅 PreHumanTaskLambdaArn。 -
此任务类型的注释合并 Lambda 函数以
ACS-BoundingBox
结尾。要查找您所在区域的注释合并 Lambda ARN,请参阅 AnnotationConsolidationLambdaArn。
以下是在 区域中创建标记作业的 AWS
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'
}, ] )
为边界框标记作业提供模板
如果要使用 API 创建标记作业,必须在 UiTemplateS3Uri
中提供工作人员任务模板。复制并修改以下模板。仅修改 short-instructions
、 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>
边界框输出数据
在创建边界框标记作业后,您的输出数据将位于使用 API 时在 Amazon S3 参数中指定的 S3OutputPath
存储桶中,或者位于 控制台的 Job overview (作业概述) 部分的 Output dataset location (输出数据集位置) 字段中。
例如,成功完成的单类边界框任务的输出清单文件将包含以下内容:
[ { "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 } } } ]
要了解有关边界框标记作业产生的输出清单文件的更多信息,请参阅边界框作业输出。
要详细了解 Ground Truth 生成的输出清单文件以及 Ground Truth 用于存储输出数据的文件结构,请参阅输出数据。