我已经成功地从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%
答案 0 :(得分:0)
尝试一下
for label in labels:
desc, score = label.description, int(label.score * 100)
print(f"{desc} {score}%")