How do i tag 18.5k images for a dataset using Roboflow API and python

Project Type: Classification
Operating System & Browser: Microsoft, Google Chrome

I have 18.5k images to annotate and can’t all do it individually. I found this code to do it but I keep getting this error:

-------- Annotations successfully uploaded: {‘error’: ‘Endpoint not found.’} ----------

I have a CSV file and have made sure everything matches.
For security reasons, I have hidden the actual IDs here.
The only issue seems to be this line:

f"https://api.roboflow.com/dataset/{PROJECT_ID}/annotations?api_key={ROBOFLOW_API_KEY}",

What can I do?


Here is my code:

import csv
import requests

Roboflow API Key and Project Details

ROBOFLOW_API_KEY = “my_actual_id”
WORKSPACE_ID = “my_wksp_id”
PROJECT_ID = “my_proj_id”

Load labels from CSV

labels =
try:
with open(“labels.csv”, “r”) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
labels.append(row)
except FileNotFoundError:
print(“Error: ‘labels.csv’ file not found. Make sure it’s in the same directory as the script.”)
exit()

Debug: Print parsed CSV content

print(“Parsed CSV Content:”)
for label in labels:
print(label)

Check if CSV contains the necessary columns

if not labels or “image_id” not in labels[0] or “category” not in labels[0]:
print(“Error: CSV file must contain ‘image_id’ and ‘category’ columns.”)
exit()

Collect all annotations into a list

annotations =
for label in labels:
# Create annotation entries
annotations.append({
“image_id”: label[“image_id”], # Match your CSV column name
“annotations”: [{“label”: label[“category”]}] # Use ‘category’ instead of ‘label’
})

Debug: Print the payload being sent to the API

print(“Prepared Annotations Payload:”)
print(annotations)

Send annotations in bulk

try:
response = requests.post(
f"https://api.roboflow.com/dataset/{PROJECT_ID}/annotations?api_key={ROBOFLOW_API_KEY}",
json={“annotations”: annotations}
)

# Check the response
if response.status_code == 200:
    print("Annotations successfully uploaded:", response.json())
else:
    print("Failed to upload annotations:")
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.text}")

except requests.exceptions.RequestException as e:
print(“Error: Failed to connect to Roboflow API.”)
print(e)

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