Open In App
Related Articles

Amazon Web Services – Using Custom UI Templates in Sagemaker

Like Article
Save Article
Report issue

In this article,  we will look into how you can use a custom UI template with AWS Lambda functions in Amazon Sagemaker ground truth. 

Here we will be using a Jupyter notebook to create a ground truth labeling job using a custom UI template with AWS-provided lambda functions using an AWS SDK such as boto3. To do so follow the below steps:

Step 1: First create a custom UI template file named customui.html to create a semantic segmentation job. A sample code has been given below:


    <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">
                <li>Inspect the Image</li>
                <li>Add appropriate label for the image.</li>
<p>Use the tools to label the requested items in the image</p>


Step 2: Now create a JSON file named testlabels.json for the labels and an input manifest file named input.manifest for the images in Amazon Simple Storage Service.

Step 3: Upload the HTML, manifest, and JSON files to amazon simple storage service by executing this python code:


import boto3
import os
bucket = 'labelingjobdemoinputz'
prefix ='GroundTruthCustom'
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,
boto3.Session().resource('s3').Bucket (bucket).Object(os.path.join(prefix,


Step 4: Retrieve the Amazon Resource Names(ARNs) for the pre-processing and annotation consolidation Lambda functions provided by AWS. For example here is the semantic segmentation ARNs:

Step 5: Now create a labeling job using an AWS SDK. Make sure to replace the default variables in the script with the corresponding amazon S3 file paths and ARNs. 


import boto3
client = boto3.client('sagemaker')
        'DataSource': {
            'S3DataSource': {
                'ManifestS3Uri': 'INPUT_MANIFEST_IN_S3'
        'DataAttributes': {
            'ContentClassifiers' : [
        'S3OutputPath' : 'S3_OUTPUT_PATH' 
        'MaxPercentageOfInputDatasetLabeled': 100
        'WorkteamArn': 'WORKTEAM_ARN',
        'UiConfig': {
            'UiTemplateS3Uri' : 'HTML_TEMPLATE_IN_S3'
        'PreHumanTaskLambdaArn' : 'YOUR_ARNs_HERE',
        'TaskKeywords': [
        'TaskTitle': 'Semantic Segmentation',
        'TaskDescription': 'Draw around the specified labels using the tools',
        'NumberOfHumanWorkersPerDataObject': 1,
        'TaskTimeLimitInSeconds': 3600,
        'TaskAvailabilityLifetimeInSeconds': 1800,
        'MaxConcurrentTaskCount': 1,
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'YOUR_ARNs_HERE
            'Key': 'reason',
            'Value': 'CustomUI'


This will result on the following:

Step 6: Now navigate to the ground truth console to see the newly created labeling job. 

Now you know how to use a custom UI template with AWS-provided lambda functions in ground truth.

Last Updated : 28 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads