Skip to content

Define Image Classes#

After you’ve created a project, create classes in that project. These classes represent the categories your images can be assigned to. We will use the LandingLens API to define these classes.

Payload Format#

The request payload for defining classes has a specific format provided by LandingLens:

{
  "0": {
    "name": "clean",
  },
  "1": {
    "name": "contaminated",
  }
}

Important: You cannot modify this payload structure. Each class name must be paired with a numerical key (like "0" and "1" in this example). While these keys might seem like class IDs, it's essential to remember that you cannot change or delete them once they are defined.

Request Execution and Restrictions#

Learn about the following LandingLens class conventions before creating classes:

  • Immutable classes: You cannot delete individual classes after they are created. If you need to change a class, you might need to redefine the entire class set.
  • Label consistency: When uploading images, the labels you assign must strictly adhere to the established classes and their corresponding numerical keys. Uploading images with labels outside this set will not be possible.
  • Label indexes: For Classification projects the index values start at 0. For Object Detection and Segmentation projects the index values start at 1 (index value of 0 is reserved). Finally, for Segmentation projects the range of allowed indexes are from 1 to 254.
  • Reserved class names: For Object Detection and Segmentation projects the "ok" class name is reserved, so please make sure that you do not use it when defining your classes.
  • Unique class names: All class names in a project should be unique.

Example Code: Define Classes#

The following code defines these two classes: clean and contaminated.

import requests

# Replace "YOUR_API_KEY" and "YOUR_PROJECT_ID" with the actual values
api_key = "YOUR_API_KEY"
project_id = "YOUR_PROJECT_ID"

# Define the class creation endpoint
url = f"https://api.landing.ai/v1/projects/{project_id}/classes"

# Set the authorization header
headers = {"apikey": api_key}

# Define class labels (ensure they align with the provided format)
classes = {"0": {"name": "clean"},"1": {"name": "contaminated"}}


# Prepare the payload (adheres to the required format)
data = classes

response = requests.post(url, headers=headers, json=data)

if response.status_code == 201:
    print("Classes created successfully!")
    print("**Remember:** These classes cannot be modified individually after creation.")
else:
    print(f"Error creating classes: {response.text}")

Next Steps#

Then, go to the next step: Uploading Images.