How to Access Classes defined by Annotation tool from Python?

How to access Roboflow Class labels created within the Annotation tool, say, with Python?

Hi @Francis_Bacon

The Roboflow API returns a class property for the project API endpoint. Is that what you’re looking for?

Example based on the documentation:

{
    "workspace": {
        ...
    },
    "project": {
        ...
        "classes": {
            "class-one": 7,
            "class-two": 8,
            ...
        },
        ...
    }
}

This is a bit abstract…can you provide or point me to s snippet of Python code?

Hi @Francis_Bacon

The Python SDK tab of the previously linked docs page has information on how to initialize the project object:

import roboflow

rf = roboflow.Roboflow(api_key=YOUR_API_KEY_HERE)

# List all projects for your workspace
workspace = rf.workspace()

# get a project
project = rf.workspace().project("PROJECT_ID")

You can see the classes of the project by accessing the classes property of the project object:

print(project.classes)

This returns a object with:

{'*class name*': # of images w/ class }

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.