Пример #1
0
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
Пример #2
0
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"
Пример #3
0
def test_single_image_upload_bytesio(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_BYTES,
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_BYTES, "test", "Vector")

    with open("./tests/sample_project_vector/example_image_1.jpg", "rb") as f:
        img = io.BytesIO(f.read())
    try:
        sa.upload_image_to_project(project,
                                   img,
                                   annotation_status="InProgress")
    except sa.SABaseException as e:
        assert e.message == "Image name img_name should be set if img is not Pathlike"
    else:
        assert False

    sa.upload_image_to_project(project,
                               img,
                               image_name="rr.jpg",
                               annotation_status="InProgress")
    images = sa.search_images(project)
    assert len(images) == 1
    image = images[0]
    assert sa.annotation_status_int_to_str(
        sa.get_image_metadata(project,
                              image)["annotation_status"]) == "InProgress"
    assert image == "rr.jpg"
def test_pin_image_in_folder(tmpdir):
    tmpdir = Path(tmpdir)

    projects = sa.search_projects(PROJECT_NAME2, return_metadata=True)
    for project in projects:
        sa.delete_project(project)

    project = sa.create_project(PROJECT_NAME2, "test", "Vector")
    sa.create_folder(project, FOLDER2)

    project_folder = project["name"] + "/" + FOLDER2
    sa.upload_images_from_folder_to_project(project_folder,
                                            "./tests/sample_project_vector",
                                            annotation_status="QualityCheck")

    img_metadata0 = sa.get_image_metadata(project_folder,
                                          "example_image_1.jpg")
    assert img_metadata0["is_pinned"] == 0

    sa.pin_image(project_folder, "example_image_1.jpg")
    time.sleep(1)

    img_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg")
    assert img_metadata["is_pinned"] == 1

    sa.pin_image(project_folder, "example_image_1.jpg", True)
    time.sleep(1)
    img_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg")
    assert img_metadata["is_pinned"] == 1

    sa.pin_image(project_folder, "example_image_1.jpg", False)
    time.sleep(1)

    img_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg")
    assert img_metadata["is_pinned"] == 0

    del img_metadata["updatedAt"]
    del img_metadata0["updatedAt"]

    assert img_metadata == img_metadata0
Пример #5
0
def test_folder_image_annotation_status(tmpdir):
    PROJECT_NAME = "test folder set annotation status"
    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.set_images_annotation_statuses(
        project, ["example_image_1.jpg", "example_image_2.jpg"],
        "QualityCheck")

    for image in ["example_image_1.jpg", "example_image_2.jpg"]:
        metadata = sa.get_image_metadata(project, image)
        assert metadata["annotation_status"] == "QualityCheck"

    for image in ["example_image_3.jpg", "example_image_3.jpg"]:
        metadata = sa.get_image_metadata(project, image)
        assert metadata["annotation_status"] == "InProgress"

    sa.set_images_annotation_statuses(PROJECT_NAME, None, "QualityCheck")

    for image in sa.search_images(PROJECT_NAME):
        metadata = sa.get_image_metadata(PROJECT_NAME, image)
        assert metadata["annotation_status"] == "QualityCheck"
Пример #6
0
def test_image_copy_mult(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_CPY_MULT,
                                        return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_CPY_MULT, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="InProgress")
    sa.create_annotation_classes_from_classes_json(
        project, "./tests/sample_project_vector/classes/classes.json")
    sa.upload_image_annotations(
        project, "example_image_1.jpg",
        "./tests/sample_project_vector/example_image_1.jpg___objects.json")
    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_2.jpg",
        annotation_status="InProgress")
    sa.pin_image(project, "example_image_1.jpg")

    images = sa.search_images(project)
    assert len(images) == 2
    image = images[0]

    for _ in range(3):
        sa.copy_image(project,
                      image,
                      project,
                      include_annotations=True,
                      copy_annotation_status=True,
                      copy_pin=True)
    assert len(sa.search_images(project)) == 5
    images = sa.search_images(project)
    for i in range(3):
        assert f"example_image_1_({i+1}).jpg" in images
    anns = sa.get_image_annotations(project, f"example_image_1_({i+1}).jpg")
    assert anns["annotation_json"] is not None

    metadata = sa.get_image_metadata(project, f"example_image_1_({i+1}).jpg")
    assert metadata["is_pinned"] == 1
Пример #7
0
def test_assign_images_folder(tmpdir):
    tmpdir = Path(tmpdir)

    projects = sa.search_projects(PROJECT_NAME_VECTOR2, return_metadata=True)
    for project in projects:
        sa.delete_project(project)

    project = sa.create_project(PROJECT_NAME_VECTOR2, "test", "Vector")
    email = sa.get_team_metadata()["users"][0]["email"]
    sa.share_project(project, email, "QA")
    sa.create_folder(project, FOLDER2)

    project_folder = project["name"] + "/" + FOLDER2

    sa.upload_images_from_folder_to_project(project_folder,
                                            "./tests/sample_project_vector")

    sa.assign_images(project_folder,
                     ["example_image_1.jpg", "example_image_2.jpg"], email)

    time.sleep(1)
    im1_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg")
    im2_metadata = sa.get_image_metadata(project_folder, "example_image_2.jpg")

    assert im1_metadata["qa_id"] == email
    assert im2_metadata["qa_id"] == email

    sa.unshare_project(project, email)

    time.sleep(1)

    im1_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg")
    im2_metadata = sa.get_image_metadata(project_folder, "example_image_2.jpg")

    assert im1_metadata["qa_id"] is None
    assert im2_metadata["qa_id"] is None
    assert im1_metadata["annotator_id"] is None
    assert im2_metadata["annotator_id"] is None

    sa.share_project(project, email, "Annotator")

    sa.assign_images(project_folder,
                     ["example_image_1.jpg", "example_image_2.jpg"], email)

    time.sleep(1)
    im1_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg")
    im2_metadata = sa.get_image_metadata(project_folder, "example_image_2.jpg")

    assert im1_metadata["annotator_id"] == email
    assert im2_metadata["annotator_id"] == email
    assert im1_metadata["qa_id"] is None
    assert im2_metadata["qa_id"] is None
Пример #8
0
def test_single_image_upload_s3(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME_S3, return_metadata=True)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME_S3, "test", "Vector")

    sa.upload_image_to_project(project,
                               "sample_project_vector/example_image_1.jpg",
                               annotation_status="InProgress",
                               from_s3_bucket="superannotate-python-sdk-test")

    images = sa.search_images(project)
    assert len(images) == 1
    image = images[0]
    assert sa.get_image_metadata(project,
                                 image)["annotation_status"] == "InProgress"
Пример #9
0
def test_single_image_upload(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True)
    print(projects_found)
    for pr in projects_found:
        sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME, "test", "Vector")

    sa.upload_image_to_project(
        project,
        "./tests/sample_project_vector/example_image_1.jpg",
        annotation_status="InProgress")

    images = sa.search_images(project)
    assert len(images) == 1
    image = images[0]
    assert sa.get_image_metadata(project,
                                 image)["annotation_status"] == "InProgress"
    assert image == "example_image_1.jpg"