probnmn.data.readers

A Reader simply reads data from disk and returns it almost as is. Readers should be utilized by PyTorch torch.utils.data.Dataset. Any type of data pre-processing is not recommended in the reader, such as tokenizing words to integers, embedding tokens, or passing an image through a pre-trained CNN.

Each reader must implement three methods:

  • __len__ to return the length of data this Reader can read.

  • __getitem__ to return data based on a unique index (which behaves as a primary key).

  • keys to return a list of possible primary keys (or indices) this Reader can provide data of.

class probnmn.data.readers.ClevrTokensReader(tokens_h5path: str)[source]

Bases: object

A Reader for retrieving tokenized CLEVR programs, questions and answers, and corresponding image indices from a single HDF file containing this pre-processed data.

Parameters
tokens_h5path: str

Path to an HDF file containing tokenized programs, questions, answers and corresponding image indices.

class probnmn.data.readers.ClevrImageFeaturesReader(features_h5path: str, in_memory: bool = True)[source]

Bases: object

A Reader for retrieving pre-extracted image features from CLEVR images. We typically use features extracted using ResNet-101.

Example of an HDF file:

features_train.h5
|--- "features" [shape: (num_images, channels, height, width)]
+--- .attrs ("split", "train")
Parameters
features_h5path: str

Path to an HDF file containing a ‘dataset’ of pre-extracted image features.

in_memory: bool, optional (default = True)

Whether to load all image features in memory.