Async Batch Google Vision Text detection

Viewed 311

i'm trying to use google vision to detect text from a batch of 15 documents at once, i want it to be don't Asynchronously.

unfortunately the time it takes for client.async_batch_annotate_images() function, is the same as client.batch_annotate_images() function, which is the same time it takes if i iterate over the list of features with client.document_text_detection()

i am not sure why the response takes so much time, and maybe i am doing something wrong, i would love to get your expert opinion on this.

for example, that is how i extract the text using batch annotate images

        def batch_ocr_images():

            client = vision.ImageAnnotatorClient()

            requests = []
            features = [vision.Feature(type_=vision.Feature.Type.DOCUMENT_TEXT_DETECTION)]
            for image_file in images_files:
                with io.open(image_file, 'rb') as image_data:
                    content = image_data.read()

                image = vision.Image(content=content)
                request = vision.AnnotateImageRequest(image=image, features=features)
                requests.append(request)


            client.batch_annotate_images(requests=requests)



is this how it should work asynchronously? because it works the same speed as it does when i iterate over the images and scan one image at a time.

thanks in advance, Yaniv

1 Answers

Speed is expected to be the same as the speed configuration is on the back-end of Google. There’s no option to speed up on user/developer's end. The only difference between asynchronous and synchronous is you can do requests even offline when you are using asynchronous and you can specify larger batches of files compared to using synchronous. To read more about batch image annotation you may refer to this GCP Documentation.

Related