Python SDK quickstart
On the Segments.ai web platform you can create datasets, upload samples, create releases and download labels. All of these - and more - can also be done programmatically with the Python SDK.
This tutorial walks you through the most common Python SDK functions. The complete list of functions is documented in detail in the Python SDK reference.
First install the Segments.ai Python SDK using pip:
Import the necessary packages, and initialize the Segments client using your API key:
Create a new dataset
Let's create a new image segmentation dataset programmatically using client.add_dataset()
. Note that this dataset will be created under the user account corresponding to the API key.
The format of the task_attributes
field is documented here.
Add samples to a dataset
Now let's upload some images to this dataset using client.add_sample()
.
If the image file is on your local computer, you should first upload it to our asset storage service (using upload_asset()
) or to another cloud storage service.
We can verify that the dataset now contains 3 images using client.get_samples()
.
Now switch to the Segments.ai web platform and label the three images you just uploaded by pressing the "Start labeling" button.
Get the label of a sample
Once you've labeled some samples, you can programmatically retrieve their labels using client.get_label()
.
Optional: visualize the instance and semantic labels
When working with image segmentation datasets, you'll probably want to visualize the image and label at this point. The segments.utils
module offers some helper functions for that:
What's next?
The Python SDK offers many more functions besides the ones that were shown here. Have a look at the reference for the full list.
The Python SDK can also be used to upload labels into Segments.ai. This is particularly useful for setting up model-assisted labeling workflows, where you verify and correct model predictions instead of labeling from scratch.
Last updated