python - 使用 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 个,我肯定可以让它更快吗?
解决方案
并行执行更多操作会更快完成。您还可以在单个注释请求中包含多个图像。对于 python,请参见batch_annotate_images方法。
这有一个单个请求的示例。您将使用带有 batch_annotate_images 的请求数组。
如果您只想快速将请求发送到 api 并稍后检索结果,您可以使用asyncBatchAnnotate。
推荐阅读
- python - 您的会话因未知原因而崩溃 - Google Colab
- c - 生成没有参数的主要参数
- c++ - OpenClipboard 因 CLIPBRD_E_CANT_OPEN 崩溃
- css - 在 2 个子根之间应用不同的 css 文件
- windows - 如何从 Qt 中的对话框启动主窗口
- r - 为什么包 stats 中的 scatter.smooth 和包 ggplot2 中的 geom_smooth 会给出不同的结果?
- firebase - Firebase 推送通知权限
- python - SpaCy - 将神经核函数结果拆分成句子
- excel - 无法在 SharePoint 上使用 VBScript 更新 excel 文件
- api - Qliksense 中 JIRA Rest API 的增量负载