如何在谷歌云视觉中获取预测标签的百分比

时间:2019-10-15 11:18:47

标签: python flask google-cloud-platform google-cloud-vision

我已经成功地从google vision API中获取了每个标签的描述,但是我仍然需要获取每个标签的预测百分比,有谁能帮助我

我这样做是为了获得标签的描述

filename = photos.save(request.files['photo'])
file_url = photos.url(filename)
response = client.label_detection(image=image)
labels = response.label_annotations
for label in labels:
    print(label.description)

输出

Hair
Forehead
Chin
White-collar worker
Eyebrow
Hairstyle
Cheek
  

我想得到这样的结果:

Hair 80%
Forehead 10%
Chin 50%
White-collar worker 0%
Eyebrow 5%
Hairstyle 1%
Cheek 20%

1 个答案:

答案 0 :(得分:0)

尝试一下

for label in labels:
    desc, score = label.description, int(label.score * 100)
    print(f"{desc} {score}%")