すでに Amazon Lookout for Vision コンソールを使って回路基板サンプル画像でデータセットを作成した場合は、Amazon Lookout for Vision で作成されたマニフェストファイルを再利用してください。トレーニングおよびテストマニフェストファイルの場所は s3://bucket/datasets/project
name/train or
test/manifests/output/output.manifest です。
@staticmethoddefcreate_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 isFalse:
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 = Trueelse:
logger.info(
"Dataset creation failed: %s",
dataset_description["DatasetDescription"]["StatusMessage"],
)
finished = Trueif 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