コード例 #1
0
    def test_tensor_dataset_helper_list_y(self):
        dataset_train_x = [torch.rand(50, 32, 32) for _ in range(5)]
        dataset_train_y = [torch.randint(0, 100, (50,)).tolist()
                           for _ in range(5)]

        dataset_test_x = [torch.rand(23, 32, 32) for _ in range(5)]
        dataset_test_y = [torch.randint(0, 100, (23,)).tolist()
                          for _ in range(5)]

        cl_scenario = create_generic_scenario_from_tensors(
            dataset_train_x, dataset_train_y, dataset_test_x, dataset_test_y,
            [0] * 5)

        self.assertEqual(5, len(cl_scenario.train_stream))
        self.assertEqual(5, len(cl_scenario.test_stream))
        self.assertEqual(5, cl_scenario.n_experiences)

        for exp_id in range(cl_scenario.n_experiences):
            scenario_train_x, scenario_train_y, _ = \
                load_all_dataset(cl_scenario.train_stream[exp_id].dataset)
            scenario_test_x, scenario_test_y, _ = \
                load_all_dataset(cl_scenario.test_stream[exp_id].dataset)

            self.assertTrue(torch.all(torch.eq(
                dataset_train_x[exp_id],
                scenario_train_x)))
            self.assertSequenceEqual(
                dataset_train_y[exp_id],
                scenario_train_y.tolist())
            self.assertSequenceEqual(
                dataset_train_y[exp_id],
                cl_scenario.train_stream[exp_id].dataset.targets)
            self.assertEqual(0, cl_scenario.train_stream[exp_id].task_label)

            self.assertTrue(torch.all(torch.eq(
                dataset_test_x[exp_id],
                scenario_test_x)))
            self.assertSequenceEqual(
                dataset_test_y[exp_id],
                scenario_test_y.tolist())
            self.assertSequenceEqual(
                dataset_test_y[exp_id],
                cl_scenario.test_stream[exp_id].dataset.targets)
            self.assertEqual(0, cl_scenario.test_stream[exp_id].task_label)
コード例 #2
0
    def test_tensor_dataset_helper_tensor_y(self):

        train_exps = [[torch.rand(50, 32, 32),
                       torch.randint(0, 100, (50, ))] for _ in range(5)]
        test_exps = [[torch.rand(23, 32, 32),
                      torch.randint(0, 100, (23, ))] for _ in range(5)]

        cl_scenario = create_generic_scenario_from_tensor_lists(
            train_exps, test_exps, [0] * 5)

        self.assertEqual(5, len(cl_scenario.train_stream))
        self.assertEqual(5, len(cl_scenario.test_stream))
        self.assertEqual(5, cl_scenario.n_experiences)

        for exp_id in range(cl_scenario.n_experiences):
            scenario_train_x, scenario_train_y, _ = \
                load_all_dataset(cl_scenario.train_stream[exp_id].dataset)
            scenario_test_x, scenario_test_y, _ = \
                load_all_dataset(cl_scenario.test_stream[exp_id].dataset)

            self.assertTrue(
                torch.all(torch.eq(train_exps[exp_id][0], scenario_train_x)))
            self.assertTrue(
                torch.all(torch.eq(train_exps[exp_id][1], scenario_train_y)))
            self.assertSequenceEqual(
                train_exps[exp_id][1].tolist(),
                cl_scenario.train_stream[exp_id].dataset.targets)
            self.assertEqual(0, cl_scenario.train_stream[exp_id].task_label)

            self.assertTrue(
                torch.all(torch.eq(test_exps[exp_id][0], scenario_test_x)))
            self.assertTrue(
                torch.all(torch.eq(test_exps[exp_id][1], scenario_test_y)))
            self.assertSequenceEqual(
                test_exps[exp_id][1].tolist(),
                cl_scenario.test_stream[exp_id].dataset.targets)
            self.assertEqual(0, cl_scenario.test_stream[exp_id].task_label)