Exemplo n.º 1
0
def test_add_bbox_noinit(tmpdir):
    tmpdir = Path(tmpdir)

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

    project = sa.create_project(
        PROJECT_NAME_NOINIT, PROJECT_DESCRIPTION, "Vector"
    )
    sa.upload_images_from_folder_to_project(
        project, PATH_TO_SAMPLE_PROJECT, annotation_status="InProgress"
    )
    sa.create_annotation_classes_from_classes_json(
        project, PATH_TO_SAMPLE_PROJECT / "classes" / "classes.json"
    )
    sa.create_annotation_class(project, "test_add", "#FF0000")
    images = sa.search_images(project, "example_image_1")

    image_name = images[0]
    sa.add_annotation_bbox_to_image(
        project, image_name, [10, 10, 500, 100], "test_add"
    )
    sa.add_annotation_polygon_to_image(
        project, image_name, [100, 100, 500, 500, 200, 300], "test_add"
    )
    annotations_new = sa.get_image_annotations(project,
                                               image_name)["annotation_json"]

    assert len(annotations_new) == 2
    export = sa.prepare_export(project, include_fuse=True)
    sa.download_export(project, export, tmpdir)
    assert len(list(Path(tmpdir).rglob("*.*"))) == 4
Exemplo n.º 2
0
def test_anntotation_class_new():
    projects = sa.search_projects(PROJECT_NAME, return_metadata=True)
    for project in projects:
        sa.delete_project(project)

    sa.create_project(PROJECT_NAME, "tt", "Vector")

    sa.create_annotation_class(PROJECT_NAME, "tt", "#FFFFFF")

    assert len(sa.search_annotation_classes(PROJECT_NAME)) == 1

    sa.create_annotation_class(PROJECT_NAME, "tt", "#FFFFFF")

    assert len(sa.search_annotation_classes(PROJECT_NAME)) == 1
Exemplo n.º 3
0
def test_add_bbox_noinit(tmpdir):
    tmpdir = Path(tmpdir)

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

    project = sa.create_project(PROJECT_NAME_NOINIT, PROJECT_DESCRIPTION,
                                "Vector")
    sa.upload_images_from_folder_to_project(project,
                                            PATH_TO_SAMPLE_PROJECT,
                                            annotation_status="InProgress")
    sa.create_annotation_classes_from_classes_json(
        project, PATH_TO_SAMPLE_PROJECT / "classes" / "classes.json")
    sa.create_annotation_class(project, "test_add", "#FF0000")
    images = sa.search_images(project, "example_image_1")

    image_name = images[0]
    sa.add_annotation_bbox_to_image(project, image_name, [10, 10, 500, 100],
                                    "test_add")
    sa.add_annotation_polygon_to_image(project, image_name,
                                       [100, 100, 500, 500, 200, 300],
                                       "test_add")
    annotations_new = sa.get_image_annotations(project,
                                               image_name)["annotation_json"]

    assert len(annotations_new["instances"]) == 2
    export = sa.prepare_export(project, include_fuse=True)
    sa.download_export(project, export, tmpdir)

    non_empty_annotations = 0
    json_files = tmpdir.glob("*.json")
    for json_file in json_files:
        json_ann = json.load(open(json_file))
        if "instances" in json_ann and len(json_ann["instances"]) > 0:
            non_empty_annotations += 1
            assert len(json_ann["instances"]) == 2

    assert non_empty_annotations == 1
Exemplo n.º 4
0
def test_annotation_classes():
    projects = sa.search_projects(PROJECT_NAME, return_metadata=True)
    for project in projects:
        sa.delete_project(project)
    project = sa.create_project(PROJECT_NAME, "test1", "Vector")
    clss = sa.search_annotation_classes(project)
    assert len(clss) == 0

    ac = sa.create_annotation_class(project, "fff", "#FFFFFF")
    clss = sa.search_annotation_classes(project)
    assert len(clss) == 1

    ac = sa.search_annotation_classes(project, "ff")[0]
    sa.delete_annotation_class(project, ac)
    clss = sa.search_annotation_classes(project)
    assert len(clss) == 0
    sa.delete_project(project)
