Exemplo n.º 1
0
def test_run(snapshot, sample_query, tmp_path):

    random.seed(1)

    with open(os.path.join(tmp_path, "query.yml"), "w") as query_file:
        query_file.write(sample_query)

    main(['generate', os.path.join(tmp_path, "query.yml")])
    os.remove(os.path.join(tmp_path, "query.yml"))

    if snapshot["update_snapshots"]:

        if os.path.isdir("./snapshots/run"):
            shutil.rmtree("./snapshots/run")

        shutil.copytree(tmp_path, "./snapshots/run")
        return

    with FourCornersCSV(annotations_file="./snapshots/run/aug_annotations.csv",
                        normalized=True) as annotation_loader, Directory(
                            directory="./snapshots/run") as image_loader:
        snapshot_images = annotation_loader.load_annotated_images(image_loader)

    with FourCornersCSV(annotations_file=os.path.join(tmp_path,
                                                      "aug_annotations.csv"),
                        normalized=True) as annotation_loader, Directory(
                            directory=tmp_path) as image_loader:
        run_images = annotation_loader.load_annotated_images(image_loader)

    for image_name in snapshot_images:

        snapshot_image, snapshot_annot = snapshot_images[image_name]
        run_image, run_annot = run_images[image_name]

        snapshot_bboxes = annotations_to_numpy_array(snapshot_annot)
        run_bboxes = annotations_to_numpy_array(run_annot)

        assert np.allclose(
            snapshot_image,
            run_image), "Image for {} differs".format(image_name)
        assert np.allclose(
            snapshot_bboxes,
            run_bboxes), "Bounding boxes for {} differ".format(image_name)

    for image_name in run_images:

        if image_name not in snapshot_images:
            assert False, "Image {} not in snapshot".format(image_name)
Exemplo n.º 2
0
def yolokeras_imageset():
    with YOLOKeras(annotations_file=os.path.join(
            fixtures_directory, "yolokeras", "annotations.txt")
                   ) as annotation_loader, Directory(directory=os.path.join(
                       fixtures_directory, "yolokeras")) as image_loader:
        images = annotation_loader.load_annotated_images(image_loader)

    return images
Exemplo n.º 3
0
def coco_imageset():
    with COCO(annotations_file=os.path.join(fixtures_directory, "coco",
                                            "annotations.coco.json")
              ) as annotation_loader, Directory(directory=os.path.join(
                  fixtures_directory, "coco")) as image_loader:
        images = annotation_loader.load_annotated_images(image_loader)

    return images
Exemplo n.º 4
0
def pascalvoc_additional_values_imageset():
    with PascalVOC(annotations_folder=os.path.join(
            fixtures_directory, "pascalvoc-additionalvalues")
                   ) as annotation_loader, Directory(directory=os.path.join(
                       fixtures_directory, "pascalvoc")) as image_loader:
        images = annotation_loader.load_annotated_images(image_loader)

    return images
Exemplo n.º 5
0
def yolodarknet_imageset():
    with YOLODarknet(
            annotations_folder=os.path.join(fixtures_directory, "yolodarknet"),
            image_ext="jpg") as annotation_loader, Directory(
                directory=os.path.join(fixtures_directory,
                                       "yolodarknet")) as image_loader:
        images = annotation_loader.load_annotated_images(image_loader)

    return images
Exemplo n.º 6
0
def sample_image_wh_bboxes():
    with WidthHeightCSV(annotations_file=os.path.join(fixtures_directory,
                                                      "annotations-wh.csv"),
                        normalized=True) as annotation_loader, Directory(
                            directory=fixtures_directory) as image_loader:

        images = annotation_loader.load_annotated_images(image_loader)

    return images["wheat1.jpg"]
Exemplo n.º 7
0
def sample_image():
    with FourCornersCSV(annotations_file=os.path.join(fixtures_directory,
                                                      "annotations.csv"),
                        normalized=True) as annotation_loader, Directory(
                            directory=fixtures_directory) as image_loader:

        images = annotation_loader.load_annotated_images(image_loader)

    return images["wheat1.jpg"]
Exemplo n.º 8
0
def yolokeras_equiv_csv_imageset():
    with FourCornersCSV(
            annotations_file=os.path.join(fixtures_directory, "yolokeras",
                                          "annotations.csv"),
            normalized=True) as annotation_loader, Directory(
                directory=os.path.join(fixtures_directory,
                                       "yolokeras")) as image_loader:
        images = annotation_loader.load_annotated_images(image_loader)

    return images