diff --git a/e2e_tests/cli/__init__.py b/e2e_tests/cli/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/e2e_tests/cli/convert/__init__.py b/e2e_tests/cli/convert/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/e2e_tests/cli/convert/test_convert.py b/e2e_tests/cli/convert/test_convert.py new file mode 100644 index 000000000..f5f93c83c --- /dev/null +++ b/e2e_tests/cli/convert/test_convert.py @@ -0,0 +1,71 @@ +from os.path import dirname +from pathlib import Path +from typing import Tuple + +import pytest + +from e2e_tests.helpers import assert_cli, run_cli_command + + +class TestExportCli: + this_file_path = Path(dirname(__file__)).absolute() + data_path = (this_file_path / ".." / ".." / "data").resolve() + + @pytest.fixture(autouse=True) + def config(self) -> None: + assert self.data_path.exists(), "Data path does not exist, tests cannot run" + + def compare_directories(self, path: Path, expected_path: Path) -> Tuple[bool, str]: + """ + Compare two directories recursively + """ + assert path.exists() and expected_path.exists() + assert path.is_dir() and expected_path.is_dir() + + for file in path.iterdir(): + if file.is_dir(): + # Recursively compare directories + result = self.compare_directories(file, expected_path / file.name) + if not result[0]: + return result + else: + if file.name.startswith("."): + # Ignore hidden files + continue + + # Compare files + with file.open("r") as f: + content = f.read() + + with Path(expected_path / file.name).open() as f: + expected_content = f.read() + + if content != expected_content: + return (False, f"File {file} does not match expected file") + + return (True, "") + + @pytest.mark.parametrize( + "format, input_path, expectation_path", + [("yolo_segmented", data_path / "yolov8/from", data_path / "yolov8/to")], + ) + def test_darwin_convert(self, format: str, input_path: Path, expectation_path: Path, tmp_path: Path) -> None: + """ + Test converting a file format to another format + """ + assert input_path is not None and expectation_path is not None, "Input or expectation path is None" + assert ( + input_path.exists() and expectation_path.exists() + ), f"Input path {input_path.absolute()} or expectation path {expectation_path.absolute()} does not exist" + assert ( + input_path.is_dir() and expectation_path.is_dir() + ), f"Input path {input_path.absolute()} or expectation path {expectation_path.absolute()} is not a directory" + + result = run_cli_command(f"darwin convert {format} {str(input_path)} {str(tmp_path)}") + + assert_cli(result, 0) + assert self.compare_directories(expectation_path, tmp_path)[0] + + +if __name__ == "__main__": + pytest.main(["-vv", "-s", __file__]) diff --git a/e2e_tests/data/yolov8/from/test_input_with_bboxes_and_polys.json b/e2e_tests/data/yolov8/from/test_input_with_bboxes_and_polys.json new file mode 100644 index 000000000..4dee13356 --- /dev/null +++ b/e2e_tests/data/yolov8/from/test_input_with_bboxes_and_polys.json @@ -0,0 +1,839 @@ +{ + "version": "2.0", + "schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json", + "item": { + "name": "test2.png", + "path": "/", + "source_info": { + "dataset": { + "name": "test-1692", + "slug": "test-1692", + "dataset_management_url": "https://staging.v7labs.com/datasets/37551/dataset-management" + }, + "item_id": "018afa47-77aa-13d3-c39e-ed5fa1687f8e", + "team": { + "name": "E2E Testing", + "slug": "e2e-testing" + }, + "workview_url": "https://staging.v7labs.com/workview?dataset=37551&item=018afa47-77aa-13d3-c39e-ed5fa1687f8e" + }, + "slots": [ + { + "type": "image", + "slot_name": "0", + "width": 500, + "height": 500, + "thumbnail_url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/files/04a443cd-7e67-4dca-a892-4885eb57f687/thumbnail", + "source_files": [ + { + "file_name": "test2.png", + "url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/uploads/ea2c7c7a-ac58-4f97-99a7-b9e96399164c" + } + ] + } + ] + }, + "annotations": [ + { + "bounding_box": { + "h": 171.37, + "w": 196.78999999999996, + "x": 89.98, + "y": 122.7 + }, + "id": "12625a60-5e96-44fb-bb39-4218748a7eb3", + "name": "test_poly", + "polygon": { + "paths": [ + [ + { + "x": 154.82, + "y": 247.82 + }, + { + "x": 145.96, + "y": 266.78 + }, + { + "x": 137.03, + "y": 258.22 + }, + { + "x": 158.18, + "y": 242.01 + } + ], + [ + { + "x": 197.21, + "y": 134.77 + }, + { + "x": 196.52, + "y": 132.7 + }, + { + "x": 190.74, + "y": 132.7 + }, + { + "x": 181.97, + "y": 134.36 + }, + { + "x": 162.92, + "y": 140.29 + }, + { + "x": 150.85, + "y": 146.01 + }, + { + "x": 142.59, + "y": 151.73 + }, + { + "x": 138.07, + "y": 156.25 + }, + { + "x": 125.36, + "y": 172.77 + }, + { + "x": 120.91, + "y": 179.76 + }, + { + "x": 112.65, + "y": 196.27 + }, + { + "x": 106.3, + "y": 212.16 + }, + { + "x": 100.59, + "y": 229.82 + }, + { + "x": 99.98, + "y": 251.59 + }, + { + "x": 100.62, + "y": 259.21 + }, + { + "x": 104.83, + "y": 267.55 + }, + { + "x": 110.1, + "y": 267.12 + }, + { + "x": 122.63, + "y": 257.14 + }, + { + "x": 120.51, + "y": 254.72 + }, + { + "x": 115.43, + "y": 243.92 + }, + { + "x": 114.12, + "y": 238.88 + }, + { + "x": 114.76, + "y": 218.55 + }, + { + "x": 123.05, + "y": 190.64 + }, + { + "x": 131.95, + "y": 172.85 + }, + { + "x": 140.21, + "y": 160.78 + }, + { + "x": 152.84, + "y": 149.42 + }, + { + "x": 162.37, + "y": 143.07 + }, + { + "x": 169.36, + "y": 139.89 + }, + { + "x": 185.83, + "y": 134.77 + } + ], + [ + { + "x": 197.76, + "y": 144.77 + }, + { + "x": 186.66, + "y": 144.77 + }, + { + "x": 174.36, + "y": 148.55 + }, + { + "x": 164.19, + "y": 153.63 + }, + { + "x": 155.3, + "y": 159.98 + }, + { + "x": 148.05, + "y": 166.79 + }, + { + "x": 140.61, + "y": 177.85 + }, + { + "x": 131.71, + "y": 195.64 + }, + { + "x": 125.29, + "y": 215.89 + }, + { + "x": 124.12, + "y": 225.54 + }, + { + "x": 124.12, + "y": 238.88 + }, + { + "x": 130.29, + "y": 251.01 + }, + { + "x": 180.46, + "y": 211.69 + }, + { + "x": 193.53, + "y": 178.04 + }, + { + "x": 196.08, + "y": 168.36 + }, + { + "x": 197.35, + "y": 157.56 + } + ], + [ + { + "x": 276.77, + "y": 240.15 + }, + { + "x": 276.77, + "y": 228.08 + }, + { + "x": 276.08, + "y": 225.32 + }, + { + "x": 269.81, + "y": 212.79 + }, + { + "x": 264.73, + "y": 204.53 + }, + { + "x": 258.53, + "y": 196.68 + }, + { + "x": 252.04, + "y": 191.82 + }, + { + "x": 247.46, + "y": 189.88 + }, + { + "x": 232.21, + "y": 189.24 + }, + { + "x": 225.17, + "y": 191.12 + }, + { + "x": 208.66, + "y": 201.28 + }, + { + "x": 191.45, + "y": 215.44 + }, + { + "x": 193.34, + "y": 217.96 + }, + { + "x": 195.28, + "y": 224.9 + }, + { + "x": 197.82, + "y": 237.61 + }, + { + "x": 197.15, + "y": 240.11 + }, + { + "x": 195.32, + "y": 241.94 + }, + { + "x": 192.82, + "y": 242.61 + }, + { + "x": 190.32, + "y": 241.94 + }, + { + "x": 188.49, + "y": 240.11 + }, + { + "x": 185.33, + "y": 225.25 + }, + { + "x": 167.93, + "y": 261.08 + }, + { + "x": 159.78, + "y": 275.55 + }, + { + "x": 168.6, + "y": 278.69 + }, + { + "x": 178.31, + "y": 280.98 + }, + { + "x": 197.27, + "y": 283.44 + }, + { + "x": 232.21, + "y": 284.07 + }, + { + "x": 243.32, + "y": 281.9 + }, + { + "x": 252.58, + "y": 277.75 + }, + { + "x": 268.54, + "y": 263.07 + }, + { + "x": 274.26, + "y": 253.54 + }, + { + "x": 276.13, + "y": 244.6 + } + ], + [ + { + "x": 286.77, + "y": 240.15 + }, + { + "x": 286.77, + "y": 228.08 + }, + { + "x": 285.5, + "y": 223.0 + }, + { + "x": 278.47, + "y": 207.79 + }, + { + "x": 273.39, + "y": 199.53 + }, + { + "x": 266.4, + "y": 190.64 + }, + { + "x": 256.95, + "y": 183.09 + }, + { + "x": 247.46, + "y": 179.88 + }, + { + "x": 232.21, + "y": 179.24 + }, + { + "x": 220.18, + "y": 182.46 + }, + { + "x": 215.1, + "y": 185.0 + }, + { + "x": 196.4, + "y": 198.36 + }, + { + "x": 202.23, + "y": 182.93 + }, + { + "x": 206.08, + "y": 168.36 + }, + { + "x": 207.35, + "y": 157.56 + }, + { + "x": 207.77, + "y": 144.51 + }, + { + "x": 209.3, + "y": 144.1 + }, + { + "x": 211.13, + "y": 142.27 + }, + { + "x": 211.8, + "y": 139.77 + }, + { + "x": 211.13, + "y": 137.27 + }, + { + "x": 209.3, + "y": 135.44 + }, + { + "x": 207.4, + "y": 134.93 + }, + { + "x": 204.77, + "y": 126.47 + }, + { + "x": 202.94, + "y": 124.64 + }, + { + "x": 197.9, + "y": 122.7 + }, + { + "x": 190.28, + "y": 122.7 + }, + { + "x": 180.75, + "y": 124.61 + }, + { + "x": 157.92, + "y": 131.63 + }, + { + "x": 145.85, + "y": 137.35 + }, + { + "x": 137.59, + "y": 143.07 + }, + { + "x": 123.05, + "y": 158.87 + }, + { + "x": 112.25, + "y": 174.76 + }, + { + "x": 100.82, + "y": 198.9 + }, + { + "x": 90.62, + "y": 229.35 + }, + { + "x": 89.98, + "y": 240.15 + }, + { + "x": 90.62, + "y": 259.21 + }, + { + "x": 91.92, + "y": 264.25 + }, + { + "x": 96.37, + "y": 273.15 + }, + { + "x": 99.47, + "y": 276.25 + }, + { + "x": 103.24, + "y": 277.55 + }, + { + "x": 109.59, + "y": 277.55 + }, + { + "x": 114.63, + "y": 276.25 + }, + { + "x": 129.29, + "y": 264.14 + }, + { + "x": 142.25, + "y": 276.37 + }, + { + "x": 142.08, + "y": 286.53 + }, + { + "x": 142.75, + "y": 289.03 + }, + { + "x": 144.58, + "y": 290.86 + }, + { + "x": 147.08, + "y": 291.53 + }, + { + "x": 149.58, + "y": 290.86 + }, + { + "x": 154.61, + "y": 284.12 + }, + { + "x": 164.27, + "y": 287.68 + }, + { + "x": 177.57, + "y": 290.9 + }, + { + "x": 197.27, + "y": 293.44 + }, + { + "x": 232.21, + "y": 294.07 + }, + { + "x": 251.23, + "y": 289.59 + }, + { + "x": 257.58, + "y": 286.41 + }, + { + "x": 260.76, + "y": 283.87 + }, + { + "x": 277.2, + "y": 268.07 + }, + { + "x": 282.92, + "y": 258.54 + }, + { + "x": 286.13, + "y": 244.6 + } + ] + ] + }, + "slot_names": [ + "0" + ] + }, + { + "bounding_box": { + "h": 105.33, + "w": 155.33, + "x": 297.33, + "y": 56.0 + }, + "id": "8cde0f3c-f54a-41fd-a362-3c3ab371bbea", + "name": "bbox", + "slot_names": [ + "0" + ] + }, + { + "bounding_box": { + "h": 91.33, + "w": 149.33, + "x": 308.67, + "y": 256.67 + }, + "id": "132284e2-d231-4183-8385-80847591736b", + "name": "bbox", + "slot_names": [ + "0" + ] + }, + { + "bounding_box": { + "h": 47.33, + "w": 52.0, + "x": 190.0, + "y": 352.67 + }, + "id": "840ec567-bb79-4570-a13c-53956dfa3cad", + "name": "bbox", + "slot_names": [ + "0" + ] + }, + { + "bounding_box": { + "h": 54.419999999999995, + "w": 63.74999999999999, + "x": 32.46, + "y": 43.79 + }, + "id": "d865c6bd-f1cb-4aea-9a7f-a4de36ff4c51", + "name": "test_poly", + "polygon": { + "paths": [ + [ + { + "x": 96.21, + "y": 62.67 + }, + { + "x": 95.47, + "y": 55.9 + }, + { + "x": 93.44, + "y": 53.87 + }, + { + "x": 90.67, + "y": 53.12 + }, + { + "x": 87.46, + "y": 53.63 + }, + { + "x": 86.8, + "y": 50.56 + }, + { + "x": 83.44, + "y": 47.2 + }, + { + "x": 78.67, + "y": 46.46 + }, + { + "x": 74.56, + "y": 47.87 + }, + { + "x": 73.0, + "y": 49.43 + }, + { + "x": 68.1, + "y": 44.53 + }, + { + "x": 65.33, + "y": 43.79 + }, + { + "x": 55.9, + "y": 46.53 + }, + { + "x": 49.38, + "y": 52.63 + }, + { + "x": 47.23, + "y": 53.2 + }, + { + "x": 43.87, + "y": 56.56 + }, + { + "x": 35.87, + "y": 70.56 + }, + { + "x": 32.46, + "y": 83.33 + }, + { + "x": 32.46, + "y": 92.0 + }, + { + "x": 33.2, + "y": 94.77 + }, + { + "x": 35.23, + "y": 96.8 + }, + { + "x": 39.33, + "y": 98.21 + }, + { + "x": 46.77, + "y": 96.8 + }, + { + "x": 49.67, + "y": 94.57 + }, + { + "x": 53.23, + "y": 97.47 + }, + { + "x": 56.0, + "y": 98.21 + }, + { + "x": 58.77, + "y": 97.47 + }, + { + "x": 61.47, + "y": 94.77 + }, + { + "x": 64.92, + "y": 87.16 + }, + { + "x": 66.56, + "y": 88.8 + }, + { + "x": 69.33, + "y": 89.54 + }, + { + "x": 74.1, + "y": 88.8 + }, + { + "x": 75.67, + "y": 87.24 + }, + { + "x": 78.67, + "y": 88.21 + }, + { + "x": 81.44, + "y": 87.47 + }, + { + "x": 86.8, + "y": 82.1 + }, + { + "x": 92.8, + "y": 74.1 + }, + { + "x": 96.21, + "y": 62.67 + } + ] + ] + }, + "slot_names": [ + "0" + ] + } + ] +} \ No newline at end of file diff --git a/e2e_tests/data/yolov8/to/darknet.labels b/e2e_tests/data/yolov8/to/darknet.labels new file mode 100644 index 000000000..2ac86ac5c --- /dev/null +++ b/e2e_tests/data/yolov8/to/darknet.labels @@ -0,0 +1,2 @@ +bbox +test_poly