AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
CreateDataset
搭配使用 AWS SDK
以下代码示例演示如何使用 CreateDataset
。
有关更多信息,请参阅创建数据集。
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class Datasets: @staticmethod def create_dataset(lookoutvision_client, project_name, manifest_file, dataset_type): """ Creates a new Lookout for Vision dataset :param lookoutvision_client: A Lookout for Vision Boto3 client. :param project_name: The name of the project in which you want to create a dataset. :param bucket: The bucket that contains the manifest file. :param manifest_file: The path and name of the manifest file. :param dataset_type: The type of the dataset (train or test). """ try: bucket, key = manifest_file.replace("s3://", "").split("/", 1) logger.info("Creating %s dataset type...", dataset_type) dataset = { "GroundTruthManifest": {"S3Object": {"Bucket": bucket, "Key": key}} } response = lookoutvision_client.create_dataset( ProjectName=project_name, DatasetType=dataset_type, DatasetSource=dataset, ) logger.info("Dataset Status: %s", response["DatasetMetadata"]["Status"]) logger.info( "Dataset Status Message: %s", response["DatasetMetadata"]["StatusMessage"], ) logger.info("Dataset Type: %s", response["DatasetMetadata"]["DatasetType"]) # Wait until either created or failed. finished = False status = "" dataset_description = {} while finished is False: dataset_description = lookoutvision_client.describe_dataset( ProjectName=project_name, DatasetType=dataset_type ) status = dataset_description["DatasetDescription"]["Status"] if status == "CREATE_IN_PROGRESS": logger.info("Dataset creation in progress...") time.sleep(2) elif status == "CREATE_COMPLETE": logger.info("Dataset created.") finished = True else: logger.info( "Dataset creation failed: %s", dataset_description["DatasetDescription"]["StatusMessage"], ) finished = True if status != "CREATE_COMPLETE": message = dataset_description["DatasetDescription"]["StatusMessage"] logger.exception("Couldn't create dataset: %s", message) raise Exception(f"Couldn't create dataset: {message}") except ClientError: logger.exception("Service error: Couldn't create dataset.") raise
-
有关API详细信息,请参阅CreateDataset中的 AWS SDKPython (Boto3) API 参考。
-
操作
CreateModel