Skip to content

Code Examples

Uploading Images to a Dataset

from innotescus.innotescus import ApiClient, DataType, AnnotationFormat, TaskType, ExportType, JobStatus, ResponseCode
project_name = "test_project"
dataset_name = "test_dataset"

# Path to your images
file_path = '/path/to/files'

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

# Find all files in this path
file_paths = [os.path.join(file_path, f) for f in os.listdir(file_path)]

# 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, dataset_name, file_paths, DataType.IMAGE)

Uploading Annotations to a Task

from innotescus.innotescus import ApiClient, DataType, AnnotationFormat, TaskType, ExportType, JobStatus, ResponseCode
project_name = "test_project"
dataset_name = "test_dataset"
task_name = "test_task"

# Path to your images
annotation_path = '/path/to/annotation_files'

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

# Find all files in this path
file_paths = [os.path.join(annotation_path , f) for f in os.listdir(annotation_path )]

# Upload annotations to the specified task/dataset combo. If this task does not exist it will be created
response = client.upload_annotations(project_name, dataset_name, TaskType.SEGMENTATION, DataType.IMAGE, AnnotationFormat.COCO, import_file_paths, task_name, "", True)

Generate and Download Exports

# Start an export for a given project, list of datasets, and list of tasks
response = client.export("demo_export", project_name, AnnotationFormat.COCO, ExportType.ANNOTATIONS, [dataset_name], task_name)
attempts = 0

# If the export was started successfully, begin polling for the completion of the export job
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