Python SDK

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.

import spb.sdk
# Print Suite SDK version
print(spb.sdk.__version__)

Initialize the SDK Client to access your project

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

Upload Image to Suite

Upload local image

image_path = '<Local Path to Your Image>'
dataset = '<Your Dataset Name>'
client.upload_image(image_path, dataset)
# The uploaded image can be seen at the Suite Web UI

Upload image at Amazon S3 bucket

You need AWS credentials to access your S3 bucket.

bucket = '<Your S3 Bucket Name>'
image_path = '<Path to your Image in the Bucket>'
dataset = '<Your Dataset Name>'
client.upload_image_s3(bucket, image_path, dataset)
# The uploaded image can be seen at the Suite Web UI

Access Raw Data on Suite

Get a data row from Suite

data = client.get_data(data_idx=0)
# Print data information
print('Key: {}'.format(data.get_key()))
print('Dataset: {}'.format(data.get_dataset_name()))
print('Image URL: {}'.format(data.get_image_url()))
print('Status: {}'.format(data.get_status()))

Read the corresponding image from a data row

image = data.get_numpy_image()
# Print image information
print('Image type: {}'.format(image.__class__))
print('Image dtype: {}'.format(image.dtype))
print('Image shape: {}'.format(image.shape))
# Plot the image
import matplotlib.pyplot as plt
plt.imshow(image)

Download the image file to local storage.

download_path, result = data.download_image(download_to='./test.jpg')
# Print the HTTP response
print(result)
# Plot the downloaded image
import PIL.Image
image = PIL.Image.open(download_path)
plt.imshow(image)

Access Raw Data with Filters

Filtering via Dataset

dataset = '<Your Dataset Name>'
# Total number of data in your dataset
num_data = client.get_num_data(dataset=dataset)
print('Size of "{}" dataset: {}'.format(dataset, num_data))
# Get 0-th data in the dataset
data = client.get_data(data_idx=0, dataset=dataset)

Filtering via Label Tags

tags = ['<Label Tag 1>', '<Label Tag 2>', ...]
# Number of data containing all the tags
num_data = client.get_num_data(tags=tags)
print('Number of data containing tags {}: {}'.format(tags, num_data))
# Get 0-th data in the filtered list of data
data = client.get_data(data_idx=0, tags=tags)
# Print tags of the data
print('Tags: {}'.format(data.get_tags()))

Manage labels on Suite

Get the label information for each data row

category_labels = data.get_category_labels()
object_labels = data.get_object_labels()
# Print labels
print('category_labels', category_labels)
print('object_labels', object_labels)
# Example output:
# category_labels ['bugatti']
# object_labels [
# {'id': 1, 'class': 'bugatti',
# 'shape': {'box': {'x': 83, 'y': 52, 'width': 819, 'height': 457}},
# 'properties': []},
# {'id': 2, 'class': ...},
# {'id': 3, 'class': ...},
# ...
# ]

Change the label information locally

category_labels = ['teslaroadster']
object_labels[0]['class'] = 'teslaroadster'
# Print labels
print('category_labels', category_labels)
print('object_labels', object_labels)
# Example output:
# category_labels ['teslaroadster']
# object_labels [
# {'id': 1, 'class': 'teslaroadster',
# 'shape': {'box': {'x': 83, 'y': 52, 'width': 819, 'height': 457}},
# 'properties': []},
# {'id': 2, 'class': ...},
# {'id': 3, 'class': ...},
# ...
# ]

Apply the changes to Suite (update label information)

data.set_category_labels(category_labels)
data.set_object_labels(object_labels)
# The change can be seen at the Suite Web UI

Verify the update

# Get the data row from the Suite
data = client.get_data(data_idx=0)
# Print labels
print('category_labels', data.get_category_labels())
print('object_labels', data.get_object_labels())
# Example output:
# Same with the labels at local

Any other questions? E-mail us at support@superb-ai.com.