首页 > 解决方案 > 使用 Python 在 10,000 多张图像上使用 Vision API 的最快方法

问题描述

我似乎无法在 python 中找到一种在速度方面可以与 DarkNet 竞争的方法。人们会认为会有图像的内置网络处理。我目前正在做的是:

from tqdm import tqdm
from joblib import Parallel, delayed
from google.cloud import vision, firestore


def detect_faces_uri(uri):
    client = vision.ImageAnnotatorClient()
    image = vision.types.Image()
    image.source.image_uri = uri

    response = client.face_detection(image=image)
    faces = response.face_annotations

    if faces:
        print('found face!')
        return uri

list_of_uris = ['gs://example/image.png'*...] # * 10,000+

detected_images = Parallel(n_jobs=12)(delayed(detect_faces_uri)(url) for url in tqdm(list_of_uris))

我一次处理大约 4 - 10 个,我肯定可以让它更快吗?

标签: pythongoogle-cloud-platformgoogle-vision

解决方案


并行执行更多操作会更快完成。您还可以在单​​个注释请求中包含多个图像。对于 python,请参见batch_annotate_images方法。

有一个单个请求的示例。您将使用带有 batch_annotate_images 的请求数组。

如果您只想快速将请求发送到 api 并稍后检索结果,您可以使用asyncBatchAnnotate


推荐阅读