Перейти к содержанию

ImageFolder

ImageFolderDataset - это класс для чтения датасетов классификации, на основе директорий. Каждая директорая содержит снимки из одного класса.

Пример структуры датасета:

SomeImageFolder
├── class1
    ├── image1.jpg
    ├── imageN.jpg
├── class2
    ├── image1.jpg
    ├── imageM.jpg

Пример использования в коде:

from hyppopipe.data import TrainVal
from hyppopipe.data.dataset import ImageFolderDataset

train_dataset = ImageFolderDataset("path_to_train_folder")
val_dataset = ImageFolderDataset("path_to_validation_folder")
data = TrainVal(train=train_dataset, val=val_dataset)

Переопределение разбиения

Флаг absorb_folders=True позволяет игнорировать готовые папки train/val и перераспределить данные через split_random_fractions(dataset, (0.7, 0.15, 0.15)) без изменения файлов на диске.

Документация

Bases: ImageDataset, ClassificationConvertible

Classification dataset with one subdirectory per class under root.

Each immediate child directory of root is treated as a class name. Image files with supported extensions inside those directories become samples. When absorb_folders is True, an extra top-level directory tier is allowed (root/<top>/<class>/...).

__getitem__(index)

Load image and class index for index.

Parameters:

Name Type Description Default
index int

Sample index in [0, len(self)).

required

Returns:

Type Description
tuple[Image, int]

A pair of loaded Image and integer class index.

__init__(root, absorb_folders=False, *, strict=True)

Build the index of image paths and class indices.

Parameters:

Name Type Description Default
root str | Path

Dataset root directory.

required
absorb_folders bool

If True, expect root/<top>/<class>/ layout instead of root/<class>/.

False
strict bool

Passed to Image.from_path when loading samples.

True

__len__()

Number of indexed samples.

as_classification_dataset()

Return this dataset for classification training.