From e048d803654bebb06bbc2e949cc7af27edcc0979 Mon Sep 17 00:00:00 2001 From: saurbhc Date: Tue, 9 Jan 2024 10:23:19 +0000 Subject: [PATCH] [PY-557] E2E test for Semantic Mask conversion (#761) * add semantic_mask e2e test - data and cli * add prints * fix newline bug in windows * rm prints --- darwin/exporter/formats/mask.py | 2 +- e2e_tests/cli/convert/test_convert.py | 1 + e2e_tests/data/semantic_mask/from/221b-2.json | 257 ++++++++++++++++++ .../data/semantic_mask/to/class_mapping.csv | 4 + 4 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 e2e_tests/data/semantic_mask/from/221b-2.json create mode 100644 e2e_tests/data/semantic_mask/to/class_mapping.csv diff --git a/darwin/exporter/formats/mask.py b/darwin/exporter/formats/mask.py index 78e7037db..0ae38e2c2 100644 --- a/darwin/exporter/formats/mask.py +++ b/darwin/exporter/formats/mask.py @@ -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"]) diff --git a/e2e_tests/cli/convert/test_convert.py b/e2e_tests/cli/convert/test_convert.py index c3c13cec2..ae197ab61 100644 --- a/e2e_tests/cli/convert/test_convert.py +++ b/e2e_tests/cli/convert/test_convert.py @@ -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( diff --git a/e2e_tests/data/semantic_mask/from/221b-2.json b/e2e_tests/data/semantic_mask/from/221b-2.json new file mode 100644 index 000000000..19bdb37cc --- /dev/null +++ b/e2e_tests/data/semantic_mask/from/221b-2.json @@ -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" + ] + } + ] +} \ No newline at end of file diff --git a/e2e_tests/data/semantic_mask/to/class_mapping.csv b/e2e_tests/data/semantic_mask/to/class_mapping.csv new file mode 100644 index 000000000..6db1b8b29 --- /dev/null +++ b/e2e_tests/data/semantic_mask/to/class_mapping.csv @@ -0,0 +1,4 @@ +class_name,class_color +__background__,0 0 0 +__raster_layer__,255 50 50 +box,50 255 50