Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vision: Add batch processing #2978

Merged

Conversation

daspecster
Copy link
Contributor

I wasn't sure the best way to add the context manager to Batch since there needs to be a result returned. I'm not sure of a good way to do that from a context manager's __exit__ without attaching the results to something.

Closes #2897

@daspecster daspecster added the api: vision Issues related to the Cloud Vision API. label Jan 31, 2017
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 31, 2017
"""Batch multiple images into one request."""


class Batch(object):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

"""
return self._images

def detect(self):

This comment was marked as spam.

This comment was marked as spam.

@@ -30,24 +30,25 @@ def __init__(self, client=None):
self._client = client
self._annotator_client = image_annotator_client.ImageAnnotatorClient()

def annotate(self, image, features):
def annotate(self, images):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@daspecster daspecster mentioned this pull request Jan 31, 2017
10 tasks
*********************

Multiple images can be processed with a single request by passing ``Image``s to
``Client.batch(images)``.

This comment was marked as spam.

>>> batch.add_image(image_one, [face_feature, logo_feature])
>>> batch.add_image(image_two, [logo_feature])
>>> results = batch.detect()
>>> for face in results[0].faces:

This comment was marked as spam.

@@ -507,3 +509,53 @@ def test_detect_properties_filename(self):
image = client.image(filename=FACE_FILE)
properties = image.detect_properties()
self._assert_properties(properties)


class TestVisionBatchProcessing(BaseVisionTestCase):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -30,24 +30,25 @@ def __init__(self, client=None):
self._client = client
self._annotator_client = image_annotator_client.ImageAnnotatorClient()

def annotate(self, image, features):
def annotate(self, images):

This comment was marked as spam.

"""Batch multiple images into one request."""


class Batch(object):

This comment was marked as spam.

@@ -71,6 +72,14 @@ def __init__(self, project=None, credentials=None, http=None,
else:
self._use_gax = use_gax

def batch(self):
"""Batch image processing.

This comment was marked as spam.

@daspecster
Copy link
Contributor Author

I just wanted to check. I think everything was addressed here?

@lukesneeringer
Copy link
Contributor

lukesneeringer commented Feb 9, 2017

I would still like to understand why annotate's signature changed, but everything else seems good.

@daspecster
Copy link
Contributor Author

@lukesneeringer annotate isn't meant to be used directly. It should probably be named _annotate in hindsight. detect() is the documented method that calls annotate().

That said, the signature change is required because multiple images need to be passed to _vision_api.annotate() in order to build the requests.

You build multiple Request objects and send them as a list and sending them as one request rather than making a request for each image.

Alternatively I could have duplicated the annotate() methods in _http.py and _gax.py and made the changes to handle multiple requests there, but there would have been a decent amount of duplicated code.

@lukesneeringer
Copy link
Contributor

Okay, that is fine.

@daspecster
Copy link
Contributor Author

Ok, I'll merge this in an hour or two. There's some other vision work that I want to get closer to finished before I rebase this into it.

@daspecster daspecster merged commit db0dc85 into googleapis:master Feb 9, 2017
@daspecster daspecster deleted the vision-batch-processing-part-2 branch February 9, 2017 17:20
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
* Add Vision batch support to the surface.
parthea pushed a commit that referenced this pull request Oct 21, 2023
* Add Vision batch support to the surface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vision Issues related to the Cloud Vision API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants