Skip to content

Commit 2426228

Browse files
committed
Fix coco-convert-empty-array
1 parent 04f1228 commit 2426228

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

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))
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]}]}

tests/converter_test/test_conversion.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,22 @@ def test_instance_segmentation_sa2coco_vector(tmpdir):
9494
input_dir, out_path, "COCO", "instance_test_vector", "Vector",
9595
"instance_segmentation"
9696
)
97+
98+
99+
def test_instance_segmentation_sa2coco_vector_empty_array(tmpdir):
100+
input_dir = Path(
101+
"tests"
102+
) / "converter_test" / "COCO" / "input" / "fromSuperAnnotate" / "cats_dogs_vector_instance_segm_empty_array"
103+
out_path = Path(tmpdir) / "fromSuperAnnotate" / "instance_test_vector"
104+
sa.export_annotation(
105+
input_dir, out_path, "COCO", "instance_test_vector", "Vector",
106+
"instance_segmentation"
107+
)
108+
import json
109+
json_path = out_path / "instance_test_vector.json"
110+
with open(json_path, 'r') as f:
111+
data = json.loads(f.read())
112+
truth_path = input_dir / "truth.json"
113+
with open(truth_path, 'r') as f:
114+
truth = json.loads(f.read())
115+
assert truth == data

0 commit comments

Comments
 (0)