i’ve been trying to use roboflow’s api to upload a lot to images and their annotation and i walked through the provided colab notebook to use it
this is the error
{'error': {'message': 'Unsupported get request. Dataset with ID `XXX` does not exist or cannot be loaded due to missing permissions.', 'type': 'GraphMethodException', 'hint': 'You can see your available datasets by issuing a GET request to /datasets'}}
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-10-a855405627e4> in <module>()
38
39
---> 40 img_id = r.json()['id']
41
42 annotation_filename = os.path.splitext(filename)[0]+'.xml'
KeyError: 'id'
and I’ve used this section
import requests
import base64
import io
from PIL import Image
import os
for filename in os.listdir("."):
if filename.endswith(".jpg") or filename.endswith(".png"):
print(filename)
# Load Image with PIL
image = Image.open(filename).convert("RGB")
# Convert to JPEG Buffer
buffered = io.BytesIO()
image.save(buffered, quality=90, format="JPEG")
# Base 64 Encode
img_str = base64.b64encode(buffered.getvalue())
img_str = img_str.decode("ascii")
# Construct the URL
upload_url = "".join([
"https://api.roboflow.com/dataset/XXX/upload",
"?api_key=" + MY_KEY,
"&name=IMG_0159_JPG.rf.15c0119df282796d2a9c90d18f615672.jpg",
"&split=train"
])
# POST to the API
r = requests.post(upload_url, data=img_str, headers={
"Content-Type": "application/x-www-form-urlencoded"
})
# Output result
print(r.json())
img_id = r.json()['id']
annotation_filename = os.path.splitext(filename)[0]+'.xml'
print(annotation_filename)
# Read Annotation as String
annotation_str = open(annotation_filename, "r").read()
# Construct the URL
upload_url = "".join([
"https://api.roboflow.com/dataset/XXX/annotate/" + img_id,
"?api_key=" + MY_KEY,
"&name=", annotation_filename
])
# POST to the API
r = requests.post(upload_url, data=annotation_str, headers={
"Content-Type": "text/plain"
})
# Output result
print(r.json())
Hello @Ruba0 - thank you for the detailed code and error. In order to upload an image to Roboflow via the upload API you need to specify the dataset name where you have XXX and be sure to include you API key in the variable “MY_KEY”, which you may already have done.
Alternatively, you might prefer to use our PIP package to upload your data - where we have wrapped some of these API nuances
Thanks for your quick reply.but when i tried to upload following image from my dataset.It won’t upload properly to the Roboflow project.Then i resized following image into (640,640) and then it worked
Roboflow Package has been used for uploading.so can you take a look at this problem? because in my end Roboflow api will work if images are resized to smaller size.
Thanks Tony!
I’m building an uploader/processor for one of my robots so it can have an image pipeline to push new images up to my project here while its out in the field