Hello! I have been trying to upload a annotation via API lately, but it always return that the annotation format is unsupported, even if i upload a exported annotation from existing images.
Are there more guidelines then what is written in the guide page?
Welcome to the forum! Sorry to hear youâre having issues with the annotate API.
We donât yet have more documentation for this beyond the annotate via api docs but Iâm happy to help. Could you share more info about the API request (ideally a code snippet) and the annotation format youâre uploading?
If you could send me an example image & annotation Iâd be happy to test on my side; itâs possible youâre encountering a bug but without more info itâs hard to say.
Once we figure things out weâll be sure to update the docs to help future readers avoid this problem!
upload_url = "".join([
f"https://api.roboflow.com/dataset/{datasetname}/annotate/{pic_id}",
"?api_key=mykey",
"&name=", f"6.xml"
])
# POST to the API
r = requests.post(upload_url, data=annotation_str, headers={
"Content-Type": "text/plaintext"
})
# Output result
return r.json()
def _uploadimg(img,picname, datasetname=âmydbâ):
image = img
if not isinstance(img,Image.Image):
# Load Image with PIL
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
image = Image.fromarray(img)
# 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([
f"https://api.roboflow.com/dataset/{datasetname}/upload",
"?api_key=mykey",
f"&name={picname}",
"&split=train"
])
# POST to the API
r = requests.post(upload_url, data=img_str, headers={
"Content-Type": "application/x-www-form-urlencoded"
})
return json.loads(r.content).get('id',None)
def test():
im = PIL.Image.open(âimages_png.rf.7c0985eb122fe55a1b9b030f551eb211.jpgâ)
picid = _uploadimg(im,âtest.jpgâ,âmydbâ)
ano = open(âimages_png.rf.7c0985eb122fe55a1b9b030f551eb211.xmlâ,ârâ).read()
annotation = _uploadannotation(ano,picid,âimages_png.rf.7c0985eb122fe55a1b9b030f551eb211.jpgâ,âmydbâ)
pass
Could you retry with the Content-Type header as text/plain instead of text/xml? I believe we use the name= query param to infer the type vs the Content-Type; it might be confusing our body parser.
Many thanks! , I hope this issue can be reproduced easily, if any additional information is necessary or the result cannot be reproduced, I will write a full standalone code to ensure the reproducibility of the issue
I tested some more variation on the uploading process and it turns out, if i use the filename â6.xmlâ or â6.txtâ. Then the upload of anotation will fail, but with something such as âtest.xmlâ or âtest.txtâ it works correctly, for now.
Iâm unsure if I just missed it completely or it was working a few days ago, but by modifying the code snippet above from â6.xmlâ to âtest.xmlâ solved my issue, the âtext/plaintextâ or âtext/xmlâ doesnât affect the calls as for now.
After some more testing, I found out it is due to the mismatch between the uploaded images name and the annotation name.
In the test script i posted earlier, I uploaded the image under âtest.jpgâ and annotation under âtest.txtâ, which is why it doesnât produce an error.
The error Iâm receiving under mismatched name is as follows: