Skip to content

Adding batch image processing to Vision API #2897

Closed

Description

@daspecster

The amount of data that Vision can return can be pretty deep and processing more than one image at a time adds another level to that.

Here's my proposed approach to work with multiple images with multiple feature types.

        >>> images = client.batch()
        >>> for i in range(10):
        ...     images.add_image(client.image(source_uri='gs://%s.jpg' % (i,)))
        >>> images.detect_faces()
        {'0.jpg': [], '1.jpg': [],}
        >>>
        >>> # With multiple feature types.
        >>> features = [Feature(FeatureTypes.FACE_DETECTION, 5),
        ...             Feature(FeatureTypes.LOGO_DETECTION, 3)]
        >>> for i in range(10):
        ...     image = client.image(source_uri='gs://%s.jpg' % (i,))
        ...     images.add_image(image=image, features=features)
        >>> images.detect()

With a context manager it could look something like this...

        >>> features = [Feature(FeatureTypes.FACE_DETECTION, 5),
        ...             Feature(FeatureTypes.LOGO_DETECTION, 3)]
        >>> with client.images() as images:
        ...     for i in range(10):
        ...         image = client.image(source_uri='gs://%s.jpg' % (i,))
        ...         images.add_image(image=image, features=features)
        ...     results = images.detect()

Activity

  1. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    api: visionIssues related to the Cloud Vision API.
    on Dec 21, 2016
  2. dhermes commented on Dec 28, 2016

    @dhermes
    Contributor

    So client.images() is like a batch? Why not name it as such? What is the equivalent backend method that you'd be using? (Or would you just be sending N requests?)

  3. daspecster commented on Dec 28, 2016

    @daspecster
    ContributorAuthor

    It will actually be one request with N vision request objects, so I could change it to batch().

    The GAPIC method is called batch_annotate_images.

  4. dhermes commented on Dec 28, 2016

    @dhermes
    Contributor

    SGTM. As for the interface of the batch, you should check out the datastore batch / accompanying docs. It commits on __exit__, but we also document an explicit public interface people can use to add mutations to the batch and to manually commit or rollback the batch (rollback is datastore transaction specific).

  5. tseaver commented on Dec 28, 2016

    @tseaver
    Contributor

    I definitely like having the context manager be "sugar" over an explicit imperative surface.

  6. removed their assignment
    on Jan 30, 2017
  7. bw4sz commented on Jun 16, 2017

    @bw4sz

    Is there a benefit to running batch if we are asking for the same feature. Would I expect performance increase by running batch versus looping through N requests?

  8. daspecster commented on Jun 16, 2017

    @daspecster
    ContributorAuthor

    @bw4sz yes, batching only makes one large request rather than multiple smaller requests, so it should be faster.

    See: https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.ImageAnnotator.BatchAnnotateImages

  9. bw4sz commented on Jun 17, 2017

    @bw4sz
  10. daspecster commented on Jun 19, 2017

    @daspecster
    ContributorAuthor

    It looks like the max number of images per request(which may be a soft limit?) is 16.

    @lukesneeringer could probably confirm this for you though.

  11. cbg44 commented on Mar 30, 2019

    @cbg44

    the limit is 100 per request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: visionIssues related to the Cloud Vision API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions