Skip to content

Commit bb7c279

Browse files
committed
Fix bug schema rbbox, ellipse
1 parent 9c0d2cb commit bb7c279

File tree

309 files changed

+414
-75
lines changed

Some content is hidden

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

309 files changed

+414
-75
lines changed

src/superannotate_databricks_connector/schemas/shapes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_rbbox_schema():
4343
StructField("x3", FloatType(), True),
4444
StructField("y3", FloatType(), True),
4545
StructField("x4", FloatType(), True),
46-
StructField("y5", FloatType(), True)
46+
StructField("y4", FloatType(), True)
4747
])
4848

4949

@@ -95,7 +95,7 @@ def get_ellipse_schema():
9595
StructField("cx", FloatType(), True),
9696
StructField("cy", FloatType(), True),
9797
StructField("rx", FloatType(), True),
98-
StructField("ty", FloatType(), True),
98+
StructField("ry", FloatType(), True),
9999
StructField("angle", FloatType(), True)
100100
])
101101

src/superannotate_databricks_connector/schemas/video_schema.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/superannotate_databricks_connector/vector.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,116 @@ def get_vector_dataframe(annotations, spark, custom_id_map=None):
160160

161161
spark_df = spark.createDataFrame(rows, schema=schema)
162162
return spark_df
163+
164+
165+
def process_attribute(attribute):
166+
return {"groupName": attribute["groupName"],
167+
"name": attribute["name"]}
168+
169+
170+
def create_instance_dict(item):
171+
"""Funciton that unpacks a dataframe row converted into a dict
172+
and transformes it to a superannotate annotaiton dictionary
173+
174+
Arg:
175+
item (dict): dictionary with a instance in the superannotate-databricks
176+
format
177+
Returns:
178+
dict processed into superannotate json format
179+
"""
180+
item_dict = {
181+
"type": item["instance_type"],
182+
"classId": int(item["classId"]),
183+
"probability": item["probability"],
184+
"groupId": int(item["groupId"]),
185+
# "pointLabels": item.get("pointLabels", None), # uncomment if needed
186+
"locked": item["locked"],
187+
"trackingId": item["trackingId"],
188+
"attributes": [process_attribute(att) for att in item["attributes"]],
189+
"error": item["error"],
190+
"createdAt": item["createdAt"],
191+
"createdBy": item["createdBy"],
192+
"creationType": item["creationType"],
193+
"updatedAt": item["updatedAt"],
194+
"updatedBy": item["updatedBy"],
195+
"className": item["className"]
196+
}
197+
198+
instance_type = item["instance_type"]
199+
if instance_type in ["bbox", "rbbox"]:
200+
item_dict["points"] = item[instance_type].asDict()
201+
elif instance_type == "cuboid":
202+
item_dict["points"] = {k: v.asDict()
203+
for k, v in item["cuboid"].asDict().items()}
204+
elif instance_type == "polygon":
205+
item_dict["points"] = item["polygon"].asDict()["points"]
206+
item_dict["exclude"] = item["polygon"].asDict()["exclude"]
207+
elif instance_type == "point":
208+
item_dict["x"] = item["point"].asDict()["x"]
209+
item_dict["y"] = item["point"].asDict()["y"]
210+
elif instance_type == "ellipse":
211+
ellipse = item["ellipse"].asDict()
212+
item_dict["cx"] = ellipse["cx"]
213+
item_dict["cy"] = ellipse["cy"]
214+
item_dict["rx"] = ellipse["rx"]
215+
item_dict["ry"] = ellipse["ry"]
216+
item_dict["angle"] = ellipse["angle"]
217+
elif instance_type == "polyline":
218+
item_dict["points"] = item["polyline"]
219+
return item_dict
220+
221+
222+
def create_tag_dict(item):
223+
"""Funciton that unpacks a dataframe row converted into a dict
224+
and transformes it to a superannotate annotaiton dictionary
225+
226+
Arg:
227+
item (dict): dictionary with a tag in the superannotate-databricks
228+
format
229+
Returns:
230+
dict processed into superannotate json format
231+
"""
232+
item_dict = {
233+
"type": item["instance_type"],
234+
"classId": item["classId"],
235+
"probability": item["probability"],
236+
"attributes": [process_attribute(att) for att in item["attributes"]],
237+
"createdAt": item["createdAt"],
238+
"createdBy": item["createdBy"],
239+
"creationType": item["creationType"],
240+
"updatedAt": item["updatedAt"],
241+
"updatedBy": item["updatedBy"],
242+
"className": item["className"]
243+
}
244+
return item_dict
245+
246+
247+
def unpack_vector_row(row):
248+
"""Funciton that unpacks a dataframe row into a
249+
superannotate json ready to be uploaded
250+
251+
Arg:
252+
row (spark.sql.Row): row from superannotate formated dataframe
253+
Returns:
254+
dict processed into superannotate json format
255+
"""
256+
metadata = {"height": row["image_height"],
257+
"width": row["image_width"],
258+
"name": row["image_name"],
259+
"projectId": row["projectId"],
260+
"isPredicted": row["isPredicted"],
261+
"status": row["status"],
262+
"pinned": row["pinned"],
263+
"annotatorEmail": row["annotatorEmail"],
264+
"qaEmail": row["qaEmail"]}
265+
instances = []
266+
for instance in row["instances"]:
267+
instances.append(create_instance_dict(instance.asDict()))
268+
for tag in row["tags"]:
269+
instances.append(create_tag_dict(tag.asDict()))
270+
comments = []
271+
for comment in row["comments"]:
272+
comments.append(comment.asDict())
273+
return {"metadata": metadata,
274+
"instances": instances,
275+
"comments": comments}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata": {"height": 1365, "width": 2048, "name": "CDY_2015.jpg", "lastAction": {"email": "satenik@superannotate.com", "timestamp": 1686080909922}, "projectId": 129671, "isPredicted": false, "status": "Skipped", "pinned": false, "annotatorEmail": null, "qaEmail": null}, "instances": [], "comments": [], "tags": []}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata": {"height": 1365, "width": 2048, "name": "CDY_2016.jpg", "lastAction": {"email": "oscar@superannotate.com", "timestamp": 1688562794392}, "projectId": 129671, "isPredicted": false, "status": "InProgress", "pinned": false, "annotatorEmail": null, "qaEmail": null}, "instances": [{"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1172.94, "x2": 1317.53, "y1": 472.77, "y2": 718.44}, "groupId": 0, "pointLabels": {}, "locked": true, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.561Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.561Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1494.4, "x2": 1693.63, "y1": 677.37, "y2": 929.78}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": true, "createdAt": "2023-04-03T10:48:48.561Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-21T13:58:54.331Z", "updatedBy": {"email": "leo@superannotate.com", "role": "Admin"}, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1305.28, "x2": 1538.77, "y1": 3.95, "y2": 509.11}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": true, "createdAt": "2023-04-03T10:48:48.561Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-05-29T13:37:55.595Z", "updatedBy": {"email": "leo@superannotate.com", "role": "Admin"}, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1466.86, "x2": 1619.75, "y1": 167.07, "y2": 462.5}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.561Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-05-11T19:34:33.333Z", "updatedBy": {"email": "satenik@superannotate.com", "role": "Admin"}, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 704, "x2": 920.9, "y1": 783.61, "y2": 1237.03}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": true, "createdAt": "2023-04-03T10:48:48.561Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-06-12T13:20:49.923Z", "updatedBy": {"email": "leo@superannotate.com", "role": "Admin"}, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 829.63, "x2": 1023.61, "y1": 586.13, "y2": 943.57}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.561Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.561Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 981.08, "x2": 1218.37, "y1": 232.77, "y2": 648.6}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "trackingId": null, "error": false, "createdAt": "2023-05-29T13:37:06.204Z", "createdBy": {"email": "leo@superannotate.com", "role": "Admin"}, "creationType": "Manual", "updatedAt": "2023-07-05T13:13:14.392Z", "updatedBy": {"role": "Admin", "email": "oscar@superannotate.com"}, "className": "CDY"}, {"type": "polygon", "classId": 1576711, "points": [1067, 224, 1059, 229, 1053, 244, 1031, 257, 1022, 271, 1022, 291, 1036.17, 302.19, 1045.81, 305.4, 1050.3, 319.53, 1040, 319, 1022, 320, 1016, 324, 1012, 332, 1006, 357, 1009, 377, 1002, 387, 1000, 395, 1004, 408, 1001, 437, 1008, 454, 1008, 461, 996, 473, 994, 480, 997, 489, 1002, 494, 1012, 498, 1026, 499, 1031, 505, 1021, 540, 1021, 550, 1025, 561, 1025, 570, 1021, 581, 1024, 594, 1036, 604, 1058, 606, 1069, 616, 1077, 617, 1100, 608, 1129, 609, 1135, 605, 1138, 586, 1151, 568, 1157, 540, 1182, 518, 1184, 496, 1188, 485, 1206, 476, 1212, 469, 1214, 458, 1209, 445, 1209, 437, 1214, 425, 1215, 412, 1209, 389, 1215, 372, 1216, 340, 1201, 331, 1183, 309, 1167, 301, 1150, 279, 1141, 276, 1131, 280, 1127, 277, 1132, 260, 1132, 248, 1126, 240, 1113, 235, 1097, 235, 1080, 225], "groupId": 0, "pointLabels": {}, "locked": true, "attributes": [], "error": null, "createdAt": "2023-05-29T13:37:25.539Z", "createdBy": {"email": "leo@superannotate.com", "role": "Admin"}, "creationType": "Manual", "updatedAt": "2023-05-29T13:37:40.406Z", "updatedBy": {"email": "leo@superannotate.com", "role": "Admin"}, "exclude": [], "className": "CDY"}], "comments": [{"correspondence": [{"text": "This is not annotated", "email": "leo@superannotate.com"}], "x": 1098.74, "y": 441.81, "resolved": false, "createdAt": "2023-04-21T13:58:59.854Z", "createdBy": {"email": "leo@superannotate.com", "role": "Admin"}, "creationType": "Manual", "updatedAt": "2023-04-21T13:59:04.377Z", "updatedBy": {"email": "leo@superannotate.com", "role": "Admin"}}, {"correspondence": [{"text": "This bounding box needs to be tighter", "email": "leo@superannotate.com"}], "x": 1360.12, "y": 280.21, "resolved": false, "createdAt": "2023-05-29T13:38:03.180Z", "createdBy": {"email": "leo@superannotate.com", "role": "Admin"}, "creationType": "Manual", "updatedAt": "2023-05-29T13:38:12.492Z", "updatedBy": {"email": "leo@superannotate.com", "role": "Admin"}}], "tags": []}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata": {"height": 1365, "width": 2048, "name": "CDY_2017.jpg", "lastAction": {"email": "satenik@superannotate.com", "timestamp": 1686080932314}, "projectId": 129671, "isPredicted": false, "status": "Completed", "pinned": false, "annotatorEmail": null, "qaEmail": null}, "instances": [{"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 174.9, "x2": 319.9, "y1": 512.01, "y2": 732.05}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": true, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-06-06T19:48:44.628Z", "updatedBy": {"email": "satenik@superannotate.com", "role": "Admin"}, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 441.86, "x2": 573.95, "y1": 723.93, "y2": 906.97}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 654.03, "x2": 773.02, "y1": 678, "y2": 917.96}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 766.98, "x2": 868.97, "y1": 747, "y2": 859.06}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 783.97, "x2": 962.97, "y1": 452.98, "y2": 636.02}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 994, "x2": 1115.03, "y1": 337.97, "y2": 512.97}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1007.92, "x2": 1199, "y1": 633.02, "y2": 896.05}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1302.94, "x2": 1495.04, "y1": 606.06, "y2": 775.05}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1324.03, "x2": 1652.94, "y1": 405, "y2": 684}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1515.01, "x2": 1749.09, "y1": 539.04, "y2": 895.03}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 915.87, "x2": 1114.93, "y1": 716.08, "y2": 1012.01}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}, {"type": "bbox", "classId": 1576711, "probability": 100, "points": {"x1": 1.02, "x2": 37.07, "y1": 741.95, "y2": 851.01}, "groupId": 0, "pointLabels": {}, "locked": false, "attributes": [], "error": null, "createdAt": "2023-04-03T10:48:48.439Z", "createdBy": null, "creationType": "Preannotation", "updatedAt": "2023-04-03T10:48:48.439Z", "updatedBy": null, "className": "CDY"}], "comments": [{"correspondence": [{"text": "change it", "email": "satenik@superannotate.com"}], "x": 870.62, "y": 560.47, "resolved": false, "createdAt": "2023-06-06T19:48:47.840Z", "createdBy": {"email": "satenik@superannotate.com", "role": "Admin"}, "creationType": "Manual", "updatedAt": "2023-06-06T19:48:52.314Z", "updatedBy": {"email": "satenik@superannotate.com", "role": "Admin"}}], "tags": []}

0 commit comments

Comments
 (0)