Skip to content

Commit 3d88174

Browse files
authored
Merge pull request #29 from superannotateai/develop-coco-fix
Develop coco fix - mixp
2 parents 176461a + 024a45a commit 3d88174

File tree

20 files changed

+471
-24
lines changed

20 files changed

+471
-24
lines changed

superannotate/api.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import json
33
import logging
4+
import sys
45
from pathlib import Path
56

67
import requests
@@ -88,8 +89,8 @@ def init(self, config_location=None):
8889
path=f'/team/{self.team_id}',
8990
)
9091

91-
self.user_id = response.json()['creator_id']
92-
self.team_name = response.json()['name']
92+
self.user_id = response.json().get('creator_id', None)
93+
self.team_name = response.json().get('name', None)
9394

9495
if not self._verify:
9596
urllib3.disable_warnings(
@@ -106,10 +107,11 @@ def init(self, config_location=None):
106107
raise SABaseException(
107108
0, "Couldn't reach superannotate " + response.text
108109
)
109-
mp.track(
110-
self.user_id, "SDK init",
111-
get_default(self.team_name, self.user_id)
112-
)
110+
if "pytest" not in sys.modules:
111+
mp.track(
112+
self.user_id, "SDK init",
113+
get_default(self.team_name, self.user_id)
114+
)
113115
except SABaseException:
114116
self._authenticated = False
115117
self._session = None

superannotate/db/annotation_classes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ def fill_class_and_attribute_names(annotations_json, annotation_classes_dict):
330330
def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
331331
if "instances" not in annotation_json:
332332
return
333+
334+
unknown_classes = {}
335+
for ann in [i for i in annotation_json["instances"] if "className" in i]:
336+
if "className" not in ann:
337+
continue
338+
annotation_class_name = ann["className"]
339+
if not annotation_class_name in annotation_classes_dict:
340+
if annotation_class_name not in unknown_classes:
341+
class_num = -(len(unknown_classes) + 1)
342+
unknown_classes[annotation_class_name] = {
343+
'id': class_num,
344+
'attribute_groups': {}
345+
}
346+
annotation_classes_dict = {**annotation_classes_dict, **unknown_classes}
347+
333348
for ann in annotation_json["instances"]:
334349
if "className" not in ann:
335350
logger.warning("No className in annotation instance")

superannotate/input_converters/converters/coco_converters/coco_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def _area(bitmask):
103103

104104
def _toBbox(bitmask):
105105
y, x = np.where(bitmask)
106+
if x.tolist() == [] and y.tolist() == []:
107+
return [0, 0, 0, 0]
106108
xmin = int(min(x))
107109
xmax = int(max(x))
108110
ymin = int(min(y))

superannotate/input_converters/converters/coco_converters/coco_converter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@ def _parse_json_into_common_format(self, sa_annotation_json, fpath):
169169

170170
if 'name' not in sa_annotation_json[
171171
'metadata'] or sa_annotation_json['metadata']['name'] is None:
172-
fname = fpath.split('/')[-1]
172+
fname = fpath.name
173173
fname = fname[:-len(
174-
self.project_type_to_json_ending[self.project_type]
174+
self.project_type_to_json_ending[self.project_type.lower()]
175175
)]
176-
177176
sa_annotation_json['metadata']['name'] = fname
178177
sa_annotation_json['metadata']['image_path'] = str(
179178
Path(fpath).parent / sa_annotation_json['metadata']['name']

superannotate/mixp/decorators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def __call__(self, *args, **kwargs):
3434
)
3535
properties.pop("project_name", None)
3636
properties = {**default, **properties}
37-
mp.track(user_id, event_name, properties)
37+
if "pytest" not in sys.modules:
38+
mp.track(user_id, event_name, properties)
3839
except:
39-
print('--- mix panel exception ---')
40+
pass
4041
return self.function(*args, **kwargs)

superannotate/mixp/utils/parsers.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,15 +1047,63 @@ def upload_images_from_folder_to_project(*args, **kwargs):
10471047
folder_path = kwargs.get("folder_path", None)
10481048
if not folder_path:
10491049
folder_path = args[1]
1050-
from ...common import DEFAULT_IMAGE_EXTENSIONS as extension
1050+
1051+
recursive_subfolders = kwargs.get("recursive_subfolders", None)
1052+
if not recursive_subfolders:
1053+
recursive_subfolders = args[6:7]
1054+
if recursive_subfolders:
1055+
recursive_subfolders = recursive_subfolders[0]
1056+
else:
1057+
recursive_subfolders = False
1058+
1059+
from ...common import DEFAULT_IMAGE_EXTENSIONS
1060+
extensions = DEFAULT_IMAGE_EXTENSIONS
1061+
extensions = kwargs.get("extensions", None)
1062+
if not extensions:
1063+
extensions = args[2:3]
1064+
if extensions:
1065+
extensions = extensions[0]
1066+
else:
1067+
extensions = DEFAULT_IMAGE_EXTENSIONS
1068+
1069+
from ...common import DEFAULT_FILE_EXCLUDE_PATTERNS
1070+
exclude_file_patterns = DEFAULT_FILE_EXCLUDE_PATTERNS
1071+
exclude_file_patterns = kwargs.get("exclude_file_patterns", None)
1072+
if not exclude_file_patterns:
1073+
exclude_file_patterns = args[5:6]
1074+
if exclude_file_patterns:
1075+
exclude_file_patterns = exclude_file_patterns[0]
1076+
else:
1077+
exclude_file_patterns = DEFAULT_FILE_EXCLUDE_PATTERNS
1078+
10511079
from pathlib import Path
1052-
glob_iterator = Path(folder_path).glob(f'*.{extension}')
1080+
import os
1081+
1082+
paths = []
1083+
for extension in extensions:
1084+
if not recursive_subfolders:
1085+
paths += list(Path(folder_path).glob(f'*.{extension.lower()}'))
1086+
if os.name != "nt":
1087+
paths += list(Path(folder_path).glob(f'*.{extension.upper()}'))
1088+
else:
1089+
paths += list(Path(folder_path).rglob(f'*.{extension.lower()}'))
1090+
if os.name != "nt":
1091+
paths += list(Path(folder_path).rglob(f'*.{extension.upper()}'))
1092+
1093+
filtered_paths = []
1094+
for path in paths:
1095+
not_in_exclude_list = [
1096+
x not in Path(path).name for x in exclude_file_patterns
1097+
]
1098+
if all(not_in_exclude_list):
1099+
filtered_paths.append(path)
1100+
10531101
return {
10541102
"event_name": "upload_images_from_folder_to_project",
10551103
"properties":
10561104
{
10571105
"Image Count":
1058-
sum(1 for _ in glob_iterator),
1106+
len(filtered_paths),
10591107
"Custom Extentions":
10601108
bool(args[2:3] or kwargs.get("extensions", None)),
10611109
"Annotation Status":
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"id": 1,
4+
"project_id": 1,
5+
"name": "class1",
6+
"color": "#626bef",
7+
"count": 0,
8+
"createdAt": "2021-03-31T21:13:10.000Z",
9+
"updatedAt": "2021-03-31T21:13:10.000Z",
10+
"attribute_groups": []
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"metadata": {
3+
"lastAction": {
4+
"email": "",
5+
"timestamp": 1619092786567
6+
},
7+
"width": 2448,
8+
"height": 3264,
9+
"name": "q.JPG",
10+
"projectId": 1,
11+
"isPredicted": false,
12+
"status": "Completed",
13+
"pinned": false,
14+
"annotatorEmail": "",
15+
"qaEmail": ""
16+
},
17+
"comments": [],
18+
"tags": [],
19+
"instances": [
20+
{
21+
"type": "polygon",
22+
"classId": 1,
23+
"probability": 100,
24+
"points": [
25+
2448,
26+
2612.07,
27+
2448,
28+
2651.45,
29+
2448,
30+
988.83
31+
],
32+
"groupId": 0,
33+
"pointLabels": {},
34+
"locked": false,
35+
"visible": true,
36+
"attributes": [],
37+
"trackingId": null,
38+
"error": null,
39+
"createdAt": "2021-04-21T06:56:10.242Z",
40+
"createdBy": {
41+
"email": "",
42+
"role": ""
43+
},
44+
"creationType": "Manual",
45+
"updatedAt": "2021-04-21T06:56:10.242Z",
46+
"updatedBy": {
47+
"email": "",
48+
"role": ""
49+
},
50+
"className": "class1"
51+
}
52+
]
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"info": {"description": "This is instance_test_vector dataset.", "url": "https://superannotate.ai", "version": "1.0", "year": 2021, "contributor": "Superannotate AI", "date_created": "17/05/2021"}, "licenses": [{"url": "https://superannotate.ai", "id": 1, "name": "Superannotate AI"}], "images": [{"id": 1, "file_name": "q.JPG", "height": 3264, "width": 2448, "license": 1}], "annotations": [{"id": 1, "image_id": 1, "segmentation": [[2448, 2612.07, 2448, 2651.45, 2448, 988.83]], "iscrowd": 0, "bbox": [0, 0, 0, 0], "area": 0, "category_id": 1}], "categories": [{"id": 1, "name": "class1", "supercategory": "class1", "isthing": 1, "color": [1, 0, 0]}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"id":599064,"project_id":76203,"name":"some","color":"#c444de","count":0,"createdAt":"2021-05-04T07:26:32.000Z","updatedAt":"2021-05-04T07:26:32.000Z","attribute_groups":[]}]

0 commit comments

Comments
 (0)