Python SDK

Superb AI Suite SDK Sample

Superb AI Suite SDK is available via Github. Please refer to the following link for more guides and example SDK use-cases: Superb AI Suite Examples SDK
  • Image Basic: Basic SDK Example for Image projects
  • Polygon to Bitmask: Convert exported polygon segmentation result to bitmask
  • Suite-Pachyderm Integration: Suite - Pachyderm import / export examples

Initialization

First, follow the steps in the guide below to install and configure the CLI-SDK package.

Initialize the Suite SDK

Once you're configured, you can initialize the Suite Python SDK as below.
1
import spb.sdk
2
3
# Print Suite SDK version
4
print(spb.sdk.__version__)
Copied!

Initialize the SDK Client to access your project

1
client = spb.sdk.Client(project_name='<Your Project Name>')
2
3
# Print project information
4
print('Project Name: {}'.format(client.get_project_name()))
5
print('Total number of data: {}'.format(client.get_num_data()))
Copied!

Upload An Image to Suite

Upload a local image

1
image_path = '<Local Path to Your Image>'
2
dataset = '<Your Dataset Name>'
3
4
client.upload_image(image_path, dataset)
5
6
# The uploaded image can be seen at the Suite Web UI
Copied!

Upload an image from your Amazon S3 bucket

You need AWS credentials to access your S3 bucket.
1
bucket = '<Your S3 Bucket Name>'
2
image_path = '<Path to your Image in the Bucket>'
3
dataset = '<Your Dataset Name>'
4
5
client.upload_image_s3(bucket, image_path, dataset)
6
7
# The uploaded image can be seen at the Suite Web UI
Copied!

Access Raw Data on Suite

Get a data row from Suite

1
# Generate iterator from selected project
2
data_iter = client.get_data_page(page_idx='<Index of pages>', page_size='<Number of data in page>')
3
data = next(data_iter)
4
5
# Print data information
6
print('Key: {}'.format(data.get_key()))
7
print('Dataset: {}'.format(data.get_dataset_name()))
8
print('Image URL: {}'.format(data.get_image_url()))
9
print('Status: {}'.format(data.get_status()))
Copied!

Read the corresponding image from a data row

1
image = data.get_image()
2
3
# Print image information
4
print('Image type: {}'.format(image.__class__))
5
print('Image dtype: {}'.format(image.dtype))
6
print('Image shape: {}'.format(image.shape))
7
8
# Plot the image
9
import matplotlib.pyplot as plt
10
plt.imshow(image)
Copied!

Download the image file to local storage.

1
download_path, result = data.download_image(download_to='./test.jpg')
2
3
# Print the HTTP response
4
print(result)
5
6
# Plot the downloaded image
7
import PIL.Image
8
image = PIL.Image.open(download_path)
9
plt.imshow(image)
Copied!

Access Raw Data with Filters

Filtering via Dataset

1
dataset = 'MSCOCO_dataset_a'
2
3
# Total number of data in your dataset
4
num_data = client.get_num_data(dataset=dataset)
5
print('Size of "{}" dataset: {}'.format(dataset, num_data))
6
7
# Get data iterator in the dataset
8
data_iter = client.get_data_page(page_idx='<Index of pages>', page_size='<Number of data in page>', dataset=dataset)
9
data = next(data_iter)
Copied!

Filtering via Label Tags

1
tags = ['<Label Tag 1>', '<Label Tag 2>', ...]
2
3
# Number of data containing all the tags
4
num_data = client.get_num_data(tags=tags)
5
print('Number of data containing tags {}: {}'.format(tags, num_data))
6
7
# Get data iterator in the filtered list of data
8
data_iter = client.get_data_page(page_idx='<Index of pages>', page_size='<Number of data in page>', tags=tags)
9
data = next(data_iter)
10
11
# Print tags of the data
12
print('Tags: {}'.format(data.get_tags()))
Copied!

Manage labels on Suite

Get the label information for each data row

1
category_labels = data.get_category_labels()
2
object_labels = data.get_object_labels()
3
4
# Print labels
5
print('category_labels', category_labels)
6
print('object_labels', object_labels)
7
# Example output:
8
# category_labels ['bugatti']
9
# object_labels [
10
# {'id': 1, 'class': 'bugatti',
11
# 'shape': {'box': {'x': 83, 'y': 52, 'width': 819, 'height': 457}},
12
# 'properties': []},
13
# {'id': 2, 'class': ...},
14
# {'id': 3, 'class': ...},
15
# ...
16
# ]
Copied!

Change the label information locally

1
category_labels = ['teslaroadster']
2
object_labels[0]['class'] = 'teslaroadster'
3
4
# Print labels
5
print('category_labels', category_labels)
6
print('object_labels', object_labels)
7
# Example output:
8
# category_labels ['teslaroadster']
9
# object_labels [
10
# {'id': 1, 'class': 'teslaroadster',
11
# 'shape': {'box': {'x': 83, 'y': 52, 'width': 819, 'height': 457}},
12
# 'properties': []},
13
# {'id': 2, 'class': ...},
14
# {'id': 3, 'class': ...},
15
# ...
16
# ]
Copied!

Apply the changes to Suite (update label information)

1
data.set_category_labels(category_labels)
2
data.set_object_labels(object_labels)
3
4
# The change can be seen at the Suite Web UI
Copied!

Verify the update

1
# Get the data row from the Suite
2
data = client.get_data(data_idx=0)
3
4
# Print labels
5
print('category_labels', data.get_category_labels())
6
print('object_labels', data.get_object_labels())
7
# Example output:
8
# Same with the labels at local
Copied!
Any other questions? E-mail us at [email protected].
Last modified 1mo ago