【发布时间】:2019-09-14 17:38:44
【问题描述】:
我尝试使用 Python API 使用批量导入来创建包含产品的产品集;但是,它会在“处理操作名称”处阻塞。
大约 1 小时后,API 仍然在“处理操作名称”处阻塞。我使用 COMMAND-LINE 方法仔细检查现有产品集。并且产品集构建成功。
我认为#同步检查操作状态有问题。 我使用来自https://cloud.google.com/vision/product-search/docs/create-product-set#product-search-bulk-import-python的示例代码:
def import_product_sets(project_id, location, gcs_uri):
"""Import images of different products in the product set.
Args:
project_id: Id of the project.
location: A compute region name.
gcs_uri: Google Cloud Storage URI.
Target files must be in Product Search CSV format.
"""
client = vision.ProductSearchClient()
# A resource that represents Google Cloud Platform location.
location_path = client.location_path(
project=project_id, location=location)
# Set the input configuration along with Google Cloud Storage URI
gcs_source = vision.types.ImportProductSetsGcsSource(
csv_file_uri=gcs_uri)
input_config = vision.types.ImportProductSetsInputConfig(
gcs_source=gcs_source)
# Import the product sets from the input URI.
response = client.import_product_sets(
parent=location_path, input_config=input_config)
print('Processing operation name: {}'.format(response.operation.name))
# synchronous check of operation status
result = response.result()
print('Processing done.')
for i, status in enumerate(result.statuses):
print('Status of processing line {} of the csv: {}'.format(
i, status))
# Check the status of reference image
# `0` is the code for OK in google.rpc.Code.
if status.code == 0:
reference_image = result.reference_images[i]
print(reference_image)
else:
print('Status code not OK: {}'.format(status.message))
我正在寻找 Python API 设计器来修复此处理错误。这是一个错误。
【问题讨论】:
-
我认为 API 块位于:
python # synchronous check of operation status result = response.result() print('Processing done.') -
这个API的当前方式是注释:
python #result = response.result() #print('Processing done.') #for i, status in enumerate(result.statuses): # print('Status of processing line {} of the csv: {}'.format( # i, status)) # Check the status of reference image # `0` is the code for OK in google.rpc.Code. #if status.code == 0: # reference_image = result.reference_images[i] # print(reference_image) # else: # print('Status code not OK: {}'.format(status.message)) -
任何有相同问题的人都可以使用这种方式来解决这个问题。并且您可以使用命令行方法来检查产品集创建状态。
标签: google-cloud-platform google-cloud-vision