Search code examples
google-cloud-platformgoogle-cloud-visiongoogle-apis-explorer

How to get the confidence scores for the Google Cloud Vision API logo detection?


How can I find the probability or likelihood (confidence score) for the logo detection method of Google Vision API?

I have an image that gives these for the logo while none are correct. I want to use a threshold for it in terms of confidence score.

Logos:
Sogndal Fotball
Tequila Herradura

code:

# Performs logo detection on the image file
response_logo = client.logo_detection(image=image)
logos = response_logo.logo_annotations
print('Logos:')

for logo in logos:
    print(logo.description)

if response_logo.error.message:
    raise Exception(
        '{}\nFor more info on error messages, check: '
        'https://cloud.google.com/apis/design/errors'.format(
            response_logo.error.message))

Solution

  • # Performs logo detection on the image file
    response_logo = client.logo_detection(image=image)
    logos = response_logo.logo_annotations
    print('Logos:')
    
    logos_dict = {}
    for logo in logos:
        print(logo.description)
        print('logo type: ', type(logo))
        print(logo)
        logos_dict.update({'logo': logo.description,
                           'logo_score': logo.score})
    
    print(logos_dict)