Dataset chapter

Omniglot data pipeline

In-memory loading, rotation augmentation, pair sampling, and one-shot episodes.

Module boundary

`mydataset.py` defines both train and test loaders

The repository uses two custom dataset classes: `OmniglotTrain` for endless pair sampling during optimization and `OmniglotTest` for one-shot evaluation episodes.

Training dataset

`OmniglotTrain` loads and augments character classes

In-memory cache

`loadToMem` walks the full training tree once and stores PIL images in memory, reducing repeated disk access during long training runs.

Rotation expansion

Each class is duplicated at 0, 90, 180, and 270 degrees, effectively turning orientation variants into extra class identities.

Sampling logic

Positive and negative pair generation

Positive pairs

Odd indices sample two images from the same class and return label `1.0`.

Negative pairs

Even indices sample images from different classes and return label `0.0`.

Transforms

The training path applies random affine augmentation before `ToTensor`, which injects mild shape variation into each sampled pair.

Evaluation dataset

`OmniglotTest` builds one-shot episodes

Episode layout

Index `0` in each episode creates the anchor image and a true match. The remaining `way - 1` entries are distractor classes.

Metric contract

The training loop treats prediction as correct only when the maximum score in the episode lands on the first pair, which is the true match.