【问题标题】:Cloud Vision Product Search python API for creating a product set resource can't return processing result用于创建产品集资源的 Cloud Vision Product Search python API 无法返回处理结果
【发布时间】: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


【解决方案1】:

ImportProductSets 是一个长时间运行的操作。示例代码会一直阻塞,直到操作完成。这就是代码看起来像卡住的原因。由于它是一种异步方法,因此您可以根据需要设置回调。

您的 csv 文件中有多少行?您可以先尝试使用一个小文件进行测试。

【讨论】:

  • 我的 csv 文件包含 20,000 行,这是 ImportProductSets 的最大值设置。我指出我们的代码看起来卡住的原因是我同时使用 REST API 和 Python API 来做同样的事情。当 REST API 完成构建产品集时,Python API 仍在处理中。我不确定 Python API 在这种情况下是否有效。谢谢@Brendan
猜你喜欢
  • 1970-01-01
  • 2020-04-07
  • 2019-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多