Annotation JSON helper functions#

Converting annotation format to and from src.superannotate format#

superannotate.import_annotation(input_dir, output_dir, dataset_format='superannotate', dataset_name='', project_type='Vector', task='object_detection', images_root='', images_extensions=None)#

Converts other annotation formats to SuperAnnotate annotation format. Currently available (project_type, task) combinations for converter presented below:

From COCO to SA

project_type

task

Pixel

panoptic_segmentation

Pixel

instance_segmentation

Vector

instance_segmentation

Vector

object_detection

Vector

keypoint_detection

From VOC to SA

project_type

task

Pixel

instance_segmentation

Vector

instance_segmentation

Vector

object_detection

From LabelBox to SA

project_type

task

Vector

object_detection

Vector

instance_segmentation

Vector

vector_annotation

Pixel

instance_segmentation

From DataLoop to SA

project_type

task

Vector

object_detection

Vector

instance_segmentation

Vector

vector_annotation

From Supervisely to SA

project_type

task

Vector

object_detection

Vector

keypoint_detection

Vector

vector_annotation

Vector

instance_segmentation

Pixel

instance_segmentation

From VoTT to SA

project_type

task

Vector

instance_segmentation

Vector

object_detection

Vector

vector_annotation

From SageMaker to SA

project_type

task

Pixel

instance_segmentation

Vector

objcet_detection

From VGG to SA

project_type

task

Vector

instance_segmentation

Vector

object_detection

Vector

vector_annotation

From GoogleCloud to SA

project_type

task

Vector

object_detection

From YOLO to SA

project_type

task

Vector

object_detection

Parameters:
  • input_dir (Pathlike(str or Path)) – Path to the dataset folder that you want to convert.

  • output_dir (Pathlike(str or Path)) – Path to the folder, where you want to have converted dataset.

  • dataset_format (str) – Annotation format to convert SuperAnnotate annotation format. Available candidates are: [“COCO”, “VOC”, “LabelBox”, “DataLoop”, “Supervisely”, ‘VGG’, ‘YOLO’, ‘SageMake’, ‘VoTT’, ‘GoogleCloud’]

  • dataset_name (str) – Name of the json file in the input_dir, which should be converted.

  • project_type (str) – SuperAnnotate project type is either ‘Vector’ or ‘Pixel’ (Default: ‘Vector’) ‘Vector’ project creates <image_name>___objects.json for each image. ‘Pixel’ project creates <image_name>___pixel.jsons and <image_name>___save.png annotation mask for each image.

  • task – Task can be one of the following: [‘panoptic_segmentation’, ‘instance_segmentation’, ‘keypoint_detection’, ‘object_detection’, ‘vector_annotation’]. (Default: “object_detection”). ‘keypoint_detection’ can be used to converts keypoints from/to available annotation format. ‘panoptic_segmentation’ will use panoptic mask for each image to generate bluemask for SuperAnnotate annotation format and use bluemask to generate panoptic mask for invert conversion. Panoptic masks should be in the input folder. ‘instance_segmentation’ ‘Pixel’ project_type converts instance masks and ‘Vector’ project_type generates bounding boxes and polygons from instance masks. Masks should be in the input folder if it is ‘Pixel’ project_type. ‘object_detection’ converts objects from/to available annotation format ‘vector_annotation’ can be used to convert all annotations (point, ellipse, circule, cuboid and etc) to SuperAnnotate vector project.

  • images_root (str) – Additonal path to images directory in input_dir

  • image_extensions (list) – List of image files xtensions in the images_root folder

superannotate.export_annotation(input_dir, output_dir, dataset_format, dataset_name, project_type='Vector', task='object_detection')#

Converts SuperAnnotate annotation format to the other annotation formats. Currently available (project_type, task) combinations for converter presented below:

From SA to COCO

project_type

task

Pixel

panoptic_segmentation

Pixel

instance_segmentation

Vector

instance_segmentation

Vector

object_detection

Vector

keypoint_detection

Parameters:
  • input_dir (Pathlike(str or Path)) – Path to the dataset folder that you want to convert.

  • output_dir (Pathlike(str or Path)) – Path to the folder, where you want to have converted dataset.

  • dataset_format (str) – One of the formats that are possible to convert. Available candidates are: [“COCO”]

  • dataset_name (str) – Will be used to create json file in the output_dir.

  • project_type (str) – SuperAnnotate project type is either ‘Vector’ or ‘Pixel’ (Default: ‘Vector’) ‘Vector’ project creates <image_name>___objects.json for each image. ‘Pixel’ project creates <image_name>___pixel.jsons and <image_name>___save.png annotation mask for each image.

  • task (str) – Task can be one of the following: [‘panoptic_segmentation’, ‘instance_segmentation’, ‘keypoint_detection’, ‘object_detection’]. (Default: “object_detection”). ‘keypoint_detection’ can be used to converts keypoints from/to available annotation format. ‘panoptic_segmentation’ will use panoptic mask for each image to generate bluemask for SuperAnnotate annotation format and use bluemask to generate panoptic mask for invert conversion. Panoptic masks should be in the input folder. ‘instance_segmentation’ ‘Pixel’ project_type converts instance masks and ‘Vector’ project_type generates bounding boxes and polygons from instance masks. Masks should be in the input folder if it is ‘Pixel’ project_type. ‘object_detection’ converts objects from/to available annotation format

superannotate.convert_project_type(input_dir, output_dir, convert_to)#

Converts SuperAnnotate ‘Vector’ project type to ‘Pixel’ or reverse.

Parameters:
  • input_dir (Pathlike(str or Path)) – Path to the dataset folder that you want to convert.

  • output_dir (Pathlike(str or Path)) – Path to the folder where you want to have converted files.

  • convert_to (str) – the project type to which the current project should be converted.


Working with annotations#

SAClient.validate_annotations(project_type, annotations_json)#

Validates given annotation JSON.

Parameters:
  • project_type (str) – The project type Vector, Pixel, Video or Document

  • annotations_json (Path-like (str or Path)) – path to annotation JSON

Returns:

The success of the validation

Return type:

bool

SAClient.aggregate_annotations_as_df(project_root, project_type, folder_names=None)#

Aggregate annotations as pandas dataframe from project root.

Parameters:
  • project_root (Path-like (str or Path)) – the export path of the project

  • project_type (str) – the project type, Vector/Pixel, Video or Document

  • folder_names (list of Pathlike (str or Path) objects) – Aggregate the specified folders from project_root. If None aggregates all folders in the project_root

Returns:

DataFrame on annotations

Return type:

pandas DataFrame