Exemplo n.º 1
0
def test_build_full_labelled_image(tanzania_image_size, tanzania_nb_labels,
                                   tanzania_raw_image_size):
    """Test the label prediction on a high-resolution image that has to be
        tiled during inference process

    The labelled output is composed of label IDs that must corresponds to the
    dataset glossary, and its shape must equal the original image size.
    """
    datapath = "./tests/data"
    dataset = "tanzania"
    image_paths = postprocess.get_image_paths(datapath, dataset,
                                              tanzania_image_size,
                                              "tanzania_sample")
    images = postprocess.extract_images(image_paths)
    coordinates = postprocess.extract_coordinates_from_filenames(image_paths)
    model = postprocess.get_trained_model(datapath, dataset,
                                          tanzania_image_size,
                                          tanzania_nb_labels)
    labelled_image = postprocess.build_full_labelled_image(
        images,
        coordinates,
        model,
        tile_size=tanzania_image_size,
        img_width=tanzania_raw_image_size,
        batch_size=2,
    )
    assert labelled_image.shape == (
        tanzania_raw_image_size,
        tanzania_raw_image_size,
    )
    assert np.all(
        [ul in range(tanzania_nb_labels) for ul in np.unique(labelled_image)])
Exemplo n.º 2
0
def test_extract_coordinates_from_filenames():
    """Test the x, y coordinates extraction from filenames

    The filename chosen convention is as follows:
        <path>/<name>_<width>_<height>_<x>_<y>.<extension>
    """
    filenames = [
        "./foofolder/foo_100_100_0_1000.png",
        "./barfolder/bar_100_100_2000_2100.png",
    ]
    coordinates = postprocess.extract_coordinates_from_filenames(filenames)
    assert np.all(coordinates == [[0, 1000], [2000, 2100]])