Python API
Client
- class hasty.Client(api_key, base_url='https://api.hasty.ai')
Client for Hasty API
- __init__(api_key, base_url='https://api.hasty.ai')
Initialize the client
- api_key
Your API key
- get_workspaces()
Returns the list of workspaces that the user can have an access to :returns: A list of
Workspace
objects.
- create_project(workspace: Union[str, Workspace], name: str, description: Optional[str] = None) Project
Creates new project
Project
- Parameters
workspace (
Workspace
, str) – Workspace object or id which the project should belongs toname (str) – Name of the project
description (str, optional) – Project description
Project
- class hasty.Project(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property description
type: string
- property workspace_id
type: string
- edit(name, description)
Edits projects properties
- Parameters
name (str) – Name of the project
description (str, optional) – Project description
- delete()
Removes project
- get_dataset(dataset_id: str)
Get dataset by id, returns ~hasty.Dataset object
- Parameters
dataset_id (str) – Dataset id
- create_dataset(name: str, norder: float = 0)
Creates a new dataset, returns ~hasty.Dataset object
- Parameters
name (str) – Name of the dataset
norder (float, optional) – Order in the list
- get_images(dataset=None, image_status=None)
Retrieves the list of projects images.
- Parameters
dataset (str, ~hasty.Dataset, list of str, list of ~hasty.Dataset) – filter images by dataset
image_status (str, list of str) –
Filters images by status, valid values are:
”NEW”
”DONE”,
”SKIPPED”
”IN PROGRESS”
”TO REVIEW”
”AUTO-LABELLED”
- get_image(image_id)
Retrieves the image by its id.
- Parameters
image_id (str) – Image ID
- upload_from_file(dataset, filepath, external_id: Optional[str] = None)
Uploads image from the given filepath
- Parameters
dataset (~hasty.Dataset, str) – Dataset object or id that the image should belongs to
filepath (str) – Local path
external_id (str) – External ID (optional)
- upload_from_url(dataset: Union[Dataset, str], filename: str, url: str, copy_original: bool = True, external_id: Optional[str] = None)
Uploads image from a given URL
- Parameters
dataset (~hasty.Dataset, str) – Dataset object or id that the image should belongs to
filename (str) – Filename of the image
url (str) – Image url
copy_original (str) – If True Hasty makes a copy of the image. Default True.
external_id (str) – External ID (optional)
- get_label_classes()
Get label classes, list of
LabelClass
objects.
- get_label_class(label_class_id: str)
Get label class by id, returns ~hasty.LabelClass object
- Parameters
label_class_id (str) – Label class id
- create_label_class(name: str, color: Optional[str] = None, class_type: str = 'object', norder: Optional[float] = None, external_id: Optional[str] = None)
Create label class, returns
LabelClass
object.- Parameters
name (str) – Label class name
color (str, optional) – Color in HEX format #0f0f0faa
class_type (str, optional) – Class type [object or background] (default object)
norder (float, optional) – Order in the Hasty tool
external_id (str, optional) – External Identifier
- get_tag_class(tag_class_id: str)
Get tag class by id, returns ~hasty.TagClass object
- Parameters
tag_class_id (str) – Tag class id
- create_tag_class(name: str, norder: Optional[float] = None)
Create tag class, returns
TagClass
object.- Parameters
name (str) – Tag class name
norder (float, optional) – Order in the Hasty tool
- create_attribute(name: str, attribute_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: Optional[List[str]] = None)
Create attribute, returns
Attribute
object.- Parameters
name (str) – Attribute name
attribute_type (str) – Attribute type [‘SELECTION’, ‘MULTIPLE-SELECTION’, ‘TEXT’, ‘INT’, ‘FLOAT’, ‘BOOL’]
description (str, optional) – Attrbute description
norder (float, optional) – Order in the Hasty tool
values (list of str) – List of values for SELECTION and MULTIPLE-SELECTION attribute type
- get_attribute_classes()
- Get attributes - class mapping. Returns list of dict with a keys:
attribute_id - Attribute ID
class_id - Class ID
attribute_order - Order of attributes within the class
class_order - Order of classes within the attribute
- set_attribute_classes(attribute_classes)
Set attribute - class mapping
- Parameters
attribute_classes (dict) –
ID (- class_id - Class) –
ID –
class (- attribute_order - Order of attributes within the) –
attribute (- class_order - Order of classes within the) –
- delete_attribute_classes(attribute_classes)
Removes attribute - class mapping
- Parameters
attribute_classes (dict) –
ID (- class_id - Class) –
ID –
class (- attribute_order - Order of attributes within the) –
attribute (- class_order - Order of classes within the) –
- export(name: str, export_format: str, dataset: Optional[Union[Dataset, str, List[Dataset], List[str]]] = None, image_status: Union[str, List[str]] = 'DONE', sign_urls: bool = False, semantic_format: str = 'gs_asc', labels_order: Optional[List[str]] = None)
Initiate export job. Returns
ExportJob
object.- Parameters
name (str) – Name of the export file
export_format (str) – Export format one of [“json_v1.1”, “semantic_png”, “json_coco”, “images”]
dataset (~hasty.Dataset, str, list of ~hasty.Dataset, list of str) – List of the datasets to export
image_status (list of str, str) – List of the image statuses to export. Default DONE
sign_urls (bool) – Whether to generate sign urls for images. Default False
semantic_format (str) – Format for semantic_png export. [“gs_desc”, “gs_asc”, “class_color”]
labels_order (list of str) – Draw order for semantic_png export [“z_index”, “class_type”, “class_order”]
- get_instance_segmentor()
Returns instance segmentation model. Returns
InstanceSegmentor
object.
- get_semantic_segmentor()
Returns semantic segmentation model. Returns
SemanticSegmentor
object.
- get_attributer()
Returns active attributer model for the project. Returns
Attributer
object.
- get_automated_labeling_jobs()
Get automated labeling jobs, list of
AutomatedLabelingJob
objects.
- get_automated_labeling_job(job_id: str)
Get automated labeling jobs, list of
AutomatedLabelingJob
objects.- Parameters
job_id (str) – Automated labeling job id
- create_automated_labeling_job(experiment_id: str, confidence_threshold: float = 0.8, max_detections_per_image: int = 100, num_images: int = 0, masker_threshold: float = 0.5, dataset_id: Optional[str] = None)
Create automated labeling job, returns
AutomatedLabelingJob
object.- Parameters
experiment_id (str) – ID of an experiment, that would be used for automated labeling
confidence_threshold (float, optional) – Confidence threshold of the predictions that should be applied (default 0.8)
max_detections_per_image (int, optional) – Max number of labels that should be created, default 100
num_images (int, optional) – Total number of images that should be used for automated labeling (default all)
masker_threshold (float, optional) – Threshold for mask head (default 0.5)
dataset_id (str, optional) – Filter images by dataset
Dataset
- class hasty.Dataset(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property norder
type: float
- edit(name: str, norder: float)
Edit dataset properties
- Parameters
name (str) – Name of the dataset
norder (float) – Order in the list
- delete()
Removes dataset
Image
- class hasty.Image(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property dataset_id
type: string
- property dataset_name
type: string
- property width
type: int
- property height
type: int
- property status
type: string
- property public_url
type: string
- property external_id
type: string
- get_labels()
Returns image labels (list of ~hasty.Label objects)
- create_label(label_class: Union[LabelClass, str], bbox: Optional[List[int]] = None, polygon: Optional[List[List[int]]] = None, mask: Optional[List[int]] = None, z_index: Optional[int] = None, external_id: Optional[str] = None)
Create label
- Parameters
label_class (LabelClass, str) – Label class or label class ID of the label
bbox (list of int) – Coordinates of bounding box [x_min, y_min, x_max, y_max]
polygon (list) – List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]]
mask (list of int) – RLE Encoded binary mask, (order right -> down)
z_index (int) – Z index of the label. A label with greater value is in front of a label with a lower one.
external_id (str, optional) – External Identifier
- create_labels(labels)
Create multiple labels. Returns a list of ~hasty.Label objects
- Parameters
labels (list of dict) – List of labels, keys: class_id: Label class ID of the label bbox: Coordinates of bounding box [x_min, y_min, x_max, y_max] polygon: List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]] mask: RLE Encoded binary mask, (order right -> down) z_index: Z index of the label. external_id: External Identifier
- edit_labels(labels)
Updates multiple labels. Returns a list of ~hasty.Label objects
- Parameters
labels (list of dict) – List of labels, keys: label_id: Label id class_id: Label class ID of the label bbox: Coordinates of bounding box [x_min, y_min, x_max, y_max] polygon: List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]] mask: RLE Encoded binary mask, (order right -> down) z_index: Z index of the label. external_id: External identifier
- delete_labels(label_ids: List[str])
Removes multiple labels
- Parameters
label_ids (list of str) – Returns list of ids
- set_status(status: str)
Set image status
- Parameters
status – New status one of [“NEW”, “DONE”, “SKIPPED”, “IN PROGRESS”, “TO REVIEW”]
- download(filepath: str)
Downloads image to file
- Parameters
filepath (str) – Local path
- rename(new_name: str)
Rename image
- Parameters
new_name (str) – New image name
- delete()
Removes image
- get_tags()
Returns image tags (list of ~hasty.Tag objects)
LabelClass
- class hasty.LabelClass(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property color
type: string
- property class_type
type: string
- property norder
type: float
- property external_id
type: string
- edit(name, color=None, class_type='object', norder=None, external_id=None)
Edit label class properties
- Parameters
name (str) – Label class name
color (str, optional) – Color in HEX format #0f0f0faa
class_type (str, optional) – Class type [object or background] (default object)
norder (float, optional) – Order in the Hasty tool
external_id (str, optional) – External identifier
- delete()
Deletes label class
TagClass
- class hasty.TagClass(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property norder
type: float
- edit(name, norder=None)
Edit tag class properties
- Parameters
name (str) – Taп class name
norder (float, optional) – Order in the Hasty tool
- delete()
Deletes tag class
Attribute
- class hasty.Attribute(requester, data, obj_params=None)
- property id
type: string
- property name
type: string
- property project_id
type: string
- property attribute_type
type: string
- property description
type: string
- property norder
type: float
- property values
type: Dict
- edit(name: str, attribute_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: Optional[List[str]] = None)
Edit attribute properties
- Parameters
Args –
name (str) – Attribute name
attribute_type (str) – Attribute type [‘SELECTION’, ‘MULTIPLE-SELECTION’, ‘TEXT’, ‘INT’, ‘FLOAT’, ‘BOOL’]
description (str, optional) – Attrbute description
norder (float, optional) – Order in the Hasty tool
values (list of str) – List of values for SELECTION and MULTIPLE-SELECTION attribute type
- delete()
Deletes attribute
Label
- class hasty.Label(requester, data, obj_params=None)
- property id
type: string
- property project_id
type: string
- property image_id
type: string
- property class_id
type: string
- property bbox
type: string
- property polygon
type: string
- property mask
type: string
- property z_index
type: string
- property external_id
type: string
- edit(label_class, bbox=None, polygon=None, mask=None, z_index=None, external_id=None)
Update label properties
- Parameters
label_class (LabelClass, str) – Label class or label class ID of the label
bbox (list of int) – Coordinates of bounding box [x_min, y_min, x_max, y_max]
polygon (list) – List of x, y pairs [[x0, y0], [x1, y1], …. [x0, y0]]
mask (list of int) – RLE Encoded binary mask, (order right -> down)
z_index (float) – Z index of the label. A label with greater value is in front of a label with a lower one.
external_id (str, optional) – External Identifier
- delete()
Delete label
- get_attributes()
Get attributes values, list of
LabelAttribute
objects.
- set_attribute(attribute, value)
Set label attribute
- Parameters
attribute (~hasty.Attribute, str) –
value (str, float, int, bool, list of str) –
Tag
Attributer
- class hasty.Attributer(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, bboxes: Optional[List[List[str]]] = None, confidence_threshold: float = 0.5)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
bboxes (list of list of int) – List of bounding boxes [x_min, y_min, x_max, y_max]
confidence_threshold (float) – Confidence threshold [0, 1) (default 0.5)
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
attribute_id (str): Attribute id
lov_ids (list of str): List of attribute values
- Return type
List of List of dict
Detector
- class hasty.Detector(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, confidence_threshold: float = 0.5, max_detections_per_image: int = 100)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
confidence_threshold (float) – Confidence threshold [0, 1) (default 0.5)
max_detections_per_image (int) – Maximum detections per image (default 100)
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
score (float): Confidence score
class_id (str): Label class ID
- Return type
List of dict
InstanceSegmentor
- class hasty.InstanceSegmentor(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, confidence_threshold: float = 0.5, max_detections_per_image: int = 100)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
confidence_threshold (float) – Confidence threshold [0, 1) (default 0.5)
max_detections_per_image (int) – Maximum detections per image (default 100)
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
mask (list of int): RLE Encoded binary mask, (order right -> down)
score (float): Confidence score
class_id (str): Label class ID
- Return type
List of dict
SemanticSegmentor
- class hasty.SemanticSegmentor(requester, data, obj_params=None)
- discover_model()
Performs model discovery and loads model to GPU
- predict(image_url: Optional[str] = None, image_path: Optional[str] = None, min_size: float = 0.0)
Returns predictions for provided image.
- Parameters
image_url (str) – Image URL
image_path (str) – Path to local image file
min_size (float) – Ignore prediction with an area less then min_size
- Returns
bbox (list of int): Coordinates of bounding box [x_min, y_min, x_max, y_max]
mask (list of int): RLE Encoded binary mask, (order right -> down)
class_id (str): Label class ID
- Return type
List of dict