Skip to content

pixano.datasets.builders.folders.image

ImageFolderBuilder(source_dir, target_dir, dataset_item, info, url_prefix=None)

Bases: FolderBaseBuilder

Builder for image datasets stored in a folder.

Source code in pixano/datasets/builders/folders/base.py
def __init__(
    self,
    source_dir: Path | str,
    target_dir: Path | str,
    dataset_item: type[DatasetItem],
    info: DatasetInfo,
    url_prefix: Path | str | None = None,
) -> None:
    """Initialize the `FolderBaseBuilder`.

    Args:
        source_dir: The source directory for the dataset.
        target_dir: The target directory for the dataset.
        dataset_item: The dataset item schema.
        info: User informations (name, description, ...) for the dataset.
        url_prefix: The path to build relative URLs for the views. Useful to build dataset libraries to pass the
            relative path from the media directory.
    """
    super().__init__(target_dir=target_dir, dataset_item=dataset_item, info=info)
    self.source_dir = Path(source_dir)
    if url_prefix is None:
        url_prefix = Path(".")
    else:
        url_prefix = Path(url_prefix)
    self.url_prefix = url_prefix

    view_name = None
    entity_name = None
    for k, s in self.schemas.items():
        if issubclass(s, View):
            if view_name is not None:
                raise ValueError("Only one view schema is supported in folder based builders.")
            view_name = k
            view_schema = s
        if issubclass(s, Entity):
            if entity_name is not None:
                raise ValueError("Only one entity schema is supported in folder based builders.")
            entity_name = k
            entity_schema = s
    if view_name is None or entity_name is None:
        raise ValueError("View and entity schemas must be defined in the schemas argument.")
    self.view_name = view_name
    self.view_schema: type[View] = view_schema
    self.entity_name = entity_name
    self.entity_schema: type[Entity] = entity_schema