ImageFolder
ImageFolderDataset reads classification datasets laid out as one subdirectory per class. Each immediate child folder of root becomes a class name; supported image files inside are indexed as samples.
When absorb_folders=True, an extra top-level tier is allowed (root/<split>/<class>/...), which is useful when train/val folders are already separated in the dataset.
Example layout:
FundusDataset/
├── Glaucoma/
│ ├── img001.png
│ └── img002.png
└── Non Glaucoma/
├── img003.png
└── img004.png
from hyppopipe.data import TrainVal
from hyppopipe.data.dataset import ImageFolderDataset
train_dataset = ImageFolderDataset("data/train")
val_dataset = ImageFolderDataset("data/val")
data = TrainVal(train=train_dataset, val=val_dataset)
Re-splitting an existing dataset
Set absorb_folders=True to ignore pre-defined train/val folders and call split_random_fractions(dataset, (0.7, 0.15, 0.15)) to create new splits without moving files on disk.
Documentation¶
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)
¶
__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 |
False
|
strict
|
bool
|
Passed to |
True
|
__len__()
¶
Number of indexed samples.
as_classification_dataset()
¶
Return this dataset for classification training.