AutoML Vision元数据问题

问题描述

我正在尝试使用Raspi 3B +和AutoML Vision来训练分类模型。但是,当我尝试在Google Cloud Platform上创建数据集时,会遇到如下问题:

Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/google/api core/grpc helpers.py",line 57,in error remapped callable
return callable (*args,**kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/grpc/ channel.py",line 826,in call __
return end_unary_response blocking({state,call,False,None)
File "/home/pi/.local/lib/python3.7/site-packages/grpc/ channel.py",line 729,in end unary response blocking
raise InactiveRpcError(state)
grpc. channel. InactiveRpcError: < InactiveRpcError of RPC that terminated with:
status = StatusCode. INVALID ARGUMENT
details = "List of found errors: 1.Field: parent; Message: required field is invalid "
debug error string = "{"created":"G1604833054.567218256","description":"Error received from peer ipv6: [2a00:1450:400a: 801: :200a] :443","file":"src/core/lib/surface/call.cc","file line":1056,"grpc_message":"List of found
errors:\tl.Field: parent; nessage: required field is invalid\t","grpc_ status":3}"
>

创建数据集代码

automl_client = automl.AutoMlClient()
project_location = automl_client.location_path(project_id,region_name)
bucket = storage_client.bucket(bucket_name)

# upload the images to google cloud bucket
upload_image_excel(bucket,bucket_name,dataset_name,status_list,csv_name) 

# Create a new automl dataset programatically
classification_type = 'MULTICLASS' 
dataset_Metadata = {'classification_type': classification_type}
dataset_config = {
    'display_name': dataset_name,'image_classification_dataset_Metadata': dataset_Metadata
}

dataset = automl_client.create_dataset(project_location,dataset_config)
dataset_id = dataset.name.split('/')[-1]
dataset_full_id = automl_client.dataset_path(
    project_id,region_name,dataset_id
)

# Read the *.csv file on Google Cloud
remote_csv_path = 'gs://{0}/{1}'.format(bucket_name,csv_name)
input_uris = remote_csv_path.split(',')
input_config = {'gcs_source': {'input_uris': input_uris}}
response = automl_client.import_data(dataset_full_id,input_config)

有人知道这里发生了什么吗?

解决方法

您使用的是哪个地区?请注意,对于此功能,当前项目资源必须位于us-central1区域中才能使用此API [1]。

错误提示是一个无效参数,因此我认为上述不是问题。查看有关创建数据集的GCP文档[1],我发现您的代码与该示例上的代码不同。元数据和配置的设置方式不同。您能否尝试使用与示例共享中相同的格式来重新创建它?我相信这应该可以解决遇到的问题。

这里有一个代码示例:

from google.cloud import automl

# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# display_name = "your_datasets_display_name"

client = automl.AutoMlClient()

# A resource that represents Google Cloud Platform location.
project_location = f"projects/{project_id}/locations/us-central1"
# Specify the classification type
# Types:
# MultiLabel: Multiple labels are allowed for one example.
# MultiClass: At most one label is allowed per example.
# https://cloud.google.com/automl/docs/reference/rpc/google.cloud.automl.v1#classificationtype
metadata = automl.ImageClassificationDatasetMetadata(
    classification_type=automl.ClassificationType.MULTILABEL
)
dataset = automl.Dataset(
    display_name=display_name,image_classification_dataset_metadata=metadata,)

# Create a dataset with the dataset metadata in the region.
response = client.create_dataset(parent=project_location,dataset=dataset)

created_dataset = response.result()

# Display the dataset information
print("Dataset name: {}".format(created_dataset.name))
print("Dataset id: {}".format(created_dataset.name.split("/")[-1]))

[1] https://cloud.google.com/vision/automl/docs/create-datasets#automl_vision_classification_create_dataset-python