def test_video(tmpdir):
    tmpdir = Path(tmpdir)

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

    project = sa.create_project(PROJECT_NAME1, "test", "Vector")
    time.sleep(1)
    sa.create_annotation_class(project, "fr", "#FFAAAA")
    time.sleep(1)
    sa.create_annotation_class(project, "fr2", "#FFAACC")

    sa.upload_videos_from_folder_to_project(
        project, "./tests/sample_videos", target_fps=2
    )

    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")

    subprocess.run(
        f'superannotatecli upload-videos --project "{PROJECT_NAME2}" --folder ./tests/sample_videos --target-fps 2',
        check=True,
        shell=True
    )
    time.sleep(5)
    sa.create_annotation_class(project, "fr2", "#FFAACC")

    assert len(sa.search_images(PROJECT_NAME1)) == len(
        sa.search_images(PROJECT_NAME2)
    )

    sa.create_folder(project, "new folder")

    sa.upload_videos_from_folder_to_project(
        PROJECT_NAME2 + "/new folder", "./tests/sample_videos", target_fps=2
    )

    assert len(sa.search_images(PROJECT_NAME2 + "/new folder")) == len(
        sa.search_images(PROJECT_NAME2)
    )
Exemplo n.º 6
0

def sdk_uplaod(project_name, image_path):
    """Upload Images via SA sdk"""
    project_metadata = sa.get_project_metadata(project_name)
    _uploaded, _skipped, _duplicate = sa.upload_images_from_folder_to_project(
        project=project_metadata["name"], folder_path="./images")
    sa.upload_annotations_from_folder_to_project(project_name, "./annotations")


if __name__ == "__main__":
    height = 1600
    width = 1600
    count = 100
    project_name = "Large Dataset2"
    image_path = "./images"
    sa.create_project(project_name, "x", "Vector")
    sa.create_annotation_class(project_name, "CUBOID", "#FFFFFF")
    sa.create_annotation_class(project_name, "BBOX", "#FFFFFF")
    sa.create_annotation_class(project_name, "POLYGON", "#FFFFFF")
    sa.create_annotation_class(project_name, "POLYLINE", "#FFFFFF")
    sa.create_annotation_class(project_name, "ELLIPSE", "#FFFFFF")
    if os.path.exists("./images"):
        shutil.rmtree("./images")
    if os.path.exists("./annotations"):
        shutil.rmtree("./annotations")
    pathlib.Path("./images").mkdir(exist_ok=True)
    pathlib.Path("./annotations").mkdir(exist_ok=True)
    generate_images(width, height, count)
    sdk_uplaod(project_name, image_path)
