Skip to content

Commit

Permalink
[PY-557] E2E test for Semantic Mask conversion (#761)
Browse files Browse the repository at this point in the history
* add semantic_mask e2e test - data and cli

* add prints

* fix newline bug in windows

* rm prints
  • Loading branch information
saurbhc authored Jan 9, 2024
1 parent ad3da18 commit e048d80
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 1 deletion.
2 changes: 1 addition & 1 deletion darwin/exporter/formats/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def export(
image = Image.fromarray(mask)
image.save(outfile)

with open(output_dir / "class_mapping.csv", "w") as f:
with open(output_dir / "class_mapping.csv", "w", newline="") as f:
writer = csv_writer(f)
writer.writerow(["class_name", "class_color"])

Expand Down
1 change: 1 addition & 0 deletions e2e_tests/cli/convert/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def compare_directories(self, path: Path, expected_path: Path) -> None:
reason="File paths are different on Windows, leading to test failure",
),
),
("semantic_mask", data_path / "semantic_mask/from", data_path / "semantic_mask/to"),
],
)
def test_darwin_convert(
Expand Down
257 changes: 257 additions & 0 deletions e2e_tests/data/semantic_mask/from/221b-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
{
"version": "2.0",
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json",
"item": {
"name": "221b-2.jpeg",
"path": "/",
"source_info": {
"item_id": "018cc9c5-9c6a-a4b7-2bf3-31182f29d6b2",
"team": {
"name": "Rafal's Team",
"slug": "rafals-team"
},
"dataset": {
"name": "saurabh-test-semantic-mask",
"slug": "saurabh-test-semantic-mask",
"dataset_management_url": "https://staging.v7labs.com/datasets/75623/dataset-management"
},
"workview_url": "https://staging.v7labs.com/workview?dataset=75623&item=018cc9c5-9c6a-a4b7-2bf3-31182f29d6b2"
},
"slots": [
{
"type": "image",
"slot_name": "0",
"width": 626,
"height": 1024,
"thumbnail_url": "https://staging.v7labs.com/api/v2/teams/rafals-team/files/123f67c9-950c-4358-a344-13e1ba6b3ca5/thumbnail",
"source_files": [
{
"file_name": "221b-2.jpeg",
"url": "https://staging.v7labs.com/api/v2/teams/rafals-team/uploads/d481a3c0-c35c-436c-85c6-ac522fcb0680"
}
]
}
]
},
"annotations": [
{
"id": "d5c61932-45cd-42a2-bf88-fed8d7e5a9fc",
"name": "__raster_layer__",
"properties": [],
"raster_layer": {
"dense_rle": [
0,
192527,
1,
4,
0,
13,
1,
26,
0,
581,
1,
47,
0,
579,
1,
47,
0,
578,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
50,
0,
576,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
48,
0,
578,
1,
48,
0,
578,
1,
48,
0,
578,
1,
47,
0,
579,
1,
47,
0,
579,
1,
48,
0,
579,
1,
47,
0,
579,
1,
47,
0,
579,
1,
47,
0,
578,
1,
48,
0,
578,
1,
48,
0,
578,
1,
48,
0,
578,
1,
49,
0,
577,
1,
49,
0,
577,
1,
50,
0,
576,
1,
50,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
49,
0,
577,
1,
48,
0,
579,
1,
47,
0,
579,
1,
47,
0,
580,
1,
45,
0,
581,
1,
45,
0,
583,
1,
41,
0,
419659
],
"mask_annotation_ids_mapping": {
"6850da86-a46b-422a-bb0b-4f650c2e0c4e": 1
},
"total_pixels": 641024
},
"slot_names": [
"0"
]
},
{
"id": "6850da86-a46b-422a-bb0b-4f650c2e0c4e",
"mask": {},
"name": "box",
"properties": [],
"slot_names": [
"0"
]
}
]
}
4 changes: 4 additions & 0 deletions e2e_tests/data/semantic_mask/to/class_mapping.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class_name,class_color
__background__,0 0 0
__raster_layer__,255 50 50
box,50 255 50

0 comments on commit e048d80

Please sign in to comment.