내용으로 건너뛰기

Ground Truth에서 AWS 제공 Lambda 함수와 함께 사용자 지정 UI 템플릿을 사용하려면 어떻게 해야 합니까?

2분 분량
0

레이블 지정 작업에 Amazon SageMaker Ground Truth 사용자 지정 UI 템플릿과 AWS Lambda 함수를 사용하려고 합니다.

해결 방법

다음 예와 같이 레이블 지정 작업의 사용자 지정 UI 템플릿을 만듭니다.

  1. 시맨틱 분할 작업의 경우 다음 예와 같이 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 boto3import 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 리소스 이름(ARN)을 검색합니다. 예를 들어 시맨틱 분할 ARN은 다음과 같습니다.
    arn:aws:lambda:eu-west-1:111122223333:function:PRE-SemanticSegmentation
    arn:aws:lambda:eu-west-1:111122223333:function:ACS-SemanticSegmentation

  6. 레이블 지정 작업을 만들려면 boto3과 같은 AWS SDK를 사용합니다.

    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"}],
    )

이전 예제에서 다음 단계를 완료합니다.

  • S3_OUTPUT_PATH를 S3 출력 경로로 바꿉니다.
  • IAM_ROLE_ARN을 역할 ARN으로 바꿉니다.
  • WORKTEAM_ARN을 작업팀 ARN으로 바꿉니다.
  • INPUT_MANIFEST_IN_S3를 입력 매니페스트 URI로 바꿉니다.
  • LABELS_JSON_IN_S3를 레이블 JSON URI로 바꿉니다.
  • HTML_TEMPLATE_IN_S3를 HTML 템플릿 URI로 바꿉니다.

관련 정보

시맨틱 분할 알고리즘

AWS 공식업데이트됨 2년 전