Come posso utilizzare un modello di interfaccia utente personalizzato con le funzioni Lambda fornite da AWS in Ground Truth?
Desidero utilizzare un modello di interfaccia utente personalizzato Amazon SageMaker Ground Truth e le funzioni AWS Lambda per un processo di etichettatura.
Risoluzione
Crea un modello di interfaccia utente personalizzato per il processo di etichettatura, come mostrato nell'esempio seguente:
-
Per i processi di segmentazione semantica, imposta la variabile name su crowd-semantic-segmentation, come mostrato nell'esempio seguente. Per i processi di delimitazione con riquadri, imposta la variabile name su boundingBox. Per un elenco completo degli elementi HTML avanzati per i modelli personalizzati, consulta Riferimento per gli elementi 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> -
Crea un file JSON per le etichette. Esempio:
{ "labels": [ { "label": "Chair" }, ... { "label": "Oven" } ] } -
Crea un file manifesto di input per le immagini. Esempio:
{"source-ref":"s3://awsdoc-example-bucket/input_manifest/apartment-chair.jpg"} {"source-ref":"s3://awsdoc-example-bucket/input_manifest/apartment-carpet.jpg"} -
Carica i file HTML, manifesto e JSON in Amazon Simple Storage Service (Amazon S3). Esempio:
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') -
Recupera i nomi della risorsa Amazon (ARN) per le funzioni Lambda di pre-elaborazione e consolidamento delle annotazioni. Ad esempio, ecco gli ARN per la segmentazione semantica:
arn:aws:lambda:eu-west-1:111122223333:function:PRE-SemanticSegmentation
arn:aws:lambda:eu-west-1:111122223333:function:ACS-SemanticSegmentation -
Per creare il processo di etichettatura, utilizza un SDK AWS, come 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"}], )
Nell'esempio precedente, completa questi passaggi:
- Sostituisci S3_OUTPUT_PATH con il percorso di output di S3
- Sostituisci IAM_ROLE_ARN con l’ARN del ruolo
- Sostituisci WORKTEAM_ARN con l’ARN del team di lavoro
- Sostituisci INPUT_MANIFEST_IN_S3 con l'URI del manifesto di input
- Sostituisci LABELS_JSON_IN_S3 con l'URI del JSON delle etichette
- Sostituisci HTML_TEMPLATE_IN_S3 con l'URI del modello HTML
Informazioni correlate
- Argomenti
- Machine Learning & AI
- Lingua
- Italiano
