此错误通常发生在使用Automl Vision进行图像分类或对象检测时,因为该服务要求至少有一些有效的预处理示例用于训练模型。如果没有提供有效的示例,则会收到上述错误消息。
解决此问题的方法是添加有效的预处理示例。以下是一些可能有助于解决问题的示例代码:
from google.cloud import automl_v1beta1 as automl
#设置Automl Vision客户端 client = automl.AutoMlClient()
dataset_id = "DATASET_ID"
model_id = "MODEL_ID"
#为图像分类问题添加示例 input_uris = ["gs://BUCKET_ID/path/to/image1.jpg", "gs://BUCKET_ID/path/to/image2.jpg"]
response = client.import_data(dataset_id, input_config={"gcs_source": {"input_uris": input_uris}}) print("Response:", response)
from google.cloud import storage
storage_client = storage.Client() bucket_name = "BUCKET_NAME" bucket = storage_client.bucket(bucket_name)
blob = bucket.blob("image1.jpg") blob.upload_from_filename("local/path/to/image1.jpg")
client = automl.AutoMlClient()
input_config = {"gcs_source": {"input_uris": ["gs://{}/image1.jpg".format(bucket_name)]}} response = client.create_dataset("projects/PROJECT_ID/locations/us-central1/datasets/DATASET_ID", {"image_classification_dataset_metadata": {}}, input_config=input_config) print("Response:", response)