1

在使用命令行搜索 product_set 时,我们可以设置参数features.max Results来限制响应中返回的项目数。

Field-specific considerations:

features.maxResults - The maximum number of results to be returned.

但是如何在运行此处提供的 python 脚本时传递此参数?

另外,这个参数会影响响应时间吗?

4

1 回答 1

1

文档确实写得不是很好,但是我发现您只需max_results=<max>在方法中添加参数product_search,如下所示:

response = image_annotator_client.product_search(
        image, image_context=image_context,max_results=2)

为了确认它有效,我在 google 库的文件中添加了一个调试行/usr/local/lib/python3.7/dist-packages/google/cloud/vision_helpers/decorators.py

当我运行代码时,我得到了对 api 的请求的打印输出,如您所见,参数定义正确:

# python3 search.py 

结果:

#BEGIN DEBUG:
{'image': source {
  image_uri: "gs://<bucket>/short-blue.jpeg"
}
, 'features': [{'type_': <Type.PRODUCT_SEARCH: 12>, 'max_results': 2}], 'image_context': product_search_params {
  product_set: "projects/<project>/locations/us-west1/productSets/product-set-name"
  product_categories: "apparel-v2"
  filter: "color:blue"
}
}
#END DEBUG:

Product set index time: 
None
Search results:
于 2021-10-27T15:34:47.890 回答