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)