Skip to content

Commit 4506e37

Browse files
committed
Merge remote-tracking branch 'origin/json_enhacement'
2 parents cd70d4c + 832a50f commit 4506e37

File tree

297 files changed

+35133
-11496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+35133
-11496
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[BASIC]
2-
good-names=df,f,e,i,j,k,im
2+
good-names=df,f,e,i,j,k,im,pt
33

44
bad-functions=
55
apply,

superannotate/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ def consensus(*args, **kwargs):
8989
SANonExistingProjectNameException
9090
)
9191
from .input_converters.conversion import (
92-
coco_split_dataset, convert_platform, convert_project_type,
93-
export_annotation, import_annotation
92+
coco_split_dataset, convert_project_type, export_annotation,
93+
import_annotation
9494
)
95+
from .old_to_new_format_convertor import update_json_format
9596
from .version import __version__
9697

9798
formatter = logging.Formatter(fmt='SA-PYTHON-SDK - %(levelname)s - %(message)s')

superannotate/analytics/common.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import glob
12
import json
23
import logging
34
from pathlib import Path
4-
import glob
55

66
import pandas as pd
7+
78
from ..exceptions import SABaseException
9+
810
logger = logging.getLogger("superannotate-python-sdk")
911

1012

@@ -32,7 +34,12 @@ def df_to_annotations(df, output_dir):
3234
image_height = None
3335
image_width = None
3436
image_df = df[df["imageName"] == image]
35-
image_annotation = []
37+
image_annotation = {
38+
"instances": [],
39+
"metadata": {},
40+
"tags": [],
41+
"comments": []
42+
}
3643
instances = image_df["instanceId"].dropna().unique()
3744
for instance in instances:
3845
instance_df = image_df[image_df["instanceId"] == instance]
@@ -67,27 +74,31 @@ def df_to_annotations(df, output_dir):
6774
"name": row["attributeName"]
6875
}
6976
)
70-
image_annotation.append(instance_annotation)
77+
image_annotation["instances"].append(instance_annotation)
7178
image_width = image_width or instance_df.iloc[0]["imageWidth"]
7279
image_height = image_height or instance_df.iloc[0]["imageHeight"]
7380
image_pinned = image_pinned or instance_df.iloc[0]["imagePinned"]
7481
image_status = image_status or instance_df.iloc[0]["imageStatus"]
7582

7683
comments = image_df[image_df["type"] == "comment"]
7784
for _, comment in comments.iterrows():
78-
comment_json = {"type": "comment"}
85+
comment_json = {}
7986
comment_json.update(comment["meta"])
87+
comment_json["correspondence"] = comment_json["comments"]
88+
del comment_json["comments"]
8089
comment_json["resolved"] = comment["commentResolved"]
81-
image_annotation.append(comment_json)
90+
image_annotation["comments"].append(comment_json)
91+
92+
tags = image_df[image_df["type"] == "tag"]
93+
for _, tag in tags.iterrows():
94+
image_annotation["tags"].append(tag["tag"])
8295

83-
meta = {
84-
"type": "meta",
96+
image_annotation["metadata"] = {
8597
"width": int(image_width),
8698
"height": int(image_height),
8799
"status": image_status,
88100
"pinned": bool(image_pinned)
89101
}
90-
image_annotation.append(meta)
91102
json.dump(
92103
image_annotation,
93104
open(output_dir / f"{image}___{project_suffix}", "w"),
@@ -236,13 +247,11 @@ def __append_annotation(annotation_dict):
236247

237248
def __get_image_metadata(image_name, annotations):
238249
image_metadata = {"imageName": image_name}
239-
for annotation in annotations:
240-
if "type" in annotation and annotation["type"] == "meta":
241-
image_metadata["imageHeight"] = annotation.get("height")
242-
image_metadata["imageWidth"] = annotation.get("width")
243-
image_metadata["imageStatus"] = annotation.get("status")
244-
image_metadata["imagePinned"] = annotation.get("pinned")
245-
break
250+
251+
image_metadata["imageHeight"] = annotations["metadata"].get("height")
252+
image_metadata["imageWidth"] = annotations["metadata"].get("width")
253+
image_metadata["imageStatus"] = annotations["metadata"].get("status")
254+
image_metadata["imagePinned"] = annotations["metadata"].get("pinned")
246255
return image_metadata
247256

248257
def __get_user_metadata(annotation):
@@ -289,38 +298,30 @@ def __get_user_metadata(annotation):
289298
image_name = annotation_path.name.split(type_postfix)[0]
290299
image_metadata = __get_image_metadata(image_name, annotation_json)
291300
annotation_instance_id = 0
292-
for annotation in annotation_json:
301+
if include_comments:
302+
for annotation in annotation_json["comments"]:
303+
comment_resolved = annotation["resolved"]
304+
comment_meta = {
305+
"x": annotation["x"],
306+
"y": annotation["y"],
307+
"comments": annotation["correspondence"]
308+
}
309+
annotation_dict = {
310+
"type": "comment",
311+
"meta": comment_meta,
312+
"commentResolved": comment_resolved,
313+
}
314+
user_metadata = __get_user_metadata(annotation)
315+
annotation_dict.update(user_metadata)
316+
annotation_dict.update(image_metadata)
317+
__append_annotation(annotation_dict)
318+
if include_tags:
319+
for annotation in annotation_json["tags"]:
320+
annotation_dict = {"type": "tag", "tag": annotation}
321+
annotation_dict.update(image_metadata)
322+
__append_annotation(annotation_dict)
323+
for annotation in annotation_json["instances"]:
293324
annotation_type = annotation.get("type", "mask")
294-
if annotation_type == "meta":
295-
continue
296-
if annotation_type == "comment":
297-
if include_comments:
298-
comment_resolved = annotation["resolved"]
299-
comment_meta = {
300-
"x": annotation["x"],
301-
"y": annotation["y"],
302-
"comments": annotation["comments"]
303-
}
304-
annotation_dict = {
305-
"type": annotation_type,
306-
"meta": comment_meta,
307-
"commentResolved": comment_resolved,
308-
}
309-
user_metadata = __get_user_metadata(annotation)
310-
annotation_dict.update(user_metadata)
311-
annotation_dict.update(image_metadata)
312-
__append_annotation(annotation_dict)
313-
continue
314-
if annotation_type == "tag":
315-
if include_tags:
316-
annotation_tag = annotation["name"]
317-
annotation_dict = {
318-
"type": annotation_type,
319-
"tag": annotation_tag
320-
}
321-
annotation_dict.update(image_metadata)
322-
__append_annotation(annotation_dict)
323-
continue
324325
annotation_class_name = annotation.get("className")
325326
if annotation_class_name is None or annotation_class_name not in class_name_to_color:
326327
logger.warning(

0 commit comments

Comments
 (0)