创建CSV文件的最佳方法是什么?该文件列出了要导入到AutoML Vision的Google Cloud存储桶中的图像?
如果你想监听保存在bucket上的文件,你可以使用谷歌云功能来监听新文件,并在另一个bucket 中创建csv文件
例如,您可以使用此python代码作为起点,此代码记录新上传文件的详细信息
def hello_gcs_generic(data, context):
"""Background Cloud Function to be triggered by Cloud Storage.
This generic function logs relevant data when a file is changed.
Args:
data (dict): The Cloud Functions event payload.
context (google.cloud.functions.Context): Metadata of triggering event.
Returns:
None; the output is written to Stackdriver Logging
"""
print('Event ID: {}'.format(context.event_id))
print('Event type: {}'.format(context.event_type))
print('Bucket: {}'.format(data['bucket']))
print('File: {}'.format(data['name']))
print('Metageneration: {}'.format(data['metageneration']))
print('Created: {}'.format(data['timeCreated']))
print('Updated: {}'.format(data['updated']))
基本上,该功能是监听存储事件"google.storage.object.finalize"(上传文件时会发生这种情况(
要在云上部署此功能,您可以使用以下命令
gcloud functions deploy hello_gcs_generic --runtime python37 --trigger-resource [your bucket name] --trigger-event google.storage.object.finalize
或者您可以使用GCP控制台(Web UI(来部署此功能。
- 在触发器字段上选择"云存储">
- 在事件类型上选择"完成/创建">
- 指定您的bucket
甚至可以在云函数中使用Auto ML直接处理文件,如本例所述。