def SplitTinyImageNet(n_experiences=10,
                      return_task_id=False,
                      seed=0,
                      fixed_class_order=None,
                      train_transform=_default_train_transform,
                      test_transform=_default_test_transform):
    """
    Creates a CL scenario using the Tiny ImageNet dataset.
    If the dataset is not present in the computer the method automatically
    download it and store the data in the data folder.

    :param n_experiences: The number of experiences in the current scenario.
    :param return_task_id: if True, for every experience the task id is returned
        and the Scenario is Multi Task. This means that the scenario returned
        will be of type ``NCMultiTaskScenario``. If false the task index is
        not returned (default to 0 for every batch) and the returned scenario
        is of type ``NCSingleTaskScenario``.
    :param seed: A valid int used to initialize the random number generator.
        Can be None.
    :param fixed_class_order: A list of class IDs used to define the class
        order. If None, value of ``seed`` will be used to define the class
        order. If non-None, ``seed`` parameter will be ignored.
        Defaults to None.
    :param train_transform: The transformation to apply to the training data,
        e.g. a random crop, a normalization or a concatenation of different
        transformations (see torchvision.transform documentation for a
        comprehensive list of possible transformations).
        If no transformation is passed, the default train transformation
        will be used.
    :param test_transform: The transformation to apply to the test data,
        e.g. a random crop, a normalization or a concatenation of different
        transformations (see torchvision.transform documentation for a
        comprehensive list of possible transformations).
        If no transformation is passed, the default test transformation
        will be used.

    :returns: A :class:`NCMultiTaskScenario` instance initialized for the the
        MT scenario using CIFAR10 if the parameter ``return_task_id`` is True,
        a :class:`NCSingleTaskScenario` initialized for the SIT scenario using
        CIFAR10 otherwise.
        """

    train_set, test_set = _get_tiny_imagenet_dataset(train_transform,
                                                     test_transform)

    if return_task_id:
        return nc_scenario(train_dataset=train_set,
                           test_dataset=test_set,
                           n_experiences=n_experiences,
                           task_labels=True,
                           seed=seed,
                           fixed_class_order=fixed_class_order,
                           class_ids_from_zero_in_each_exp=True)
    else:
        return nc_scenario(train_dataset=train_set,
                           test_dataset=test_set,
                           n_experiences=n_experiences,
                           task_labels=False,
                           seed=seed,
                           fixed_class_order=fixed_class_order)
Beispiel #2
0
    def test_nc_sit_type(self):
        mnist_train = MNIST('./data/mnist', train=True, download=True)
        mnist_test = MNIST('./data/mnist', train=False, download=True)
        my_nc_scenario = nc_scenario(
            mnist_train, mnist_test, 5, task_labels=False)

        for batch_info in my_nc_scenario.train_stream:
            self.assertIsInstance(batch_info, Experience)

        for batch_info in my_nc_scenario.test_stream:
            self.assertIsInstance(batch_info, Experience)
Beispiel #3
0
    def test_nc_mt_type(self):
        mnist_train = MNIST('./data/mnist', train=True, download=True)
        mnist_test = MNIST('./data/mnist', train=False, download=True)
        my_nc_scenario = nc_scenario(
            mnist_train, mnist_test, 5, task_labels=True,
            class_ids_from_zero_in_each_exp=True)

        for task_info in my_nc_scenario.train_stream:
            self.assertIsInstance(task_info, Experience)

        for task_info in my_nc_scenario.test_stream:
            self.assertIsInstance(task_info, Experience)
Beispiel #4
0
    def test_nc_sit_type(self):
        mnist_train = MNIST(root=expanduser("~") + "/.avalanche/data/mnist/",
                            train=True,
                            download=True)
        mnist_test = MNIST(root=expanduser("~") + "/.avalanche/data/mnist/",
                           train=False,
                           download=True)
        my_nc_scenario = nc_scenario(mnist_train,
                                     mnist_test,
                                     5,
                                     task_labels=False)

        for batch_info in my_nc_scenario.train_stream:
            self.assertIsInstance(batch_info, Experience)

        for batch_info in my_nc_scenario.test_stream:
            self.assertIsInstance(batch_info, Experience)
Beispiel #5
0
def SplitTinyImageNet(n_experiences=10,
                      return_task_id=False,
                      seed=0,
                      fixed_class_order=None,
                      train_transform=_default_train_transform,
                      eval_transform=_default_eval_transform):
    """
    Creates a CL scenario using the Tiny ImageNet dataset.

    If the dataset is not present in the computer, this method will
    automatically download and store it.

    The returned scenario will return experiences containing all patterns of a
    subset of classes, which means that each class is only seen "once".
    This is one of the most common scenarios in the Continual Learning
    literature. Common names used in literature to describe this kind of
    scenario are "Class Incremental", "New Classes", etc. By default,
    an equal amount of classes will be assigned to each experience.

    This generator doesn't force a choice on the availability of task labels,
    a choice that is left to the user (see the `return_task_id` parameter for
    more info on task labels).

    The scenario instance returned by this method will have two fields,
    `train_stream` and `test_stream`, which can be iterated to obtain
    training and test :class:`Experience`. Each Experience contains the
    `dataset` and the associated task label.

    The scenario API is quite simple and is uniform across all scenario
    generators. It is recommended to check the tutorial of the "benchmark" API,
    which contains usage examples ranging from "basic" to "advanced".

    :param n_experiences: The number of experiences in the current scenario.
    :param return_task_id: if True, a progressive task id is returned for every
        experience. If False, all experiences will have a task ID of 0.
    :param seed: A valid int used to initialize the random number generator.
        Can be None.
    :param fixed_class_order: A list of class IDs used to define the class
        order. If None, value of ``seed`` will be used to define the class
        order. If non-None, ``seed`` parameter will be ignored.
        Defaults to None.
    :param train_transform: The transformation to apply to the training data,
        e.g. a random crop, a normalization or a concatenation of different
        transformations (see torchvision.transform documentation for a
        comprehensive list of possible transformations).
        If no transformation is passed, the default train transformation
        will be used.
    :param eval_transform: The transformation to apply to the test data,
        e.g. a random crop, a normalization or a concatenation of different
        transformations (see torchvision.transform documentation for a
        comprehensive list of possible transformations).
        If no transformation is passed, the default test transformation
        will be used.

    :returns: A properly initialized :class:`NCScenario` instance.
    """

    train_set, test_set = _get_tiny_imagenet_dataset(train_transform,
                                                     eval_transform)

    if return_task_id:
        return nc_scenario(train_dataset=train_set,
                           test_dataset=test_set,
                           n_experiences=n_experiences,
                           task_labels=True,
                           seed=seed,
                           fixed_class_order=fixed_class_order,
                           class_ids_from_zero_in_each_exp=True)
    else:
        return nc_scenario(train_dataset=train_set,
                           test_dataset=test_set,
                           n_experiences=n_experiences,
                           task_labels=False,
                           seed=seed,
                           fixed_class_order=fixed_class_order)