|
| 1 | +from pathlib import Path |
| 2 | +import subprocess |
| 3 | +import time |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +import superannotate as sa |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize( |
| 11 | + "project_type,name,description,from_folder", [ |
| 12 | + ( |
| 13 | + "Vector", "Example Project test vector preannotation cli upload", |
| 14 | + "test vector", Path("./tests/sample_project_vector") |
| 15 | + ), |
| 16 | + ( |
| 17 | + "Pixel", "Example Project test pixel preannotation cli upload", |
| 18 | + "test pixel", Path("./tests/sample_project_pixel") |
| 19 | + ) |
| 20 | + ] |
| 21 | +) |
| 22 | +def test_preannotation_folder_upload_download_cli( |
| 23 | + project_type, name, description, from_folder, tmpdir |
| 24 | +): |
| 25 | + projects_found = sa.search_projects(name, return_metadata=True) |
| 26 | + for pr in projects_found: |
| 27 | + sa.delete_project(pr) |
| 28 | + |
| 29 | + project = sa.create_project(name, description, project_type) |
| 30 | + sa.upload_images_from_folder_to_project( |
| 31 | + project, from_folder, annotation_status="InProgress" |
| 32 | + ) |
| 33 | + sa.create_annotation_classes_from_classes_json( |
| 34 | + project, from_folder / "classes" / "classes.json" |
| 35 | + ) |
| 36 | + subprocess.run( |
| 37 | + [ |
| 38 | + f"superannotate upload-preannotations --project '{name}' --folder '{from_folder}'" |
| 39 | + ], |
| 40 | + check=True, |
| 41 | + shell=True |
| 42 | + ) |
| 43 | + time.sleep(5) |
| 44 | + count_in = len(list(from_folder.glob("*.json"))) |
| 45 | + |
| 46 | + images = sa.search_images(project) |
| 47 | + for image_name in images: |
| 48 | + sa.download_image_preannotations(project, image_name, tmpdir) |
| 49 | + |
| 50 | + count_out = len(list(Path(tmpdir).glob("*.json"))) |
| 51 | + |
| 52 | + assert count_in == count_out |
| 53 | + |
| 54 | + |
| 55 | +def test_preannotation_folder_upload_download_cli_vector_COCO(tmpdir): |
| 56 | + project_type = "Vector" |
| 57 | + name = "Example Project test vector preannotation cli upload coco vector" |
| 58 | + description = "test" |
| 59 | + from_folder = "./tests/converter_test/COCO/input/toSuperAnnotate/keypoint_detection" |
| 60 | + task = "keypoint_detection" |
| 61 | + dataset_name = "person_keypoints_test" |
| 62 | + |
| 63 | + projects_found = sa.search_projects(name, return_metadata=True) |
| 64 | + for pr in projects_found: |
| 65 | + sa.delete_project(pr) |
| 66 | + |
| 67 | + project = sa.create_project(name, description, project_type) |
| 68 | + sa.upload_images_from_folder_to_project( |
| 69 | + project, from_folder, annotation_status="InProgress" |
| 70 | + ) |
| 71 | + # sa.create_annotation_classes_from_classes_json( |
| 72 | + # project, from_folder / "classes" / "classes.json" |
| 73 | + # ) |
| 74 | + subprocess.run( |
| 75 | + [ |
| 76 | + f"superannotate upload-preannotations --project '{name}' --folder '{from_folder}' --format COCO --task {task} --dataset-name {dataset_name}" |
| 77 | + ], |
| 78 | + check=True, |
| 79 | + shell=True |
| 80 | + ) |
| 81 | + # time.sleep(5) |
| 82 | + # count_in = len(list(from_folder.glob("*.json"))) |
| 83 | + |
| 84 | + # images = sa.search_images(project) |
| 85 | + # for image_name in images: |
| 86 | + # sa.download_image_preannotations(project, image_name, tmpdir) |
| 87 | + |
| 88 | + # count_out = len(list(Path(tmpdir).glob("*.json"))) |
| 89 | + |
| 90 | + # assert count_in == count_out |
| 91 | + |
| 92 | + |
| 93 | +def test_preannotation_folder_upload_download_cli_vector_object_COCO(tmpdir): |
| 94 | + project_type = "Vector" |
| 95 | + name = "Example Project test vector preannotation cli upload coco object vector" |
| 96 | + description = "test" |
| 97 | + from_folder = "./tests/converter_test/COCO/input/toSuperAnnotate/instance_segmentation" |
| 98 | + task = "instance_segmentation" |
| 99 | + dataset_name = "instances_test" |
| 100 | + |
| 101 | + projects_found = sa.search_projects(name, return_metadata=True) |
| 102 | + for pr in projects_found: |
| 103 | + sa.delete_project(pr) |
| 104 | + |
| 105 | + project = sa.create_project(name, description, project_type) |
| 106 | + sa.upload_images_from_folder_to_project( |
| 107 | + project, from_folder, annotation_status="InProgress" |
| 108 | + ) |
| 109 | + # sa.create_annotation_classes_from_classes_json( |
| 110 | + # project, from_folder / "classes" / "classes.json" |
| 111 | + # ) |
| 112 | + subprocess.run( |
| 113 | + [ |
| 114 | + f"superannotate upload-preannotations --project '{name}' --folder '{from_folder}' --format COCO --task {task} --dataset-name {dataset_name}" |
| 115 | + ], |
| 116 | + check=True, |
| 117 | + shell=True |
| 118 | + ) |
| 119 | + |
| 120 | + |
| 121 | +def test_preannotation_folder_upload_download_cli_pixel_object_COCO(tmpdir): |
| 122 | + project_type = "Pixel" |
| 123 | + name = "Example Project test pixel preannotation cli upload coco object pixel" |
| 124 | + description = "test" |
| 125 | + from_folder = "./tests/converter_test/COCO/input/toSuperAnnotate/panoptic_segmentation" |
| 126 | + task = "panoptic_segmentation" |
| 127 | + dataset_name = "panoptic_test" |
| 128 | + |
| 129 | + projects_found = sa.search_projects(name, return_metadata=True) |
| 130 | + for pr in projects_found: |
| 131 | + sa.delete_project(pr) |
| 132 | + |
| 133 | + project = sa.create_project(name, description, project_type) |
| 134 | + sa.upload_images_from_folder_to_project( |
| 135 | + project, from_folder, annotation_status="InProgress" |
| 136 | + ) |
| 137 | + # sa.create_annotation_classes_from_classes_json( |
| 138 | + # project, from_folder / "classes" / "classes.json" |
| 139 | + # ) |
| 140 | + subprocess.run( |
| 141 | + [ |
| 142 | + f"superannotate upload-preannotations --project '{name}' --folder '{from_folder}' --format COCO --task {task} --dataset-name {dataset_name}" |
| 143 | + ], |
| 144 | + check=True, |
| 145 | + shell=True |
| 146 | + ) |
0 commit comments