Skip to content

simet.providers.local_binary_provider

simet.providers.local_binary_provider

LocalBinaryProvider

LocalBinaryProvider(data_path)

Bases: Provider

Provider that builds a binary image dataset from a local folder tree.

Wraps :class:simet.datasets.BinaryFolderDataset to read images from self.data_path with the expected structure (case-insensitive class dirs): GOOD/ and BAD/. Applies the given project :class:Transform.

Notes
  • Labels are assigned as: GOOD → 1, BAD → 0.
  • File discovery is recursive under the class subfolders.
  • If the path does not exist or contains no images, an exception is raised.
Example

provider = LocalBinaryProvider(data_path=Path("./data/my_run")) ds = provider.get_data(transform=SomeTransform()) len(ds) > 0 True

Source code in simet/providers/base/provider.py
46
47
def __init__(self, data_path: Path) -> None:
    self.data_path = data_path

get_data

get_data(transform)

Return a BinaryFolderDataset for self.data_path with transform.

Validates that self.data_path exists before constructing the dataset.

Parameters:

Name Type Description Default
transform Transform

Project transform wrapper; transform.get_transform() is passed to the underlying dataset.

required

Returns:

Name Type Description
VisionDataset VisionDataset

A dataset yielding (image, label) pairs.

Raises:

Type Description
FileNotFoundError

If self.data_path does not exist.

RuntimeError

If no images are found under GOOD/ and BAD/ (raised by BinaryFolderDataset).

Source code in simet/providers/local_binary_provider.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@override
def get_data(self, transform: Transform) -> VisionDataset:
    """Return a `BinaryFolderDataset` for `self.data_path` with `transform`.

    Validates that `self.data_path` exists before constructing the dataset.

    Args:
        transform: Project transform wrapper; `transform.get_transform()` is
            passed to the underlying dataset.

    Returns:
        VisionDataset: A dataset yielding `(image, label)` pairs.

    Raises:
        FileNotFoundError: If `self.data_path` does not exist.
        RuntimeError: If no images are found under GOOD/ and BAD/ (raised by
            `BinaryFolderDataset`).
    """
    if not self.data_path.exists():
        logger.error(f"The specified path {self.data_path} does not exist.")
        raise FileNotFoundError(
            f"The specified path {self.data_path} does not exist."
        )
    dataset = BinaryFolderDataset(
        root=self.data_path, transform=transform.get_transform()
    )
    logger.info(f"Created dataset from {self.data_path}")
    return dataset