get_similar_product_file get product from different product-set
having one project_id, in location = 'us-east1' and different project-set. When I do a product_search I get result from different project-set while I have specified a single project-set.
Environment details
- Python version: Python 3.6.13
- pip version: pip 21.3.1
-
google-cloud-visionversion: `2.6.2
Steps to reproduce
- make few product-set
- make a research
Code example
def get_similar_products_file( project_id, location, product_set_id, product_category, file_path, filter, max_results ): """Search similar products to image. Args: project_id: Id of the project. location: A compute region name. product_set_id: Id of the product set. product_category: Category of the product. file_path: Local file path of the image to be searched. filter: Condition to be applied on the labels. Example for filter: (color = red OR color = blue) AND style = kids It will search on all products with the following labels: color:red AND style:kids color:blue AND style:kids max_results: The maximum number of results (matches) to return. If omitted, all results are returned. """ # product_search_client is needed only for its helper methods. product_search_client = vision.ProductSearchClient() image_annotator_client = vision.ImageAnnotatorClient()
# Read the image as a stream of bytes.
with open(file_path, 'rb') as image_file:
content = image_file.read()
# Create annotate image request along with product search feature.
image = vision.Image(content=content)
# product search specific parameters
product_set_path = product_search_client.product_set_path(
project=project_id, location=location,
product_set=product_set_id)
product_search_params = vision.ProductSearchParams(
product_set=product_set_path,
product_categories=[product_category],
filter=filter)
image_context = vision.ImageContext(
product_search_params=product_search_params)
# Search products similar to the image.
response = image_annotator_client.product_search(
image,
image_context=image_context,
max_results=max_results
)
results = response.product_search_results.results
index_time = response.product_search_results.index_time
print('Product set index time: ')
print(index_time)
print('Search results:')
for result in results:
product = result.product
print('Score(Confidence): {}'.format(result.score))
print('Image name: {}'.format(result.image))
print('Product name: {}'.format(product.name))
print('Product display name: {}'.format(
product.display_name))
print('Product description: {}\n'.format(product.description))
print('Product labels: {}\n'.format(product.product_labels))
return results
Stack trace
Product set index time: 2021-12-30 08:54:26.706854+00:00 Search results: Score(Confidence): 0.7713396549224854 Image name: projects/visual-search-331409/locations/us-east1/products/121/referenceImages/71C2yF+l7pL Product name: projects/visual-search-331409/locations/us-east1/products/121 Product display name: PETZL Aquila Cintura Addominale Product description:
Product labels: [key: "asin" value: "B07949QTGL" , key: "asin" value: "B0794CMMV2" , key: "asin" value: "B0794FR8TV" , key: "asin" value: "B0794BSD5V" ]
Score(Confidence): 0.720783531665802 Image name: projects/visual-search-331409/locations/us-east1/products/748/referenceImages/41J7Olo2MFL Product name: projects/visual-search-331409/locations/us-east1/products/748 Product display name: adidas RS Hoodie W_ Product description:
Product labels: [key: "asin" value: "B01N3OZO0P" , key: "asin" value: "B01MRGXBBV" ]
Score(Confidence): 0.720783531665802 Image name: projects/visual-search-331409/locations/us-east1/products/747/referenceImages/41J7Olo2MFL Product name: projects/visual-search-331409/locations/us-east1/products/747 Product display name: adidas - MOD. YG Product description:
Product labels: [key: "asin" value: "B01NBMX3P1" ]
Score(Confidence): 0.4772458076477051 Image name: projects/visual-search-331409/locations/us-east1/products/1462/referenceImages/51zxs8BvtML Product name: projects/visual-search-331409/locations/us-east1/products/1462 Product display name: Mizuno WAVE SKY 2_ Product description:
Product labels: [key: "asin" value: "B07F34VJL6" ]
Score(Confidence): 0.4547160565853119 Image name: projects/visual-search-331409/locations/us-east1/products/1524/referenceImages/61FofTixQUL Product name: projects/visual-search-331409/locations/us-east1/products/1524 Product display name: 1524 Product description:
Product labels: []
I'm going to transfer this issue to google-cloud-python as we're planning to move the code for google-cloud-vision there in the next 1-2 weeks