ReferentialGym.datasets package

Submodules

ReferentialGym.datasets.CLEVR_dataset module

ReferentialGym.datasets.CLEVR_dataset.download_preprocess_dataset(path)
ReferentialGym.datasets.CLEVR_dataset.ToLongTensor(data)
class ReferentialGym.datasets.CLEVR_dataset.Rescale(output_size)

Bases: object

class ReferentialGym.datasets.CLEVR_dataset.ToTensor

Bases: object

class ReferentialGym.datasets.CLEVR_dataset.CLEVRDataset(root, train=True, transform=Compose( <ReferentialGym.datasets.CLEVR_dataset.Rescale object> <ReferentialGym.datasets.CLEVR_dataset.ToTensor object> ), download=False)

Bases: torch.utils.data.dataset.Dataset

_check_exists()
_download()

Download and preprocess the Sort-of-CLEVR dataset if it doesn’t exist already.

getVocabSize()
getAnswerVocabSize()
getclass(idx)

ReferentialGym.datasets.MSCOCO_dataset module

class ReferentialGym.datasets.MSCOCO_dataset.MSCOCODataset(root, annFile, transform=None, transfer_learning=False, extract_features=None, data_suffix='TL.npy')

Bases: torchvision.datasets.coco.CocoDetection

root (string): Root directory where images are downloaded to. annFile (string): Path to json annotation file. transform (callable, optional): A function/transform that takes in an PIL image

and returns a transformed version. E.g, transforms.ToTensor

transfer_learning (bool): Bool that defines whether we use the transfer learning version of the dataset. extract_features: Function that takes only one argument, i.e. the image tensor from

feature extraction is attempted.

make_tl_dataset()
getclass(idx)
getlatentvalue(idx)

ReferentialGym.datasets.MineRL_dataset module

ReferentialGym.datasets.dSprites_dataset module

class ReferentialGym.datasets.dSprites_dataset.dSpritesDataset(root='./', train=True, transform=None, split_strategy=None)

Bases: torch.utils.data.dataset.Dataset

counter_test_threshold = None

With regards to designing axises as primitives:

It implies that all the values on this latent axis are treated as test values when combined with a test value on any other latent axis.

N.B.: it is not possible to test for out-of-distribution values in that context… N.B.1: It is required that the number of primitive latent axis be one less than

the counter_test_thershold, at most.

A number of fillers along this primitive latent axis can then be specified in front of the FP pattern… Among the effective indices, those with an ordinal lower or equal to the number of filler allowed will be part of the training set.

getclass(idx)
getlatentvalue(idx)
getlatentclass(idx)
gettestlatentmask(idx)

ReferentialGym.datasets.dataset module

ReferentialGym.datasets.dataset.shuffle(experiences, orders=None)
class ReferentialGym.datasets.dataset.Dataset(kwargs)

Bases: torch.utils.data.dataset.Dataset

getNbrDistractors(mode='train')
setNbrDistractors(nbr_distractors, mode='train')
getNbrClasses() → int
sample(idx: int = None, from_class: List[int] = None, excepts: List[int] = None, target_only: bool = False) → Dict[str, object]

Sample an experience from the dataset. Along with relevant distractor experiences. If :param from_class: is not None, the sampled experiences will belong to the specified class(es). If :param excepts: is not None, this function will make sure to not sample from the specified list of exceptions. :param from_class: None, or List of keys (Strings or Integers) that corresponds to entries in self.classes. :param excepts: None, or List of indices (Integers) that are not considered for sampling. :param target_only: bool (default: False) defining whether to sample only the target or distractors too.

Returns

  • sample_d: Dict of:
    • ”experiences”: Tensor of the sampled experiences.

    • ”indices”: List[int] of the indices of the sampled experiences.

    • ”exp_labels”: List[int] consisting of the indices of the label to which the experiences belong.

    • ”exp_latents”: Tensor representatin the latent of the experience in one-hot-encoded vector form.

    • ”exp_latents_values”: Tensor representatin the latent of the experience in value form.

    • some other keys provided by the dataset used…

ReferentialGym.datasets.dict_dataset_wrapper module

class ReferentialGym.datasets.dict_dataset_wrapper.DictDatasetWrapper(dataset)

Bases: torch.utils.data.dataset.Dataset

getclass(idx)

ReferentialGym.datasets.dual_labeled_dataset module

class ReferentialGym.datasets.dual_labeled_dataset.DualLabeledDataset(kwargs)

Bases: ReferentialGym.datasets.dataset.Dataset

set_mode(newmode='train')
getNbrClasses() → int
sample(idx: int = None, from_class: List[int] = None, excepts: List[int] = None, target_only: bool = False) → Dict[str, object]

Sample an experience from the dataset. Along with relevant distractor experiences. If :param from_class: is not None, the sampled experiences will belong to the specified class(es). If :param excepts: is not None, this function will make sure to not sample from the specified list of exceptions. :param from_class: None, or List of keys (Strings or Integers) that corresponds to entries in self.classes. :param excepts: None, or List of indices (Integers) that are not considered for sampling. :param target_only: bool (default: False) defining whether to sample only the target or distractors too.

Returns

  • sample_d: Dict of:
    • ”experiences”: Tensor of the sampled experiences.

    • ”indices”: List[int] of the indices of the sampled experiences.

    • ”exp_labels”: List[int] consisting of the indices of the label to which the experiences belong.

    • ”exp_latents”: Tensor representatin the latent of the experience in one-hot-encoded vector form.

    • ”exp_latents_values”: Tensor representatin the latent of the experience in value form.

    • some other keys provided by the dataset used…

ReferentialGym.datasets.extended_sort_of_CLEVR_dataset module

ReferentialGym.datasets.extended_sort_of_CLEVR_dataset.generate_dataset(root, dataset_size=10000, img_size=75, object_size=5, nb_objects=6, nb_nr_qs=5, nb_r_qs=7)

Inspired by: https://github.com/kimhc6028/relational-networks/blob/master/sort_of_clevr_generator.py

class ReferentialGym.datasets.extended_sort_of_CLEVR_dataset.XSortOfCLEVRDataset(root, train=True, transform=None, generate=False, dataset_size=10000, test_size=2000, img_size=75, object_size=5, nb_objects=6, nb_nr_qs=5, nb_r_qs=7, test_id_analogy=False, test_id_analogy_threshold=3)

Bases: torch.utils.data.dataset.Dataset

_check_exists()
_generate(root, dataset_size, img_size, object_size, nb_objects, nb_nr_qs, nb_r_qs)

Generate the Sort-of-CLEVR dataset if it doesn’t exist already.

getclass(idx)
getlatentvalue(idx)
getlatentclass(idx)
getlatentonehot(idx)

ReferentialGym.datasets.labeled_dataset module

class ReferentialGym.datasets.labeled_dataset.LabeledDataset(kwargs)

Bases: ReferentialGym.datasets.dataset.Dataset

set_mode(newmode='train')
getNbrClasses() → int
sample(idx: int = None, from_class: List[int] = None, excepts: List[int] = None, target_only: bool = False) → Dict[str, object]

Sample an experience from the dataset. Along with relevant distractor experiences. If :param from_class: is not None, the sampled experiences will belong to the specified class(es). If :param excepts: is not None, this function will make sure to not sample from the specified list of exceptions. :param from_class: None, or List of keys (Strings or Integers) that corresponds to entries in self.classes. :param excepts: None, or List of indices (Integers) that are not considered for sampling. :param target_only: bool (default: False) defining whether to sample only the target or distractors too.

Returns

  • sample_d: Dict of:
    • ”experiences”: Tensor of the sampled experiences.

    • ”indices”: List[int] of the indices of the sampled experiences.

    • ”exp_labels”: List[int] consisting of the indices of the label to which the experiences belong.

    • ”exp_latents”: Tensor representatin the latent of the experience in one-hot-encoded vector form.

    • ”exp_latents_values”: Tensor representatin the latent of the experience in value form.

    • some other keys provided by the dataset used…

ReferentialGym.datasets.sort_of_CLEVR_dataset module

ReferentialGym.datasets.sort_of_CLEVR_dataset.generate_dataset(root, dataset_size=10000, img_size=75, object_size=5, nb_objects=6)

Inspired by: https://github.com/kimhc6028/relational-networks/blob/master/sort_of_clevr_generator.py

class ReferentialGym.datasets.sort_of_CLEVR_dataset.SortOfCLEVRDataset(root, train=True, transform=None, generate=False, dataset_size=10000, test_size=2000, img_size=75, object_size=5, nb_objects=6, test_id_analogy=False, test_id_analogy_threshold=3)

Bases: torch.utils.data.dataset.Dataset

_check_exists()
_generate(root, dataset_size, img_size, object_size, nb_objects)

Generate the Sort-of-CLEVR dataset if it doesn’t exist already.

getclass(idx)
getlatentvalue(idx)
getlatentclass(idx)
getlatentonehot(idx)

ReferentialGym.datasets.utils module

class ReferentialGym.datasets.utils.DictBatch(data)

Bases: object

pin_memory()
cuda()
keys()
ReferentialGym.datasets.utils.collate_dict_wrapper(batch)
class ReferentialGym.datasets.utils.ResizeNormalize(size, use_cuda=False, normalize_rgb_values=False, toPIL=False, rgb_scaler=1.0)

Bases: object

class ReferentialGym.datasets.utils.AddEgocentricInvariance(marker_demisize=2)

Bases: object

class ReferentialGym.datasets.utils.Rescale(output_size)

Bases: object

class ReferentialGym.datasets.utils.RescaleNormalize(size, use_cuda=False, normalize_rgb_values=False)

Bases: object

Module contents