Skip to main content

Overview

The dataset module provides functionality for loading and managing image datasets. It automatically discovers images, loads captions, and provides convenient iteration and batching.

dataset.load()

Load a dataset from a folder of images.

Parameters

string | Path
required
Path to folder containing images. The folder should contain image files and optionally text files with captions.
list[string]
List of file extensions to include. Defaults to common image formats: [".jpg", ".jpeg", ".png", ".webp", ".bmp"]
dict
Additional arguments (reserved for future use)

Returns

Dataset
Dataset instance containing loaded images and captions

Directory Structure

The dataset loader expects a directory structure like this:
Captions are loaded from .txt files with the same name as the image. If a caption file doesn’t exist, the caption will be None.

Example

Errors

error
Raised if the specified path does not exist
error
Raised if:
  • The path is not a directory
  • No images found with specified extensions

Dataset Operations

Length

Get the number of items in the dataset using len().

Indexing

Access individual items by index. Returns a tuple of (image, caption).

Returns

PIL.Image.Image
PIL Image object loaded from disk
string | None
Caption text from corresponding .txt file, or None if no caption exists

Iteration

Iterate over all items in the dataset.

Example


Dataset.batch()

Iterate over the dataset in batches.

Parameters

integer
required
Number of items per batch

Yields

list[tuple[PIL.Image.Image, string | None]]
List of (image, caption) tuples. The last batch may be smaller than batch_size if the dataset size is not evenly divisible.

Example

Notes

The last batch may contain fewer items than batch_size if the dataset size is not evenly divisible.

Caption Files

HyperGen automatically loads captions from text files matching image names.

Format

For each image file (e.g., photo.jpg), create a text file with the same name (e.g., photo.txt) containing the caption:
The caption file should contain plain text. The entire contents of the file will be used as the caption, with leading/trailing whitespace removed.

Example Caption File

Behavior

  • If a caption file exists, its contents are loaded as a string
  • If no caption file exists, the caption will be None
  • Caption files are optional - you can have some images with captions and others without
  • Captions are automatically associated with their corresponding images by filename

Use Cases

Training

Data Analysis

Preprocessing


Type Reference

Dataset

The main dataset class returned by dataset.load().