OxfordFlowerDataset

A PyTorch Dataset for the Oxford 102 Flowers dataset (8189 images across 102 categories). Indexing yields a (image, label, image_path) tuple, where image is an RGB NumPy array.

from pyvisim.datasets import OxfordFlowerDataset

dataset = OxfordFlowerDataset(purpose="train")
image, label, path = dataset[0]

Iterating yields the same tuple, in the same order:

import os

for image, label, path in dataset:
    print("Image shape:", image.shape)
    print("Image label:", label)
    print("Image path:", os.path.basename(path))

Downloads

The first class instantiation downloads three files from the website of the University of Oxford’s Visual Geometry Group into the user cache directory:

  • the dataset images: 8189 images of 102 flower categories,

  • ``imagelabels.mat``: the category label of every image,

  • ``setid.mat``: the ids assigning each image to the training, validation or test split.

The swapped train/test split

The constructor’s purpose accepts "train", "validation", "test", or a list to combine splits (for example ["train", "validation"]).

Attention

The original dataset contains 1020 training, 1020 validation and 6149 test images. This class maps the original test ids to train and the original train ids to test, so the training set has the most images, which makes more sense. However, keep this in mind if you compare results against papers that use the original split. For more technical information, visit https://github.com/MechaCritter/Python-Visual-Similarity/blob/main/docs/dataset/arc42.md.

API reference

class pyvisim.datasets.OxfordFlowerDataset(purpose='train')[source]

Bases: Dataset[tuple[ndarray[tuple[int, …], dtype[uint8]], int, str]]

Oxford Flower Dataset. It can be found at: https://www.robots.ox.ac.uk/~vgg/data/flowers/102/index.html.

In the original dataset, number of train images (‘trnid’) is 1020, number of validation images (‘valid’) is 1020, and number of test images (‘tstid’) is 6149. Since it makes more sense to have more images for training for this project, the train and test splits have been swapped.

Note

The dataset takes no transform. Every item is the raw RGB uint8 array, which is the image format all embedders, feature extractors and similarity metrics of this library accept. Preprocessing is owned by the model consuming the image, so a transform here would apply it twice and would not reach the images loaded through image_paths. To train with augmentations, wrap the dataset in your own torch.utils.data.Dataset and apply the transform there.

Parameters:

purpose (str | list[str]) – Purpose of the dataset (‘train’, ‘test’, ‘validation’). You can also pass a list such as [‘train’, ‘validation’] to get a combined dataset.