1- import functools
21import json
32import logging
43import os
1211
1312logger = logging .getLogger ()
1413
15- DEFAULT_IMAGE_EXTENSIONS = ("jpg" , "jpeg" , "png" , "tif" , "tiff" , "webp" , "bmp" )
16- DEFAULT_FILE_EXCLUDE_PATTERNS = ("___save.png" , "___fuse.png" )
17-
18- DEFAULT_VIDEO_EXTENSIONS = ("mp4" , "avi" , "mov" , "webm" , "flv" , "mpg" , "ogg" )
19-
20- SPECIAL_CHARACTERS_IN_PROJECT_FOLDER_NAMES = set ('/\\ :*?"<>|' )
21-
2214_PROJECT_TYPES = {"Vector" : 1 , "Pixel" : 2 }
2315
2416_ANNOTATION_STATUSES = {
3022 "Skipped" : 6 ,
3123}
3224
33- _UPLOAD_STATES_STR_TO_CODES = {"Initial" : 1 , "Basic" : 2 , "External" : 3 }
34- _UPLOAD_STATES_CODES_TO_STR = {1 : "Initial" , 2 : "Basic" , 3 : "External" }
35-
36- _USER_ROLES = {"Admin" : 2 , "Annotator" : 3 , "QA" : 4 , "Customer" : 5 , "Viewer" : 6 }
37- _AVAILABLE_SEGMENTATION_MODELS = ["autonomous" , "generic" ]
38- _MODEL_TRAINING_STATUSES = {
39- "NotStarted" : 1 ,
40- "InProgress" : 2 ,
41- "Completed" : 3 ,
42- "FailedBeforeEvaluation" : 4 ,
43- "FailedAfterEvaluation" : 5 ,
44- "FailedAfterEvaluationWithSavedModel" : 6 ,
45- }
46-
47- _PREDICTION_SEGMENTATION_STATUSES = {
48- "NotStarted" : 1 ,
49- "InProgress" : 2 ,
50- "Completed" : 3 ,
51- "Failed" : 4 ,
52- }
53-
54- _MODEL_TRAINING_TASKS = {
55- "Instance Segmentation for Pixel Projects" : "instance_segmentation_pixel" ,
56- "Instance Segmentation for Vector Projects" : "instance_segmentation_vector" ,
57- "Keypoint Detection for Vector Projects" : "keypoint_detection_vector" ,
58- "Object Detection for Vector Projects" : "object_detection_vector" ,
59- "Semantic Segmentation for Pixel Projects" : "semantic_segmentation_pixel" ,
60- }
61-
62-
63- def prediction_segmentation_status_from_str_to_int (status ):
64- return _PREDICTION_SEGMENTATION_STATUSES [status ]
65-
66-
67- def prediction_segmentation_status_from_int_to_str (status ):
68- for idx , item in _PREDICTION_SEGMENTATION_STATUSES .items ():
69- if item == status :
70- return idx
71- raise RuntimeError ("NA segmentation/prediction status" )
72-
73-
74- def model_training_status_int_to_str (project_status ):
75- for item in _MODEL_TRAINING_STATUSES :
76- if _MODEL_TRAINING_STATUSES [item ] == project_status :
77- return item
78- raise RuntimeError ("NA training status" )
79-
80-
81- def model_training_status_str_to_int (project_status ):
82- return _MODEL_TRAINING_STATUSES [project_status ]
83-
8425
8526def image_path_to_annotation_paths (image_path , project_type ):
8627 image_path = Path (image_path )
@@ -94,98 +35,13 @@ def image_path_to_annotation_paths(image_path, project_type):
9435 )
9536
9637
97- def project_type_str_to_int (project_type ):
98- return _PROJECT_TYPES [project_type ]
99-
100-
101- def project_type_int_to_str (project_type ):
102- """Converts metadata project_type int value to a string
103-
104- :param project_type: int in project metadata's 'type' key
105- :type project_type: int
106-
107- :return: 'Vector' or 'Pixel'
108- :rtype: str
109- """
110- for k , v in _PROJECT_TYPES .items ():
111- if v == project_type :
112- return k
113- raise RuntimeError ("NA Project type" )
114-
115-
116- def user_role_str_to_int (user_role ):
117- return _USER_ROLES [user_role ]
118-
119-
120- def user_role_int_to_str (user_role ):
121- for k , v in _USER_ROLES .items ():
122- if v == user_role :
123- return k
124- return None
125-
126-
127- def annotation_status_str_to_int (annotation_status ):
128- return _ANNOTATION_STATUSES [annotation_status ]
129-
130-
131- def upload_state_str_to_int (upload_state ):
132- return _UPLOAD_STATES_STR_TO_CODES [upload_state ]
133-
134-
135- def upload_state_int_to_str (upload_state ):
136- return _UPLOAD_STATES_CODES_TO_STR [upload_state ]
137-
138-
139- def annotation_status_int_to_str (annotation_status ):
140- """Converts metadata annotation_status int value to a string
141-
142- :param annotation_status: int in image metadata's 'annotation_status' key
143- :type annotation_status: int
144-
145- :return: One of 'NotStarted' 'InProgress' 'QualityCheck' 'Returned' 'Completed' 'Skipped'
146- :rtype: str
147- """
148-
149- for k , v in _ANNOTATION_STATUSES .items ():
150- if v == annotation_status :
151- return k
152- return None
153-
154-
155- def deprecated_alias (** aliases ):
156- def deco (f ):
157- @functools .wraps (f )
158- def wrapper (* args , ** kwargs ):
159- rename_kwargs (f .__name__ , kwargs , aliases )
160- return f (* args , ** kwargs )
161-
162- return wrapper
163-
164- return deco
165-
166-
167- def rename_kwargs (func_name , kwargs , aliases ):
168- for alias , new in aliases .items ():
169- if alias in kwargs :
170- if new in kwargs :
171- raise TypeError (f"{ func_name } received both { alias } and { new } " )
172- logger .warning ("%s is deprecated; use %s in %s" , alias , new , func_name )
173- kwargs [new ] = kwargs .pop (alias )
174-
175-
17638def hex_to_rgb (hex_string ):
17739 """Converts HEX values to RGB values
17840 """
17941 h = hex_string .lstrip ("#" )
18042 return tuple (int (h [i : i + 2 ], 16 ) for i in (0 , 2 , 4 ))
18143
18244
183- def rgb_to_hex (rgb_tuple ):
184- """Converts RGB values to HEX values
185- """
186- return "#%02x%02x%02x" % rgb_tuple
187-
188-
18945def blue_color_generator (n , hex_values = True ):
19046 """ Blue colors generator for SuperAnnotate blue mask.
19147 """
@@ -305,7 +161,6 @@ def write_to_json(output_path, json_data):
305161
306162
307163MAX_IMAGE_SIZE = 100 * 1024 * 1024 # 100 MB limit
308- MAX_IMAGE_RESOLUTION = {"Vector" : 100_000_000 , "Pixel" : 4_000_000 } # Resolution limit
309164
310165
311166def tqdm_converter (total_num , images_converted , images_not_converted , finish_event ):
0 commit comments