Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the cloud vision api for label detection. #12534

Open
nwaughachukwuma opened this issue Mar 31, 2024 · 1 comment
Open

Using the cloud vision api for label detection. #12534

nwaughachukwuma opened this issue Mar 31, 2024 · 1 comment
Labels
type: question Request for information or clarification. Not an issue.

Comments

@nwaughachukwuma
Copy link

It's not clear how to do label detection with google-cloud-vision. There's a complete mismatch between what's specified in this repository and what's on the docs page. If there's been a breaking change, the docs page should be clear in making it known.

Nothing in the following link works for me - https://cloud.google.com/vision/docs/libraries

Please specify how to perform label detection using cloud vision or what document I should be looking at. Thank you.

@ohmayr
Copy link
Contributor

ohmayr commented Apr 8, 2024

Hi @nwaughachukwuma, thanks for reaching out. I tried the sample provided in the link and it seems to work as expected.

Code:

# Imports the Google Cloud client library
from google.cloud import vision



def run_quickstart() -> vision.EntityAnnotation:
    """Provides a quick start example for Cloud Vision."""

    # Instantiates a client
    client = vision.ImageAnnotatorClient()

    # The URI of the image file to annotate
    file_uri = "gs://cloud-samples-data/vision/label/wakeupcat.jpg"

    image = vision.Image()
    image.source.image_uri = file_uri

    # Performs label detection on the image file
    response = client.label_detection(image=image)
    print("response: ", response)
    labels = response.label_annotations

    print("Labels:")
    for label in labels:
        print(label.description)

    return labels

run_quickstart()

Output:

response:  label_annotations {
  mid: "/m/01yrx"
  description: "Cat"
  score: 0.956459463
  topicality: 0.956459463
}
label_annotations {
  mid: "/m/0d4v4"
  description: "Window"
  score: 0.938840091
  topicality: 0.938840091
}
label_annotations {
  mid: "/m/0307l"
  description: "Felidae"
  score: 0.89566052
  topicality: 0.89566052
}
label_annotations {
  mid: "/m/01lrl"
  description: "Carnivore"
  score: 0.885138333
  topicality: 0.885138333
}
label_annotations {
  mid: "/m/01k9lj"
  description: "Jaw"
  score: 0.880326807
  topicality: 0.880326807
}
label_annotations {
  mid: "/m/07k6w8"
  description: "Small to medium-sized cats"
  score: 0.863107383
  topicality: 0.863107383
}
label_annotations {
  mid: "/m/0244x1"
  description: "Gesture"
  score: 0.852604866
  topicality: 0.852604866
}
label_annotations {
  mid: "/m/01l7qd"
  description: "Whiskers"
  score: 0.84995687
  topicality: 0.84995687
}
label_annotations {
  mid: "/m/031b6r"
  description: "Window blind"
  score: 0.834581673
  topicality: 0.834581673
}
label_annotations {
  mid: "/m/0276krm"
  description: "Fawn"
  score: 0.816135049
  topicality: 0.816135049
}

Labels:
Cat
Window
Felidae
Carnivore
Jaw
Small to medium-sized cats
Gesture
Whiskers
Window blind
Fawn

Feel free to reach out if you have any questions related to the Python client. For any API specific questions, kindly submit feedback on this link.

@parthea parthea added the type: question Request for information or clarification. Not an issue. label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants