peal.data.custom_datasets.SparseNumbersDataset

class peal.data.custom_datasets.SparseNumbersDataset[source]

Bases: Image2MixedDataset

Number-grid images with eight additional dense red intensities.

SparseNumbersDatasetGenerator writes the dataset on first use. Each csv row holds 8 Red intensities followed by 8 number slots (the number drawn there, or -1). __getitem__ expands the slots into a binary vector of length config.output_split (default 1000) and concatenates the red intensities, so attributes is Num0 ... Num<n-1> followed by Red1 ... Red8; the red channels act as confounders of the sparse number labels.

Parameters:
  • config (DataConfig) – Uses dataset_path, output_split, class_ratios and confounding_factors.

  • **kwargs – Forwarded to the generator and to Image2MixedDataset.

Variables:

attributes (list of str) – The expanded label vector; attributes_positive and attributes_negative hold its phrasings.

Methods

enable_class_restriction

Restrict keys to the samples of one class of the selected attribute.

set_task_specific_keys

Subsample keys to the proportions in config.class_ratios.

Attributes

__init__(config, **kwargs)[source]

Generate the dataset if missing and build the expanded attribute names.

Parameters:

config (DataConfig)

enable_class_restriction(class_idx)[source]

Restrict keys to the samples of one class of the selected attribute.

Parameters:

class_idx (int) – Value the expanded attribute must take (0 or 1).

set_task_specific_keys()[source]

Subsample keys to the proportions in config.class_ratios.

Labels come from _expanded_label_value so that the expanded attribute index is resolved against the raw csv row correctly.