Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PY-557] E2E test for Semantic Mask conversion #761

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member Author

@saurbhc saurbhc Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In windows, the files generated by the convert cli command have an extra line in b/w every row, which fails the e2e test - as it fails to compare the output and expected file content, but works perfectly fine on linux/macos for some reason. Found the fix from these links:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a difference between line endings for Windows and Linux/Posix being interpreted different by the writer (\r\n vs \n), but couldn't swear to it.

Either way, you've solved it. Nice one.

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
Loading