Upload an Annotation
If you already have existing annotations, along with your images, you can upload them to Roboflow.
This works with any of our supported annotation formats that use an annotation file that references the file name of the uploaded image.
You can attach annotation files when you upload images via the Python SDK. See more in the Python SDK reference
Example: Uploading a Local Annotation
import glob
from roboflow import Roboflow
# Initialize Roboflow client
rf = Roboflow(api_key="YOUR_PRIVATE_API_KEY")
# Directory path and file extension for images
dir_name = "PATH/TO/IMAGES"
file_extension_type = ".jpg"
# Annotation file path and format (e.g., .coco.json)
annotation_filename = "PATH/TO/_annotations.coco.json"
# Get the upload project from Roboflow workspace
project = rf.workspace().project("YOUR_PROJECT_NAME")
# Upload images
image_glob = glob.glob(dir_name + '/*' + file_extension_type)
for image_path in image_glob:
print(project.single_upload(
image_path=image_path,
annotation_path=annotation_filename,
# -- optional parameters: --
# annotation_labelmap=labelmap_path,
# split='train',
# num_retry_uploads=0,
# batch_name='batch_name',
# tag_names=['tag1', 'tag2'],
# is_prediction=False,
))
Example
Attaching a VOC XML annotation to an image with ID abc123 in the your-dataset dataset called YOUR_ANNOTATION.xml:
Attaching a Darknet TXT annotation to an image with ID abc123 in the your-dataset dataset called YOUR_ANNOTATION.txt using a json labelmap - in this case we need to send the contents of the annotation file in a json instead of just sending it as the body.
We're using axios to perform the POST request in this example so first run npm install axios to install the dependency.
Uploading a Local Image
Was this helpful?