Skip to content

Commit b835f7c

Browse files
authored
Merge pull request #110 from superannotateai/develop
Release
2 parents 7c6f54a + 605e51e commit b835f7c

File tree

10 files changed

+228
-95
lines changed

10 files changed

+228
-95
lines changed

superannotate/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def init(self, config_location=None):
5151
self._api_config = json.load(open(config_location))
5252

5353
try:
54-
self._token = self._api_config["token"]
54+
self._token = self._api_config["token"].strip()
5555
except KeyError:
5656
raise SABaseException(
5757
0,

superannotate/db/annotation_classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
347347
annotation_classes_dict = {**annotation_classes_dict, **unknown_classes}
348348
templates_map = get_templates_mapping()
349349
for ann in (
350-
i for i in annotation_json["instances"] if i['type'] == 'template'
350+
i for i in annotation_json["instances"] if i.get('type', None) == 'template'
351351
):
352-
ann['templateId'] = templates_map.get(ann['templateName'], -1)
352+
ann['templateId'] = templates_map.get(ann.get('templateName', ''), -1)
353353
for ann in annotation_json["instances"]:
354354
if "className" not in ann:
355355
logger.warning("No className in annotation instance")

superannotate/mixp/decorators.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@ class Trackable(object):
1717
def __init__(self, function):
1818
lock = Lock()
1919
self.function = function
20+
self._success = None
21+
self._caller_name = None
22+
self._func_name_to_track = None
2023
with lock:
2124
Trackable.registered.add(function.__name__)
2225
functools.update_wrapper(self, function)
2326

24-
def __call__(self, *args, **kwargs):
27+
def should_track(self):
28+
if self._caller_name not in Trackable.registered or self._func_name_to_track in always_trackable_func_names:
29+
return True
30+
return False
31+
32+
def track(self, *args, **kwargs):
2533
try:
26-
func_name_to_track = self.function.__name__
27-
caller_name = sys._getframe(1).f_code.co_name
28-
if caller_name not in Trackable.registered or func_name_to_track in always_trackable_func_names:
29-
data = getattr(parsers, func_name_to_track)(*args, **kwargs)
34+
if self.should_track():
35+
data = getattr(parsers, self._func_name_to_track)(*args, **kwargs)
3036
user_id = _api.user_id
3137
event_name = data['event_name']
3238
properties = data['properties']
39+
properties['Success'] = self._success
3340
default = get_default(
3441
_api.team_name,
3542
_api.user_id,
@@ -39,6 +46,19 @@ def __call__(self, *args, **kwargs):
3946
properties = {**default, **properties}
4047
if "pytest" not in sys.modules:
4148
mp.track(user_id, event_name, properties)
42-
except:
49+
except Exception as e:
4350
pass
44-
return self.function(*args, **kwargs)
51+
52+
53+
def __call__(self, *args, **kwargs):
54+
try:
55+
self._caller_name = sys._getframe(1).f_code.co_name
56+
self._func_name_to_track = self.function.__name__
57+
ret = self.function(*args, **kwargs)
58+
self._success = True
59+
self.track(*args, **kwargs)
60+
except Exception as e:
61+
self._success = False
62+
self.track(*args, **kwargs)
63+
raise e
64+
return ret

superannotate/mixp/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CALLERS_TO_IGNORE = ["get_project_metadata_bare"]
1+
CALLERS_TO_IGNORE = ["get_project_metadata_bare", "_path_to_folder_id_project"]

superannotate/mixp/utils/parsers.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,33 +1183,44 @@ def coco_split_dataset(*args, **kwargs):
11831183

11841184

11851185
def run_training(*args, **kwargs):
1186-
project = kwargs.get("project", None)
1187-
if not project:
1188-
project = args[0][0]
1186+
11891187
task = kwargs.get("task", None)
11901188
if not task:
1191-
task = args[4]
1192-
hyperparameters = kwargs.get("hyperparameters", None)
1193-
if not hyperparameters:
1194-
hyperparameters = args[4]
1195-
from superannotate.db.projects import get_project_metadata as sa_get_project_metadata
1196-
project_name = get_project_name(project)
1197-
project_metadata = sa_get_project_metadata(project_name)
1189+
task = args[2]
11981190
log = kwargs.get("log", "empty")
11991191
if log == "empty":
1200-
log = args[6:7]
1192+
log = args[7:8]
12011193
if not log:
12021194
log = False
12031195
else:
1204-
log = args[6]
1196+
log = args[7]
1197+
1198+
train_data = kwargs.get("train_data", None)
1199+
if not train_data:
1200+
train_data = args[4]
1201+
1202+
test_data = kwargs.get("test_data", None)
1203+
if not test_data:
1204+
test_data = args[5]
1205+
1206+
data_structure = "Project"
1207+
1208+
for path in train_data + test_data:
1209+
if "/" in path:
1210+
data_structure = "Folder"
1211+
break
1212+
1213+
from superannotate.db.projects import get_project_metadata as sa_get_project_metadata
1214+
project_name = get_project_name(train_data[0])
1215+
project_metadata = sa_get_project_metadata(project_name)
1216+
12051217
return {
12061218
"event_name": "run_training",
12071219
"properties":
12081220
{
12091221
"Project Type": project_metadata['type'],
12101222
"Task": task,
1211-
"Learning Rate": hyperparameters['base_lr'],
1212-
"Batch Size": hyperparameters['images_per_batch'],
1223+
"Data Structure": data_structure,
12131224
"Log": log
12141225
}
12151226
}
@@ -1673,6 +1684,7 @@ def assign_folder(*args, **kwargs):
16731684
}
16741685
}
16751686

1687+
16761688
def unassign_images(*args, **kwargs):
16771689
image_names = kwargs.get("image_names", None)
16781690
if not image_names:
@@ -1690,19 +1702,9 @@ def unassign_images(*args, **kwargs):
16901702

16911703
return {
16921704
"event_name": "unassign_images",
1693-
"properties": {
1694-
"Assign Folder": is_root,
1695-
"Image Count": len(image_names)
1696-
}
1705+
"properties":
1706+
{
1707+
"Assign Folder": is_root,
1708+
"Image Count": len(image_names)
1709+
}
16971710
}
1698-
1699-
1700-
1701-
1702-
# def unassign_images(project, image_names):
1703-
1704-
1705-
1706-
#
1707-
# Assign Folder: IsRoot(project) ,
1708-
# Image Count: len(image_names),

superannotate/ml/defaults.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
DEFAULT_HYPERPARAMETERS = {
22
"instance_type": "1 x T4 16 GB",
33
"num_epochs": 12,
4-
"dataset_split_ratio": 80,
54
"base_lr": 0.02,
65
"gamma": 0.5,
76
"images_per_batch": 4,

0 commit comments

Comments
 (0)