出现“Amazon SageMaker Ground Truth 自定义标注作业错误:无法读取空值的 'taskInput' 属性。”这个错误通常是因为在提交自定义标注作业时,传递的任务输入数据为空。
要解决这个问题,你需要确保正确地设置了任务输入数据。下面是一个示例代码,演示了如何创建自定义标注作业,并设置任务输入数据:
import boto3
# 创建SageMaker客户端
sagemaker_client = boto3.client('sagemaker')
# 定义任务输入数据
task_input = {
'dataset': {
's3DataSource': {
'manifestS3Uri': 's3://your-bucket/your-manifest.manifest'
}
}
}
# 创建自定义标注作业
response = sagemaker_client.create_labeling_job(
LabelingJobName='your-labeling-job-name',
LabelAttributeName='your-label-attribute',
InputConfig={
'DataSource': {
'S3DataSource': {
'ManifestS3Uri': 's3://your-bucket/your-manifest.manifest'
}
}
},
OutputConfig={
'S3OutputPath': 's3://your-bucket/your-output-path'
},
RoleArn='arn:aws:iam::your-account-id:role/your-role',
LabelCategoryConfigS3Uri='s3://your-bucket/your-label-categories',
LabelingJobAlgorithmsConfig={
'LabelingJobAlgorithmSpecificationArn': 'arn:aws:sagemaker:your-region:your-account-id:labeling-job-algorithm-specification/your-specification',
'InitialActiveLearningModelArn': 'arn:aws:sagemaker:your-region:your-account-id:active-learning-model/your-model'
},
HumanTaskConfig={
'WorkteamArn': 'arn:aws:sagemaker:your-region:your-account-id:workteam/your-workteam',
'UiConfig': {
'UiTemplateS3Uri': 's3://your-bucket/your-ui-template'
},
'PreHumanTaskLambdaArn': 'arn:aws:lambda:your-region:your-account-id:function:your-pre-human-task-lambda',
'TaskKeywords': ['your-task-keywords'],
'TaskTitle': 'your-task-title',
'TaskDescription': 'your-task-description',
'NumberOfHumanWorkersPerDataObject': 1,
'TaskTimeLimitInSeconds': 3600,
'TaskAvailabilityLifetimeInSeconds': 86400,
'MaxConcurrentTaskCount': 100,
'AnnotationConsolidationConfig': {
'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:your-region:your-account-id:function:your-annotation-consolidation-lambda'
}
},
StoppingConditions={
'MaxPercentageOfInputDatasetLabeled': 90
},
LabelingJobOutput={
'OutputDatasetS3Uri': 's3://your-bucket/your-output-dataset'
}
)
print(response)
请确保在 task_input 中设置了正确的数据源路径,并将其传递给 create_labeling_job() 函数的 HumanTaskConfig 参数中。
希望这个代码示例能帮助你解决问题。根据你的具体情况,你可能需要根据自己的需求进行适当的修改。