Saltar al contenido

¿Cómo puedo usar una plantilla de interfaz de usuario personalizada con las funciones de Lambda proporcionadas por AWS en Ground Truth?

3 minutos de lectura
0

Quiero usar una plantilla de interfaz de usuario personalizada de Amazon SageMaker Ground Truth y funciones de AWS Lambda para un trabajo de etiquetado.

Resolución

Crea una plantilla de interfaz de usuario personalizada para el trabajo de etiquetado, como se muestra en el siguiente ejemplo:

  1. Para los trabajos de segmentación semántica, define la variable name en crowd-semantic-segmentation, como se muestra en el siguiente ejemplo. Para los trabajos de cuadro delimitador, define la variable name en boundingBox. Para obtener una lista completa de los elementos HTML mejorados para plantillas personalizadas, consulta Referencia de elementos HTML de Crowd.

    <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. Crea un archivo JSON para las etiquetas. Ejemplo:

    {
      "labels": [
        {
          "label": "Chair"
        },
      ...
        {
          "label": "Oven"
          }
       ]
    }
  3. Crea un archivo de manifiesto de entrada para las imágenes. Ejemplo:

    {"source-ref":"s3://awsdoc-example-bucket/input_manifest/apartment-chair.jpg"}
    {"source-ref":"s3://awsdoc-example-bucket/input_manifest/apartment-carpet.jpg"}
  4. Carga los archivos HTML, de manifiesto y JSON en Amazon Simple Storage Service (Amazon S3). Ejemplo:

    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. Recupera los nombres de recursos de Amazon (ARN) para las funciones de Lambda de preprocesamiento y consolidación de anotaciones. Por ejemplo, estos son los ARN de segmentación semántica:
    arn:aws:lambda:eu-west-1:111122223333:function:PRE-SemanticSegmentation
    arn:aws:lambda:eu-west-1:111122223333:function:ACS-SemanticSegmentation

  6. Para crear el trabajo de etiquetado, utiliza un SDK de AWS, como boto3:

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

En el ejemplo anterior, sigue estos pasos:

  • Sustituye S3_OUTPUT_PATH por la ruta de salida de S3.
  • Sustituye IAM_ROLE_ARN por el ARN del rol.
  • Sustituye WORKTEAM_ARN por el ARN del equipo de trabajo.
  • Sustituye INPUT_MANIFEST_IN_S3 por el URI de manifiesto de entrada.
  • Sustituye LABELS_JSON_IN_S3 por el URI JSON de etiquetas.
  • Sustituye HTML_TEMPLATE_IN_S3 por el URI de la plantilla HTML.

Información relacionada

Algoritmo de segmentación semántica

OFICIAL DE AWSActualizada hace 2 años