Skip to content

Code Examples

Python Examples

Uploading Images to a Dataset

from innotescus import client_factory, DataType, AnnotationFormat, TaskType, ExportType, JobStatus, ResponseCode, StorageType

# Create an authenticated instance of the Innotescus API Client
client = client_factory('api_client_id', 'api_client_secret')

# Upload these files to the specified project and dataset name
#if this dataset name does not exist in this project, it will be created
response = client.upload_data(project_name = "test project", 
                              dataset_name = "test dataset", 
                              file_paths =[
                                        "/path/to/image_1.png",
                                        "/path/to/image_2.png",
                                        "/path/to/image_3.png",
                                        "/path/to/image_4.png"
                              ], 
                              data_type = DataType.IMAGE, 
                              storage_type = StorageType.URL)

Uploading Annotations to a Task

from innotescus import client_factory, DataType, AnnotationFormat, TaskType, ExportType, JobStatus, ResponseCode, StorageType

# Create an authenticated instance of the Innotescus API Client
client = client_factory('api_client_id', 'api_client_secret')

# Upload annotations to the specified task/dataset combo.
# If this task does not exist it will be created
response = client.upload_annotations(project_name = "example project", 
                                     dataset_name = "example dataset", 
                                     task_type = TaskType.SEGMENTATION, 
                                     data_type = DataType.IMAGE, 
                                     annotation_format = AnnotationFormat.COCO, 
                                     file_paths =[
                                                "/path/to/annotation_file_1.json",
                                                "/path/to/annotation_file_2.json"
                                     ], 
                                     task_name = "example task", 
                                     task_description = "Task created via annotation import", 
                                     overwrite_existing_annotations = False,
                                     pre_annotate = True)

Generate and Download Exports

# Start an export for a given project, list of datasets, and list of tasks
response = client.export(export_name = "demo_export", 
                         project_name = "sample project", 
                         annotation_format = AnnotationFormat.COCO, 
                         export_type = ExportType.ANNOTATIONS, 
                         dataset_names = ["sample dataset 1", "sample dataset 2"], 
                         task_name = "sample task")
attempts = 0

# If the export was started successfully, begin polling for the export job completion
while response.status.code == ResponseCode.SUCCESS:
    export_job_id = response.job_id

    # Get the job status to check if our export job is complete
    response = client.get_job_status(export_job_id)
    attempts += 1

    # stop after 60 seconds or when the job is complete
    if attempts >= 5 or response.job_status == JobStatus.SUCCEEDED:

        # Download the completed export to local disc
        response = client.download_export(export_job_id, file_path)
        break
    time.sleep(10) # Delay for 10 seconds

Shell Examples

All commands available to the python client are exposed using the same names. The general syntax for using the shell client is as follows:

$ innotescus <command> <arguments>

Command names are identical to the method names in the python client. For example, InnoApiClient.get_projects() is exposed as innotescus get_projects

Authenticating

Authenticating is done using the same methods as the standard python client (environmental variables & config files), however the shell client also supports an additional way to pass the client id (--client-id) and client secret (--client-secret). If provided to the CLI client, these arguments will override any settings provided elsewhere.

$ innotescus --client-id=<myid> --client-secret=<mysecret> <command>

Executing Commands

For commands with no input parameters, you only need to provide the name of the method you wish to call.

$ inotescus get_jobs

Commands with Parameter

Methods with CLI arguments expose the same arguments available to the python client, with underscores '_' replaced by hyphens '-'.

Warning: There are two differences between how the CLI and python client parse arguments.

  1. For methods with enumerable values (see DataType below), the value should be passed as the name of the enum, not it's value.

  2. When passing arguments with multiple values, the argument must be specified multiple times--one for each value in the list (see FilePaths below).

$ innotescus upload_data \
>    --project-name='My Project' \
>    --dataset-name='My Dataset' \
>    --data-type=IMAGE \
>    --file-paths=$HOME/my-first-file \
>    --file-paths=$HOME/my-second-file

Output Format

Currently, all commands return their output data as JSON to STDOUT. If you need to store this data, it should be redirected appropriately, as demonstrated below:

$ innotescus get_projects > $HOME/my-projects.json