Exemplo n.º 1
0
def test_get_target_indexes_when_int():
    test = ImageFileGroup("tests/data/image", recursive=True)
    pc = PipelineComponent()
    pc.applies_to_available = True
    pc.applies_to([0])
    targets = pc.get_target_indexes(test)
    assert len(targets) == 1 and targets[0] == 0
Exemplo n.º 2
0
def test_to_grayscale():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["TransformToGrayscale"])
    test.load_all()
    test_ind = 0
    while repr(test.files[test_ind]) != "sample.jpg":
        test_ind += 1
    assert test.files[test_ind].image.mode != "L"
    test.run_pipeline()
    assert test.files[test_ind].image.mode == "L"
Exemplo n.º 3
0
def test_limit_dimensions_no_setting():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["TransformLimitDimensions"])
    test.load_all()
    heights_before = [fobj.image.size[0] for fobj in test.files if fobj.image]
    widths_before = [fobj.image.size[0] for fobj in test.files if fobj.image]
    test.run_pipeline()
    heights_after = [fobj.image.size[0] for fobj in test.files if fobj.image]
    widths_after = [fobj.image.size[0] for fobj in test.files if fobj.image]
    assert len(test.files) > 0
    assert sum(heights_before) == sum(heights_after)
    assert sum(widths_before) == sum(widths_after)
Exemplo n.º 4
0
def test_limit_dimensions_height_only():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["TransformLimitDimensions"])
    test.pipeline.components[0].configure(max_height=100)
    test.run_pipeline()
    heights = [fobj.image.size[1] for fobj in test.files if fobj.image]
    assert len(test.files) > 0
    assert max(heights) == 100
Exemplo n.º 5
0
    def __new__(self, source: str = None, recursive: bool = False):
        """Initialize a kaishi image dataset (currently a directory of files is the only option).

        :param source: string pointing to the data source
        :type source: str
        :param recusive: flag indicating recursion
        :type recursive: bool
        """
        if torch.cuda.is_available() is False:
            warnings.warn(
                "No GPU detected, ConvNet prediction tasks will be very slow")

        if os.path.exists(source):
            return ImageFileGroup(source=source, recursive=recursive)
        else:
            raise NotImplementedError(
                "Currently only supports a valid path as input")
Exemplo n.º 6
0
def test_fix_rotation():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["TransformFixRotation"])
    test.run_pipeline()
    found_rectified = False
    found_rotated = False
    for fobj in test.files:
        if fobj.has_label("RECTIFIED"):
            found_rectified = True
        if fobj.has_label("ROTATED_LEFT"):
            found_rotated = True
        if fobj.has_label("ROTATED_RIGHT"):
            found_rotated = True
        if fobj.has_label("UPSIDE_DOWN"):
            found_rotated = True
    assert found_rectified is True and found_rotated is False
Exemplo n.º 7
0
def test_invalid_file_extensions():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["FilterInvalidFileExtensions"])
    test.run_pipeline()
    assert len(test.filtered["unsupported_extension"]) > 0
Exemplo n.º 8
0
def test_similar():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["FilterSimilar"])
    test.run_pipeline()
    assert len(test.filtered["similar"]) > 0
Exemplo n.º 9
0
def test_invalid_image_headers():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["FilterInvalidImageHeaders"])
    test.run_pipeline()
    assert len(test.filtered["invalid_header"]) > 0
Exemplo n.º 10
0
def test_get_target_indexes_when_regex():
    test = ImageFileGroup("tests/data/image", recursive=True)
    pc = PipelineComponent()
    pc.applies_to_available = True
    pc.applies_to(["real_near.*"])
    assert len(pc.get_target_indexes(test)) == 2
Exemplo n.º 11
0
def test_init_and_load_dir():
    test = ImageFileGroup("tests/data/image", recursive=True)
    assert len(test.files) > 0
Exemplo n.º 12
0
def test_save():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.load_all()
    tempdir = tempfile.TemporaryDirectory()
    test.save(tempdir.name)
    assert len(os.listdir(tempdir.name)) > 0
Exemplo n.º 13
0
def test_load_all():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.load_all()
    assert sum([fobj.image is not None for fobj in test.files]) > 0
Exemplo n.º 14
0
def test_generic_convnet():
    test = ImageFileGroup("tests/data/image", recursive=True)
    test.configure_pipeline(["LabelerGenericConvnet"])
    test.run_pipeline()
    label_count = sum([len(fobj.labels) for fobj in test.files])
    assert label_count > 0