用Python进行Google Cloud Vision大量图像的批处理

4

我是 Python 和云视觉的新手。我需要标记大约 20k 张图像。虽然我的代码可以实现这个功能,但需要很长时间来处理。是否有更高效的方法?非常感谢您的帮助。

filename=[]
description=[]
score=[]
for root, dirs, filenames in os.walk(indir):
    for f in filenames:
        if  f.endswith('.jpg'):
            file_name=indir+'/'+f

            with io.open(file_name, 'rb') as image_file:
                content = image_file.read()
            image = types.Image(content=content)
            response = client.label_detection(image=image)
            labels = response.label_annotations

            for label in labels:
                filename.append(f)
                description.append(label.description)
                score.append(label.score)

import pandas as pd

vision_op = pd.DataFrame(
    {'filename': filename,
     'description': description,
     'score': score
    })

我也想知道。 - Kong
1个回答

1
你可以从多个线程发送请求以加快速度。
由于annotate接受多个AnnotateImageRequests,因此您也可以在单个API调用中发送多个图像。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接