def test_copy_images3(tmpdir): PROJECT_NAME = "test copy3 folder images" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") sa.create_folder(project, "folder1") project = PROJECT_NAME + "/folder1" sa.copy_images(PROJECT_NAME, ["example_image_2.jpg", "example_image_3.jpg"], project, include_annotations=False, copy_annotation_status=False, copy_pin=False) num_images = sa.get_project_image_count(project) assert num_images == 2 num_images = sa.get_project_image_count(PROJECT_NAME) assert num_images == 4
def test_move_images2(tmpdir): PROJECT_NAME = "test move folder images2" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.create_folder(project, "folder1") project = PROJECT_NAME + "/folder1" sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") num_images = sa.get_project_image_count(project) assert num_images == 4 sa.create_folder(PROJECT_NAME, "folder2") project2 = PROJECT_NAME + "/folder2" num_images = sa.get_project_image_count(project2) assert num_images == 0 sa.move_images(project, None, project2) num_images = sa.get_project_image_count(project2) assert num_images == 4 num_images = sa.get_project_image_count(project) assert num_images == 0
def test_delete_images(tmpdir): PROJECT_NAME = "test delete folder images" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.create_folder(project, "folder1") project = project["name"] + "/folder1" sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") num_images = sa.get_project_image_count(project) assert num_images == 4 sa.delete_images(project, ["example_image_2.jpg", "example_image_3.jpg"]) num_images = sa.get_project_image_count(project) assert num_images == 2 sa.delete_images(project, None) num_images = sa.get_project_image_count(project) assert num_images == 0
def test_project_folder_image_count(tmpdir): PROJECT_NAME = "test folder image count" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') project = project["name"] sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") num_images = sa.get_project_image_count(project) assert num_images == 4 sa.create_folder(project, "folder1") sa.upload_images_from_folder_to_project(project + "/folder1", FROM_FOLDER, annotation_status="InProgress") num_images = sa.get_project_image_count(project) assert num_images == 4 num_images = sa.get_project_image_count(project + "/folder1") assert num_images == 4 num_images = sa.get_project_image_count(project, with_all_subfolders=True) assert num_images == 8
def test_copy_images(tmpdir): PROJECT_NAME = "test copy folder images" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.create_folder(project, "folder1") project = PROJECT_NAME + "/folder1" sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") num_images = sa.get_project_image_count(project) assert num_images == 4 im1 = sa.get_image_metadata(project, "example_image_2.jpg") assert im1["annotation_status"] == "InProgress" sa.create_folder(PROJECT_NAME, "folder2") project2 = PROJECT_NAME + "/folder2" num_images = sa.get_project_image_count(project2) assert num_images == 0 sa.copy_images(project, ["example_image_2.jpg", "example_image_3.jpg"], project2, include_annotations=False, copy_annotation_status=False, copy_pin=False) im1_copied = sa.get_image_metadata(project2, "example_image_2.jpg") assert im1_copied["annotation_status"] == "NotStarted" ann2 = sa.get_image_annotations(project2, "example_image_2.jpg") assert len(ann2["annotation_json"]["instances"]) == 0 num_images = sa.get_project_image_count(project2) assert num_images == 2 res = sa.copy_images(project, None, project2) num_images = sa.get_project_image_count(project2) assert num_images == 4 assert res == 2 sa.copy_images(project, ["example_image_2.jpg", "example_image_3.jpg"], PROJECT_NAME, include_annotations=False, copy_annotation_status=False, copy_pin=False) num_images = sa.get_project_image_count(PROJECT_NAME) assert num_images == 2
def test_folder_export(tmpdir): PROJECT_NAME = "test folder export" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.create_annotation_classes_from_classes_json( project, FROM_FOLDER / "classes" / "classes.json") sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") sa.create_folder(project, "folder1") project = PROJECT_NAME + "/folder1" sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") sa.upload_annotations_from_folder_to_project(project, FROM_FOLDER) num_images = sa.get_project_image_count(project) assert num_images == 4 sa.create_folder(PROJECT_NAME, "folder2") project2 = PROJECT_NAME + "/folder2" num_images = sa.get_project_image_count(project2) assert num_images == 0 sa.copy_images(project, ["example_image_2.jpg", "example_image_3.jpg"], project2) export = sa.prepare_export(PROJECT_NAME, ["folder1", "folder2"]) sa.download_export(project, export, tmpdir) assert len(list((tmpdir / "classes").rglob("*"))) == 1 assert len(list((tmpdir / "folder1").rglob("*"))) == 4 assert len(list((tmpdir / "folder2").rglob("*"))) == 2 assert len(list((tmpdir).glob("*.*"))) == 0 export = sa.prepare_export(PROJECT_NAME) sa.download_export(project, export, tmpdir) assert len(list((tmpdir / "classes").rglob("*"))) == 1 assert len(list((tmpdir / "folder1").rglob("*"))) == 4 assert len(list((tmpdir / "folder2").rglob("*"))) == 2 assert len(list((tmpdir).glob("*.*"))) == 4
def test_copy_images2(tmpdir): PROJECT_NAME = "test copy folder annotation images" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.create_annotation_classes_from_classes_json( project, FROM_FOLDER / "classes" / "classes.json") sa.create_folder(project, "folder1") project = PROJECT_NAME + "/folder1" sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") sa.upload_annotations_from_folder_to_project(project, FROM_FOLDER) num_images = sa.get_project_image_count(project) assert num_images == 4 sa.create_folder(PROJECT_NAME, "folder2") project2 = PROJECT_NAME + "/folder2" num_images = sa.get_project_image_count(project2) assert num_images == 0 sa.pin_image(project, "example_image_2.jpg") im1 = sa.get_image_metadata(project, "example_image_2.jpg") assert im1["is_pinned"] == 1 assert im1["annotation_status"] == "InProgress" sa.copy_images(project, ["example_image_2.jpg", "example_image_3.jpg"], project2) num_images = sa.get_project_image_count(project2) assert num_images == 2 ann1 = sa.get_image_annotations(project, "example_image_2.jpg") ann2 = sa.get_image_annotations(project2, "example_image_2.jpg") assert ann1 == ann2 im1_copied = sa.get_image_metadata(project2, "example_image_2.jpg") assert im1_copied["is_pinned"] == 1 assert im1_copied["annotation_status"] == "InProgress" im2_copied = sa.get_image_metadata(project2, "example_image_3.jpg") assert im2_copied["is_pinned"] == 0 assert im2_copied["annotation_status"] == "InProgress"
def test_direct_s3_upload(): projects_found = sa.search_projects(TEST_PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(TEST_PROJECT_NAME, "a", "Vector") print(project["id"]) csv = (Path.home() / ".aws" / "credentials").read_text().splitlines() access_key_id = csv[1].split(" = ")[1] access_secret = csv[2].split(" = ")[1] sa.upload_images_from_s3_bucket_to_project(project, access_key_id, access_secret, S3_BUCKET, S3_FOLDER) s3_client = boto3.client('s3') paginator = s3_client.get_paginator('list_objects_v2') response_iterator = paginator.paginate(Bucket=S3_BUCKET, Prefix=S3_FOLDER) on_s3 = [] for response in response_iterator: if 'Contents' in response: for object_data in response['Contents']: key = object_data['Key'] if key[-4:] in [".jpg", ".png"]: on_s3.append(key) assert len(on_s3) == sa.get_project_image_count(project)
def test_vector_preannotation_upload_from_s3(tmpdir): projects_found = sa.search_projects(TEST_PROJECT3, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(TEST_PROJECT3, "hk_test", project_type="Vector") f = urlparse(f"s3://superannotate-python-sdk-test/{TEST_PROJECT_VECTOR}") sa.upload_images_from_folder_to_project(project, f.path[1:], annotation_status="NotStarted", from_s3_bucket=f.netloc) sa.create_annotation_classes_from_classes_json(project, f.path[1:] + '/classes/classes.json', from_s3_bucket=f.netloc) assert sa.get_project_image_count(project) == 4 sa.upload_preannotations_from_folder_to_project(project, TEST_PROJECT_VECTOR, from_s3_bucket=f.netloc) for image in sa.search_images(project): sa.download_image_preannotations(project, image, tmpdir) assert len(list(Path(tmpdir).glob("*.*"))) == 4 sa.delete_project(project)
def test_download_stress(tmpdir): project = sa.search_projects(name_prefix="test_test_15")[0] export = sa.prepare_export(project) sa.download_export(project, export, tmpdir) count_in_project = sa.get_project_image_count(project) count_in_folder = len(list(Path(tmpdir).glob("*.jpg"))) assert count_in_project == count_in_folder
def test_upload_stress(): project = sa.create_project("test_test_15", "hk", 1) sa.create_annotation_classes_from_classes_json( project, "tests/sample_project_vector/classes/classes.json" ) sa.upload_images_from_folder_to_project( project, "/media/disc_drive/datasets/COCO/test2017", annotation_status="QualityCheck" ) count = sa.get_project_image_count(project) assert count == 40670
def test_move_images(tmpdir): PROJECT_NAME = "test move folder images1" tmpdir = Path(tmpdir) projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True) for pr in projects_found: sa.delete_project(pr) project = sa.create_project(PROJECT_NAME, 'test', 'Vector') sa.create_folder(project, "folder1") project = PROJECT_NAME + "/folder1" sa.upload_images_from_folder_to_project(project, FROM_FOLDER, annotation_status="InProgress") num_images = sa.get_project_image_count(project) assert num_images == 4 sa.create_folder(PROJECT_NAME, "folder2") project2 = PROJECT_NAME + "/folder2" num_images = sa.get_project_image_count(project2) assert num_images == 0 sa.move_images(project, ["example_image_2.jpg"], project2) num_images = sa.get_project_image_count(project2) assert num_images == 1 num_images = sa.get_project_image_count(project) assert num_images == 3 num_images = sa.get_project_image_count(PROJECT_NAME, with_all_subfolders=True) assert num_images == 4 images = sa.search_images_all_folders(PROJECT_NAME) assert images == [ "example_image_1.jpg", "example_image_2.jpg", "example_image_3.jpg", "example_image_4.jpg" ]
def test_upload_stress(tmpdir): tmpdir = Path(tmpdir) projects = sa.search_projects(PROJECT_NAME, return_metadata=True) for project in projects: sa.delete_project(project) project = sa.create_project(PROJECT_NAME, "hk", "Vector") sa.create_annotation_classes_from_classes_json( project, "tests/sample_project_vector/classes/classes.json" ) sa.upload_images_from_folder_to_project( project, "/media/disc_drive/datasets/COCO/test2017", annotation_status="QualityCheck" ) time.sleep(60) count = sa.get_project_image_count(project) assert count == 40670