Skip to content

Commit a5f47a0

Browse files
committed
Add validator decorator
1 parent 0e7e831 commit a5f47a0

File tree

1 file changed

+110
-70
lines changed

1 file changed

+110
-70
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 110 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,13 +2798,14 @@ def benchmark(
27982798

27992799

28002800
@Trackable
2801+
@validate_arguments
28012802
def consensus(
2802-
project: str,
2803-
folder_names,
2804-
export_root=None,
2805-
image_list=None,
2806-
annot_type="bbox",
2807-
show_plots=False,
2803+
project: NotEmptyStr,
2804+
folder_names: NotEmptyStr,
2805+
export_root: Optional[Union[NotEmptyStr, Path]] = None,
2806+
image_list: Optional[List[NotEmptyStr]] = None,
2807+
annot_type: Optional[NotEmptyStr] = "bbox",
2808+
show_plots: Optional[StrictBool] = False,
28082809
):
28092810
"""Computes consensus score for each instance of given images that are present in at least 2 of the given projects:
28102811
@@ -2852,11 +2853,18 @@ def consensus(
28522853

28532854

28542855
@Trackable
2855-
def run_segmentation(project, images_list, model):
2856+
@validate_arguments
2857+
def run_segmentation(
2858+
project: Union[NotEmptyStr, dict],
2859+
images_list: List[NotEmptyStr],
2860+
model: Union[NotEmptyStr, dict],
2861+
):
28562862
"""Starts smart segmentation on a list of images using the specified model
28572863
28582864
:param project: project name of metadata of the project
28592865
:type project: str or dict
2866+
:param images_list: image list
2867+
:type images_list: list of str
28602868
:param model: The model name or metadata of the model
28612869
:type model: str or dict
28622870
:return: tupe of two lists, list of images on which the segmentation has succeeded and failed respectively
@@ -2887,7 +2895,12 @@ def run_segmentation(project, images_list, model):
28872895

28882896

28892897
@Trackable
2890-
def run_prediction(project, images_list, model):
2898+
@validate_arguments
2899+
def run_prediction(
2900+
project: Union[NotEmptyStr, dict],
2901+
images_list: List[NotEmptyStr],
2902+
model: Union[NotEmptyStr, dict],
2903+
):
28912904
"""This function runs smart prediction on given list of images from a given project using the neural network of your choice
28922905
28932906
:param project: the project in which the target images are uploaded.
@@ -2922,8 +2935,9 @@ def run_prediction(project, images_list, model):
29222935

29232936

29242937
@Trackable
2938+
@validate_arguments
29252939
# todo test
2926-
def plot_model_metrics(metric_json_list):
2940+
def plot_model_metrics(metric_json_list=List[NotEmptyStr]):
29272941
"""plots the metrics generated by neural network using plotly
29282942
29292943
:param metric_json_list: list of <model_name>.json files
@@ -2983,13 +2997,14 @@ def get_plottable_cols(df):
29832997

29842998

29852999
@Trackable
3000+
@validate_arguments
29863001
def add_annotation_bbox_to_image(
2987-
project,
2988-
image_name,
2989-
bbox,
2990-
annotation_class_name,
2991-
annotation_class_attributes=None,
2992-
error=None,
3002+
project: NotEmptyStr,
3003+
image_name: NotEmptyStr,
3004+
bbox: List,
3005+
annotation_class_name: NotEmptyStr,
3006+
annotation_class_attributes: Optional[List[NotEmptyStr]] = None,
3007+
error: Optional[StrictBool] = None,
29933008
):
29943009
"""Add a bounding box annotation to image annotations
29953010
@@ -3017,13 +3032,14 @@ def add_annotation_bbox_to_image(
30173032

30183033

30193034
@Trackable
3035+
@validate_arguments
30203036
def add_annotation_polyline_to_image(
3021-
project,
3022-
image_name,
3023-
polyline,
3024-
annotation_class_name,
3025-
annotation_class_attributes=None,
3026-
error=None,
3037+
project: NotEmptyStr,
3038+
image_name: NotEmptyStr,
3039+
polyline: List,
3040+
annotation_class_name: NotEmptyStr,
3041+
annotation_class_attributes: Optional[List[NotEmptyStr]] = None,
3042+
error: Optional[StrictBool] = None,
30273043
):
30283044
"""Add a polyline annotation to image annotations
30293045
@@ -3050,13 +3066,14 @@ def add_annotation_polyline_to_image(
30503066

30513067

30523068
@Trackable
3069+
@validate_arguments
30533070
def add_annotation_polygon_to_image(
3054-
project,
3055-
image_name,
3056-
polygon,
3057-
annotation_class_name,
3058-
annotation_class_attributes=None,
3059-
error=None,
3071+
project: NotEmptyStr,
3072+
image_name: NotEmptyStr,
3073+
polygon: List,
3074+
annotation_class_name: NotEmptyStr,
3075+
annotation_class_attributes = None,
3076+
error: Optional[StrictBool] = None,
30603077
):
30613078
"""Add a polygon annotation to image annotations
30623079
@@ -3084,13 +3101,14 @@ def add_annotation_polygon_to_image(
30843101

30853102

30863103
@Trackable
3104+
@validate_arguments
30873105
def add_annotation_point_to_image(
3088-
project,
3089-
image_name,
3090-
point,
3091-
annotation_class_name,
3092-
annotation_class_attributes=None,
3093-
error=None,
3106+
project: NotEmptyStr,
3107+
image_name: NotEmptyStr,
3108+
point: List,
3109+
annotation_class_name: NotEmptyStr,
3110+
annotation_class_attributes: Optional[List[NotEmptyStr]] = None,
3111+
error: Optional[StrictBool] = None,
30943112
):
30953113
"""Add a point annotation to image annotations
30963114
@@ -3118,12 +3136,12 @@ def add_annotation_point_to_image(
31183136

31193137
@Trackable
31203138
def add_annotation_ellipse_to_image(
3121-
project,
3122-
image_name,
3123-
ellipse,
3124-
annotation_class_name,
3125-
annotation_class_attributes=None,
3126-
error=None,
3139+
project: NotEmptyStr,
3140+
image_name: NotEmptyStr,
3141+
ellipse: List,
3142+
annotation_class_name: NotEmptyStr,
3143+
annotation_class_attributes: Optional[List[NotEmptyStr]] = None,
3144+
error: Optional[StrictBool] = None,
31273145
):
31283146
"""Add an ellipse annotation to image annotations
31293147
@@ -3150,14 +3168,15 @@ def add_annotation_ellipse_to_image(
31503168

31513169

31523170
@Trackable
3171+
@validate_arguments
31533172
def add_annotation_template_to_image(
3154-
project,
3155-
image_name,
3156-
template_points,
3157-
template_connections,
3158-
annotation_class_name,
3159-
annotation_class_attributes=None,
3160-
error=None,
3173+
project: NotEmptyStr,
3174+
image_name: NotEmptyStr,
3175+
template_points: List,
3176+
template_connections: List,
3177+
annotation_class_name: NotEmptyStr,
3178+
annotation_class_attributes: Optional[List[NotEmptyStr]] = None,
3179+
error: Optional[StrictBool] = None,
31613180
):
31623181
"""Add a template annotation to image annotations
31633182
@@ -3195,13 +3214,14 @@ def add_annotation_template_to_image(
31953214

31963215

31973216
@Trackable
3217+
@validate_arguments
31983218
def add_annotation_cuboid_to_image(
3199-
project,
3200-
image_name,
3201-
cuboid,
3202-
annotation_class_name,
3203-
annotation_class_attributes=None,
3204-
error=None,
3219+
project: NotEmptyStr,
3220+
image_name: NotEmptyStr,
3221+
cuboid: List,
3222+
annotation_class_name: NotEmptyStr,
3223+
annotation_class_attributes: Optional[List[NotEmptyStr]] = None,
3224+
error: Optional[StrictBool] = None,
32053225
):
32063226
"""Add a cuboid annotation to image annotations
32073227
@@ -3232,7 +3252,12 @@ def add_annotation_cuboid_to_image(
32323252

32333253
@Trackable
32343254
def add_annotation_comment_to_image(
3235-
project, image_name, comment_text, comment_coords, comment_author, resolved=False
3255+
project: NotEmptyStr,
3256+
image_name: NotEmptyStr,
3257+
comment_text: NotEmptyStr,
3258+
comment_coords: List,
3259+
comment_author: NotEmptyStr,
3260+
resolved: Optional[StrictBool] = False,
32363261
):
32373262
"""Add a comment to SuperAnnotate format annotation JSON
32383263
@@ -3256,8 +3281,12 @@ def add_annotation_comment_to_image(
32563281
upload_image_annotations(project, image_name, annotations, verbose=False)
32573282

32583283

3284+
@validate_arguments
32593285
def search_images_all_folders(
3260-
project, image_name_prefix=None, annotation_status=None, return_metadata=False
3286+
project: NotEmptyStr,
3287+
image_name_prefix: Optional[NotEmptyStr] = None,
3288+
annotation_status: Optional[NotEmptyStr] = None,
3289+
return_metadata: Optional[StrictBool] = False,
32613290
):
32623291
"""Search images by name_prefix (case-insensitive) and annotation status in
32633292
project and all of its folders
@@ -3288,13 +3317,14 @@ def search_images_all_folders(
32883317

32893318

32903319
@Trackable
3320+
@validate_arguments
32913321
def upload_image_to_project(
3292-
project,
3322+
project: NotEmptyStr,
32933323
img,
3294-
image_name=None,
3295-
annotation_status="NotStarted",
3324+
image_name: Optional[NotEmptyStr] = None,
3325+
annotation_status: Optional[NotEmptyStr] = "NotStarted",
32963326
from_s3_bucket=None,
3297-
image_quality_in_editor=None,
3327+
image_quality_in_editor: Optional[NotEmptyStr] = None,
32983328
):
32993329
"""Uploads image (io.BytesIO() or filepath to image) to project.
33003330
Sets status of the uploaded image to set_status if it is not None.
@@ -3345,7 +3375,11 @@ def upload_image_to_project(
33453375

33463376

33473377
def search_models(
3348-
name=None, type_=None, project_id=None, task=None, include_global=True,
3378+
name: Optional[NotEmptyStr] = None,
3379+
type_: Optional[NotEmptyStr] = None,
3380+
project_id: Optional[int] = None,
3381+
task: Optional[NotEmptyStr] = None,
3382+
include_global: Optional[StrictBool] = True,
33493383
):
33503384
"""Search for ML models.
33513385
@@ -3374,12 +3408,13 @@ def search_models(
33743408

33753409

33763410
@Trackable
3411+
@validate_arguments
33773412
def upload_images_to_project(
3378-
project,
3379-
img_paths,
3380-
annotation_status="NotStarted",
3413+
project: NotEmptyStr,
3414+
img_paths: List[NotEmptyStr],
3415+
annotation_status: Optional[NotEmptyStr] = "NotStarted",
33813416
from_s3_bucket=None,
3382-
image_quality_in_editor=None,
3417+
image_quality_in_editor: Optional[NotEmptyStr] = None,
33833418
):
33843419
"""Uploads all images given in list of path objects in img_paths to the project.
33853420
Sets status of all the uploaded images to set_status if it is not None.
@@ -3503,13 +3538,14 @@ def _upload_s3_image(image_path: str):
35033538

35043539

35053540
@Trackable
3541+
@validate_arguments
35063542
def aggregate_annotations_as_df(
3507-
project_root,
3508-
include_classes_wo_annotations=False,
3509-
include_comments=False,
3510-
include_tags=False,
3511-
verbose=True,
3512-
folder_names=None,
3543+
project_root: Union[NotEmptyStr,Path],
3544+
include_classes_wo_annotations: Optional[StrictBool] = False,
3545+
include_comments: Optional[StrictBool] = False,
3546+
include_tags: Optional[StrictBool] = False,
3547+
verbose: Optional[StrictBool] = True,
3548+
folder_names: Optional[NotEmptyStr] = None,
35133549
):
35143550
"""Aggregate annotations as pandas dataframe from project root.
35153551
@@ -3522,6 +3558,8 @@ def aggregate_annotations_as_df(
35223558
:type include_comments: bool
35233559
:param include_tags: enables inclusion of tags info as tag column
35243560
:type include_tags: bool
3561+
:param verbose: enables logging
3562+
:type verbose: bool
35253563
:param folder_names: Aggregate the specified folders from project_root.
35263564
If None aggregate all folders in the project_root.
35273565
:type folder_names: (list of str)
@@ -3550,7 +3588,9 @@ def aggregate_annotations_as_df(
35503588

35513589
@Trackable
35523590
@validate_arguments
3553-
def delete_annotations(project: str, image_names: List[str] = None):
3591+
def delete_annotations(
3592+
project: NotEmptyStr, image_names: Optional[List[NotEmptyStr]] = None
3593+
):
35543594
"""
35553595
Delete image annotations from a given list of images.
35563596

0 commit comments

Comments
 (0)