Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Issue in migrating to google-cloud-vision 2.0 #58

Closed
murtuzamdahod opened this issue Oct 5, 2020 · 4 comments
Closed

Issue in migrating to google-cloud-vision 2.0 #58

murtuzamdahod opened this issue Oct 5, 2020 · 4 comments
Assignees
Labels
api: vision Issues related to the googleapis/python-vision API. status: investigating The issue is under investigation, which is determined to be non-trivial.

Comments

@murtuzamdahod
Copy link

Hello,
Greetings for the day.

I am trying to run this code with google-cloud-vision 2.0 but it gives me error. This code worked well with previous versions.

from google.cloud import vision_v1p4beta1 as vision
from google.oauth2 import service_account
import io

client = vision.ImageAnnotatorClient(credentials=credentials)


with io.open("temp.jpg", 'rb') as image_file:
    content = image_file.read()

image = vision.Image(content=content)
image_context = vision.ImageContext(language_hints=["en"])

response = client.annotate_image({'image': image,
                                  'image_context': image_context,
                                  'features': [{'type': vision.Feature.Type.DOCUMENT_TEXT_DETECTION, 'model': 'builtin/legacy_20190601'}], })

Error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-a12bdee22ec3> in <module>
     27 image_context = vision.ImageContext(language_hints=["en"])
     28 
---> 29 response = client.annotate_image({'image': image,
     30                                   'image_context': image_context,
     31                                   'features': [{'type': vision.Feature.Type.DOCUMENT_TEXT_DETECTION, 'model': 'builtin/legacy_20190601'}], })

~/miniconda3/envs/idp3/lib/python3.8/site-packages/google/cloud/vision_helpers/__init__.py in annotate_image(self, request, retry, timeout, metadata)
     74         elif len(request.features) == 0:
     75             request.features = self._get_all_features()
---> 76         r = self.batch_annotate_images(
     77             requests=[request], retry=retry, timeout=timeout, metadata=metadata
     78         )

~/miniconda3/envs/idp3/lib/python3.8/site-packages/google/cloud/vision_v1p4beta1/services/image_annotator/client.py in batch_annotate_images(self, request, requests, retry, timeout, metadata)
    306             if requests is not None:
    307                 for i in range(len(requests)):
--> 308                     requests[i] = image_annotator.AnnotateImageRequest(requests[i])
    309 
    310             # If we have keyword arguments corresponding to fields on the

~/miniconda3/envs/idp3/lib/python3.8/site-packages/proto/message.py in __init__(self, mapping, **kwargs)
    424         for key, value in mapping.items():
    425             pb_type = self._meta.fields[key].pb_type
--> 426             pb_value = marshal.to_proto(pb_type, value)
    427             if pb_value is not None:
    428                 params[key] = pb_value

~/miniconda3/envs/idp3/lib/python3.8/site-packages/proto/marshal/marshal.py in to_proto(self, proto_type, value, strict)
    184             # Convert lists and tuples recursively.
    185             if isinstance(value, (list, tuple)):
--> 186                 return type(value)(self.to_proto(proto_type, i) for i in value)
    187 
    188         # Convert dictionaries recursively when the proto type is a map.

~/miniconda3/envs/idp3/lib/python3.8/site-packages/proto/marshal/marshal.py in <genexpr>(.0)
    184             # Convert lists and tuples recursively.
    185             if isinstance(value, (list, tuple)):
--> 186                 return type(value)(self.to_proto(proto_type, i) for i in value)
    187 
    188         # Convert dictionaries recursively when the proto type is a map.

~/miniconda3/envs/idp3/lib/python3.8/site-packages/proto/marshal/marshal.py in to_proto(self, proto_type, value, strict)
    203         # Convert ordinary values.
    204         rule = self._rules.get(proto_type, self._noop)
--> 205         pb_value = rule.to_proto(value)
    206 
    207         # Sanity check: If we are in strict mode, did we get the value we want?

~/miniconda3/envs/idp3/lib/python3.8/site-packages/proto/marshal/rules/message.py in to_proto(self, value)
     30             return self._wrapper.pb(value)
     31         if isinstance(value, dict) and not self.is_map:
---> 32             return self._descriptor(**value)
     33         return value
     34 

ValueError: Protocol message Feature has no "type" field.

Please kindly help me in resolving this issue.

@product-auto-label product-auto-label bot added the api: vision Issues related to the googleapis/python-vision API. label Oct 5, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Oct 6, 2020
@munkhuushmgl munkhuushmgl self-assigned this Oct 12, 2020
@munkhuushmgl munkhuushmgl added status: investigating The issue is under investigation, which is determined to be non-trivial. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Oct 12, 2020
@alexcombessie
Copy link

Hi @munkhuushmgl,

I am going through the same unexpected migration issues 😞 I managed to overcome the particular issue you're having by renaming type into type_.

However, beware that I seem to have uncovered a bug with the protobuf deserialization to JSON/Dict introduced by the 2.0.0 release (see #64).

Best regards,

Alex

@munkhuushmgl
Copy link
Contributor

@alexcombessie Thanks for insight

@munkhuushmgl
Copy link
Contributor

munkhuushmgl commented Oct 14, 2020

@murtuzamdahod Did you solve the issue by changing type into type_?

@munkhuushmgl
Copy link
Contributor

Im closing this issue, feel free to reopen

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: vision Issues related to the googleapis/python-vision API. status: investigating The issue is under investigation, which is determined to be non-trivial.
Projects
None yet
Development

No branches or pull requests

4 participants