Ground Truth で、AWS が提供する Lambda 関数とカスタム UI テンプレートを使用するにはどうすればよいですか?

所要時間2分
0

Amazon SageMaker Ground Truth で、カスタム UI テンプレートと AWS Lambda 関数を、ラベル付けジョブに使用したいと考えています。

解決方法

1.    次の例に示すように、ラベル付けジョブ用のカスタム UI テンプレートを作成します。セマンティックセグメンテーションジョブの場合は次の例のように、name 変数を crowd-semantic-segmentation に設定します。バウンディングボックスジョブでは、name 変数を boundingBoxに設定します。カスタムテンプレート用の拡張 HTML 要素に関する完全なリストについては、「Crowd HTML 要素のリファレンス」をご参照ください。

<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
    <crowd-semantic-segmentation name="crowd-semantic-segmentation" src="{{ task.input.taskObject | grant_read_access }}" header= "{{ task.input.header }}" labels="{{ task.input.labels | to_json | escape }}">

        <full-instructions header= "Segmentation Instructions">
            <ol>
                <li>Read the task carefully and inspect the image.</li>
                <li>Read the options and review the examples provided to understand more about the labels.</li>
                <li>Choose the appropriate label that best suits the image.</li>
            </ol>
        </full-instructions>

        <short-instructions>
            <p>Use the tools to label the requested items in the image</p>
        </short-instructions>
    </crowd-semantic-segmentation>
</crowd-form>

2.    ラベル用の JSON ファイルを作成します。次に例を示します。

 {
        "labels": [
            {
                "label": "Chair"
            },
            ...
            {
                "label": "Oven"
            }
        ]
}

3.    イメージ用の 入力マニフェストファイル を作成します。次に例を示します。

{"source-ref":"s3://awsdoc-example-bucket/input_manifest/apartment-chair.jpg"}
{"source-ref":"s3://awsdoc-example-bucket/input_manifest/apartment-carpet.jpg"}

4.    HTML、マニフェスト、および JSON ファイルを Amazon Simple Storage Service (Amazon S3) にアップロードします。次に例を示します。

import boto3
import os

bucket = 'awsdoc-example-bucket'
prefix = 'GroundTruthCustomUI'

boto3.Session().resource('s3').Bucket(bucket).Object(os.path.join(prefix, 'customUI.html')).upload_file('customUI.html')
boto3.Session().resource('s3').Bucket(bucket).Object(os.path.join(prefix, 'input.manifest')).upload_file('input.manifest')
boto3.Session().resource('s3').Bucket(bucket).Object(os.path.join(prefix, 'testLabels.json')).upload_file('testLabels.json')

5.    前処理および注釈統合を処理する Lambda 関数用に、Amazon Resource Name (ARN) を取得します。たとえば、セマンティックセグメンテーションの場合の ARN は次のようになります。

arn:aws:lambda:eu-west-1:111122223333:function:PRE-SemanticSegmentation
arn:aws:lambda:eu-west-1:111122223333:function:ACS-SemanticSegmentation

6.    AWS SDK(boto3 など)を使用してラベリングジョブを作成します。次の例でこれらの値を置き換えます。

INPUT_MANIFEST_IN_S3 S3_OUTPUT_PATH IAM_ROLE_ARN LABELS_JSON_FILE_IN_S3 WORKTEAM_ARN HTML_TEMPLATE_IN_S3

import boto3

client = boto3.client('sagemaker')
client.create_labeling_job(LabelingJobName='SemanticSeg-CustomUI',
    LabelAttributeName='output-ref',
    InputConfig={
        'DataSource': {
            'S3DataSource': {
                'ManifestS3Uri': 'INPUT_MANIFEST_IN_S3'
            }
        },
        'DataAttributes': {
            'ContentClassifiers' : [
                'FreeOfPersonallyIdentifiableInformation',
            ]
        }
    },
    OutputConfig={
        'S3OutputPath' : 'S3_OUTPUT_PATH' 
    },
    RoleArn='IAM_ROLE_ARN',
    LabelCategoryConfigS3Uri='LABELS_JSON_FILE_IN_S3',
    StoppingConditions={
        'MaxPercentageOfInputDatasetLabeled': 100
    },
    HumanTaskConfig={
        'WorkteamArn': 'WORKTEAM_ARN',
        'UiConfig': {
            'UiTemplateS3Uri' : 'HTML_TEMPLATE_IN_S3'
        },
        'PreHumanTaskLambdaArn' : 'arn:aws:lambda:eu-west-1:111122223333:function:PRE-SemanticSegmentation',
        'TaskKeywords': [
            'SemanticSegmentation',
        ],
        'TaskTitle': 'Semantic Segmentation',
        'TaskDescription': 'Draw around the specified labels using the tools',
        'NumberOfHumanWorkersPerDataObject': 1,
        'TaskTimeLimitInSeconds': 3600,
        'TaskAvailabilityLifetimeInSeconds': 1800,
        'MaxConcurrentTaskCount': 1,
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:eu-west-1:111122223333:function:ACS-SemanticSegmentation'
        }
    },
    Tags=[
        {
            'Key': 'reason',
            'Value': 'CustomUI'
        }
    ])

関連情報

セマンティックセグメンテーションアルゴリズム

AWS公式
AWS公式更新しました 2年前
コメントはありません

関連するコンテンツ