Upload an Image
You can upload images to Roboflow projects using the web interface, Python SDK, REST API, and CLI.
Upload to an Existing Project
from roboflow import Roboflow
# Initialize the Roboflow object with your API key
rf = Roboflow(api_key="YOUR_PRIVATE_API_KEY")
# Retrieve your current workspace and project name
print(rf.workspace())
# Specify the project for upload
# let's you have a project at https://app.roboflow.com/my-workspace/my-project
workspaceId = 'my-workspace'
projectId = 'my-project'
project = rf.workspace(workspaceId).project(projectId)
# Upload the image to your project
project.upload("UPLOAD_IMAGE.jpg")
"""
Optional Parameters:
- num_retry_uploads: Number of retries for uploading the image in case of failure.
- batch_name: Upload the image to a specific batch.
- split: Upload the image to a specific split.
- tag: Store metadata as a tag on the image.
- sequence_number: [Optional] If you want to keep the order of your images in the dataset, pass sequence_number and sequence_size..
- sequence_size: [Optional] The total number of images in the sequence. Defaults to 100,000 if not set.
"""
project.upload(
image_path="UPLOAD_IMAGE.jpg",
batch_name="YOUR_BATCH_NAME",
split="train",
num_retry_uploads=3,
tag_names=["YOUR_TAG_NAME"],
sequence_number=99,
sequence_size=100
)Upload to a New Project
To upload a new project, add the following code before your model upload:
CLI upload is especially useful if you have a large number of images (i.e. 1,000+) that you want to upload to Roboflow.
Upload a Single Image
To upload a single file, use the following command:
This will ask you which of your projects to upload into, but you can also skip that by specifying it explicitly using the -p option to the command.
Upload an Image and Annotation
If you have annotations for your image such as a file called image.xml:
Upload all Images
To upload all images in a folder, use the following command:
Upload all Images and Annotations
If you have many images with annotations, you can pass a special “[filename]” value to the -a option that will match the annotation file name based on the name of the image. This would upload image1.jpg with annotations from image1.xml, and image2.jpg with annotations from image2.xml, etc
This only works if you have one annotation file for each image. If you have an entire dataset in a common format, like one downloaded from Roboflow Universe, you can also use the import command.
Upload a Dataset
To upload a full dataset, refer to the Upload Dataset documentation.
Parameters
Querystring parameters accepted by the API:
api_key: Obtain from https://app.roboflow.com/account/api image: [Optional] URL of the image to add. Use if your image is hosted elsewhere (Required when you don't POST a base64 encoded image in the request body). name: [Optional] The filename of the image (if not set, we will try to infer it). batch: [Optional] Group images under a batch with this name tag: [Optional] Can be specified multiple times. Add tags to uploaded image. split: [Optional] One of: train, valid, or test (defaults to train). sequence_number: [Optional] If you want to keep the order of your images in the dataset, you can uploaded images increasing sequence numbers. sequence_size: [Optional] The total number of images in the sequence. Defaults to 100,000 if not set. inference_id: [Optional] The inference ID passed returned from a roboflow inference detection. This inference_id allows the image to be correlated with a roboflow detection in Model Monitoring (enterprise feature).
Linux or macOS
Uploading a local file called YOUR_IMAGE.jpg using multipart/form-data (recommended):
Alternatively, uploading a base64 encoded image:
Uploading an image hosted on the web via its URL (don't forget to URL encode it):
Windows
You will need to install curl for Windows and GNU's base64 tool for Windows. The easiest way to do this is to use the git for Windows installer which also includes the curl and base64 command line tools when you select "Use Git and optional Unix tools from the Command Prompt" during installation.
Then you can use the same commands as above.
Node.js
We're using axios and form-data to perform the POST request in this example so first run npm install axios form-data to install the dependency.
Uploading with multipart/form-data (recommended):
Uploading with base64 encoded image (not recommended):
Adding an Image Hosted Elsewhere via URL
Web
We are currently beta testing roboflow.js, a browser-based JavaScript library which, among other things, includes safe client-side uploads without exposing your secret API Key to the web. If you'd like early access, please contact us.
View Uploaded Images in Roboflow
Images uploaded via the API can be found in the Annotate tab, under the unassigned column and marked as uploaded via API.
If you specify a batch upload parameter, your image will still be found in the Annotate tab but instead of going to the uploaded via API batch it will be found in the batch you specified.
Was this helpful?