Beispiel #1
0
def test_time(tmpdir):
    global DATA_PATH
    cl_dataset = CIFAR100(data_path=DATA_PATH,
                          download=False,
                          train=True,
                          labels_type="category",
                          task_labels="lifelong")
    # in practice the construction is part by part to reduce data load but here we do it at once
    x, y, t = cl_dataset.get_data()
    h5_filename = os.path.join(tmpdir, "test_time_h5.hdf5")
    h5dataset = H5Dataset(x, y, t, data_path=h5_filename)

    task_set = H5TaskSet(h5_filename, y=h5dataset.get_class_vector(), t=h5dataset.get_task_indexes(), trsf=None)

    start = time.time()
    for i in range(10000):
        a = task_set[5]
    end = time.time()
    print(f"normal __getitem__ {end - start}")

    start = time.time()
    with h5py.File(h5_filename, 'r') as hf:
        for i in range(10000):
            x = hf['x'][5]
            y = hf['y'][5]
            if 't' in hf.keys():
                t = hf['t'][5]
            else:
                t = -1
    end = time.time()
    print(f"open only once __getitem__ {end - start}")
Beispiel #2
0
def test_scenario_CIFAR100_Scenarios():
    dataset = CIFAR100(DATA_PATH,
                       train=True,
                       labels_type="category",
                       task_labels="category")
    scenario = ContinualScenario(dataset)
    assert scenario.nb_classes == 20
    assert scenario.nb_tasks == 20

    dataset = CIFAR100(DATA_PATH,
                       train=True,
                       labels_type="category",
                       task_labels="class")
    scenario = ContinualScenario(dataset)
    assert scenario.nb_classes == 20
    assert scenario.nb_tasks == 100

    dataset = CIFAR100(DATA_PATH,
                       train=True,
                       labels_type="class",
                       task_labels="class")
    scenario = ContinualScenario(dataset)
    assert scenario.nb_classes == 100
    assert scenario.nb_tasks == 100

    dataset = CIFAR100(DATA_PATH,
                       train=True,
                       labels_type="class",
                       task_labels="category")
    scenario = ContinualScenario(dataset)
    assert scenario.nb_classes == 100
    assert scenario.nb_tasks == 20

    dataset = CIFAR100(DATA_PATH,
                       train=True,
                       labels_type="category",
                       task_labels="lifelong")
    scenario = ContinualScenario(dataset)
    assert scenario.nb_classes == 20
    assert scenario.nb_tasks == 5
Beispiel #3
0
def test_on_array_dataset(tmpdir):
    filename_h5 = os.path.join(tmpdir, "test_CIFAR100_h5.hdf5")

    cl_dataset = CIFAR100(data_path=DATA_PATH,
                          download=False,
                          train=True,
                          labels_type="category",
                          task_labels="lifelong")
    # in practice the construction is part by part to reduce data load but here we do it at once
    x, y, t = cl_dataset.get_data()
    h5dataset = H5Dataset(x, y, t, data_path=filename_h5)

    scenario = ContinualScenario(h5dataset)

    for task_set in scenario:
        loader = DataLoader(task_set, batch_size=64)
        for x, y, t in loader:
            assert x.shape == torch.Size([64, 3, 32, 32])
            break

    assert scenario.nb_tasks == 5  # number of task of CIFAR100Lifelong
Beispiel #4
0
def test_on_array_dataset_incremental(tmpdir):
    filename_h5 = os.path.join(tmpdir, "test_CIFAR100_h5.hdf5")

    nb_tasks = 10

    cl_dataset = CIFAR100(data_path=DATA_PATH,
                          download=False,
                          train=True)
    # in practice the construction is part by part to reduce data load but here we do it at once
    x, y, t = cl_dataset.get_data()
    h5dataset = H5Dataset(x, y, t, data_path=filename_h5)

    scenario = ClassIncremental(h5dataset, nb_tasks=nb_tasks)

    for task_set in scenario:
        loader = DataLoader(task_set, batch_size=64)
        for x, y, t in loader:
            assert x.shape == torch.Size([64, 3, 32, 32])
            break

    assert scenario.nb_tasks == nb_tasks  # number of task of CIFAR100Lifelong
Beispiel #5
0
def test_h5dataset_reloading_slow(tmpdir):
    filename_h5 = os.path.join(tmpdir, "test_h5.hdf5")

    nb_tasks = 5

    cl_dataset = CIFAR100(data_path=DATA_PATH,
                          download=False,
                          train=True,
                          labels_type="category",
                          task_labels="lifelong")
    x, y, t = cl_dataset.get_data()

    # create dataset
    h5dataset = H5Dataset(x, y, t, data_path=filename_h5)
    # destroy object
    del h5dataset

    # reload data set
    h5dataset_reloaded = H5Dataset(x=None, y=None, t=None, data_path=filename_h5)

    scenario = ContinualScenario(h5dataset_reloaded)

    for task_set in scenario:
        loader = DataLoader(task_set)
        for _ in loader:
            pass

    assert scenario.nb_tasks == nb_tasks

    task_order = np.arange(nb_tasks)

    sub_scenario = create_subscenario(scenario, task_order[:-1])

    assert sub_scenario.nb_tasks == nb_tasks-1


    np.random.shuffle(task_order)
    sub_scenario = create_subscenario(scenario, task_order)
    assert sub_scenario.nb_tasks == nb_tasks
Beispiel #6
0
def test_scenario_CIFAR100_CoarseLabels():
    dataset = CIFAR100(DATA_PATH, train=True, labels_type="category")
    scenario = ClassIncremental(dataset, increment=10)

    assert scenario.nb_classes == 20
    assert scenario.nb_tasks == 2
Beispiel #7
0
def test_scenario_CIFAR100_ClassIncremental():
    dataset = CIFAR100(DATA_PATH, train=True)
    scenario = ClassIncremental(dataset, increment=50)

    assert scenario.nb_classes == 100
    assert scenario.nb_tasks == 2