Exemplo n.º 7
0
def test_add_bbox(tmpdir):
    tmpdir = Path(tmpdir)

    projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True)
    for pr in projects_found:
        if pr["name"] == PROJECT_NAME:
            sa.delete_project(pr)

    project = sa.create_project(PROJECT_NAME, PROJECT_DESCRIPTION, "Vector")
    sa.upload_images_from_folder_to_project(PROJECT_NAME,
                                            PATH_TO_SAMPLE_PROJECT,
                                            annotation_status="InProgress")
    sa.create_annotation_classes_from_classes_json(
        project, PATH_TO_SAMPLE_PROJECT / "classes" / "classes.json")
    sa.create_annotation_class(
        project, "test_add", "#FF0000",
        [{
            "name": "height",
            "attributes": [{
                "name": "tall"
            }, {
                "name": "short"
            }]
        }])
    sa.upload_annotations_from_folder_to_project(project,
                                                 PATH_TO_SAMPLE_PROJECT)

    images = sa.search_images(project, "example_image_1")

    image_name = images[0]
    annotations = sa.get_image_annotations(project,
                                           image_name)["annotation_json"]

    sa.add_annotation_bbox_to_image(project, image_name, [10, 10, 500, 100],
                                    "test_add")
    sa.add_annotation_polyline_to_image(project, image_name,
                                        [110, 110, 510, 510, 600, 510],
                                        "test_add")
    sa.add_annotation_polygon_to_image(project, image_name,
                                       [100, 100, 500, 500, 200, 300],
                                       "test_add", [{
                                           "name": "tall",
                                           "groupName": "height"
                                       }])
    sa.add_annotation_point_to_image(project, image_name, [250, 250],
                                     "test_add")
    sa.add_annotation_ellipse_to_image(project, image_name,
                                       [405, 405, 20, 70, 15], "test_add")
    sa.add_annotation_template_to_image(project, image_name,
                                        [600, 30, 630, 30, 615, 60],
                                        [1, 3, 2, 3], "test_add")
    sa.add_annotation_cuboid_to_image(project, image_name,
                                      [800, 500, 900, 600, 850, 450, 950, 700],
                                      "test_add")
    sa.add_annotation_comment_to_image(project, image_name, "hey", [100, 100],
                                       "*****@*****.**", True)
    annotations_new = sa.get_image_annotations(project,
                                               image_name)["annotation_json"]
    json.dump(annotations_new, open(tmpdir / "new_anns.json", "w"))

    assert len(annotations_new["instances"]) + len(
        annotations_new["comments"]) == len(annotations["instances"]) + len(
            annotations["comments"]) + 8

    export = sa.prepare_export(project, include_fuse=True)
    sa.download_export(project, export, tmpdir)

    df = sa.aggregate_annotations_as_df(tmpdir)
    print(df)
    print(image_name)

    num = len(
        df[df["imageName"] == image_name]["instanceId"].dropna().unique())

    assert num == len(
        annotations["instances"]
    ) - 3 + 7  # -6 for 3 comments and 3 invalid annotations, className or attributes
def test_create_like_project(tmpdir):
    tmpdir = Path(tmpdir)

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

    sa.create_project(PROJECT_NAME, "tt", "Vector")
    sa.create_annotation_class(PROJECT_NAME, "rrr", "#FFAAFF")

    old_settings = sa.get_project_settings(PROJECT_NAME)
    for setting in old_settings:
        if "attribute" in setting and setting["attribute"] == "Brightness":
            brightness_value = setting["value"]
    sa.set_project_settings(PROJECT_NAME, [{
        "attribute": "Brightness",
        "value": brightness_value + 10
    }])
    sa.set_project_workflow(PROJECT_NAME, [{
        "step": 1,
        "className": "rrr",
        "tool": 3
    }])
    users = sa.search_team_contributors()
    sa.share_project(PROJECT_NAME, users[1], "QA")

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

    new_project = sa.clone_project(PROJECT_NAME2,
                                   PROJECT_NAME,
                                   copy_contributors=True)
    assert new_project["description"] == "tt"
    assert new_project["type"] == 1
    time.sleep(1)

    ann_classes = sa.search_annotation_classes(PROJECT_NAME2,
                                               return_metadata=True)
    assert len(ann_classes) == 1
    assert ann_classes[0]["name"] == "rrr"
    assert ann_classes[0]["color"] == "#FFAAFF"

    new_settings = sa.get_project_settings(PROJECT_NAME2)
    for setting in new_settings:
        if "attribute" in setting and setting["attribute"] == "Brightness":
            new_brightness_value = setting["value"]

    assert new_brightness_value == brightness_value + 10

    new_workflow = sa.get_project_workflow(PROJECT_NAME2)
    assert len(new_workflow) == 1
    assert new_workflow[0]["className"] == "rrr"
    assert new_workflow[0]["tool"] == 3

    new_project = sa.get_project_metadata(new_project["name"],
                                          include_contributors=True)
    assert len(new_project["contributors"]) == 1
    assert new_project["contributors"][0]["user_id"] == users[1]
    assert new_project["contributors"][0][
        "user_role"] == sa.user_role_str_to_int("QA")