Exemplo n.º 1
0
 def test_ar1(self):
     my_nc_benchmark = self.load_ar1_scenario()
     strategy = AR1(train_epochs=1,
                    train_mb_size=10,
                    eval_mb_size=10,
                    rm_sz=200)
     StrategyTest.run_strategy(self, my_nc_benchmark, strategy)
Exemplo n.º 2
0
    def test_ar1(self):
        my_nc_scenario = self.load_ar1_scenario(fast_test=self.fast_test)

        strategy = AR1(train_epochs=1,
                       train_mb_size=10,
                       eval_mb_size=10,
                       rm_sz=200)

        self.run_strategy(my_nc_scenario, strategy)
Exemplo n.º 3
0
def main(args):
    # Device config
    device = torch.device(f"cuda:{args.cuda}" if torch.cuda.is_available()
                          and args.cuda >= 0 else "cpu")
    # ---------

    # --- TRANSFORMATIONS
    train_transform = transforms.Compose([
        Resize(224),
        ToTensor(),
        transforms.Normalize((0.1307, ), (0.3081, ))
    ])
    test_transform = transforms.Compose([
        Resize(224),
        ToTensor(),
        transforms.Normalize((0.1307, ), (0.3081, ))
    ])
    # ---------

    # --- SCENARIO CREATION
    scenario = SplitCIFAR10(5,
                            train_transform=train_transform,
                            eval_transform=test_transform)
    # ---------

    # CREATE THE STRATEGY INSTANCE
    cl_strategy = AR1(criterion=CrossEntropyLoss(), device=device)

    # TRAINING LOOP
    print('Starting experiment...')
    results = []
    for experience in scenario.train_stream:
        print("Start of experience: ", experience.current_experience)
        print("Current Classes: ", experience.classes_in_this_experience)

        cl_strategy.train(experience, num_workers=4)
        print('Training completed')

        print('Computing accuracy on the whole test set')
        results.append(cl_strategy.eval(scenario.test_stream, num_workers=4))
Exemplo n.º 4
0
    cl_strategy = EWC(model,
                      Adam(model.parameters(), lr=0.001),
                      CrossEntropyLoss(),
                      ewc_lambda=0.5,
                      mode="separate",
                      train_mb_size=args.batch_size,
                      train_epochs=args.num_epochs,
                      eval_mb_size=args.batch_size * 2,
                      evaluator=eval_plugin,
                      device=device)
elif (args.cl_strategy == "AR1"):
    cl_strategy = AR1(model,
                      Adam(model.parameters(), lr=0.001),
                      CrossEntropyLoss(),
                      ewc_lambda=0.5,
                      train_mb_size=args.batch_size,
                      train_epochs=args.num_epochs,
                      eval_mb_size=args.batch_size * 2,
                      evaluator=eval_plugin,
                      device=device)
elif (args.cl_strategy == "GDumb"):
    cl_strategy = GDumb(model,
                        Adam(model.parameters(), lr=0.001),
                        CrossEntropyLoss(),
                        mem_size=200,
                        train_mb_size=args.batch_size,
                        train_epochs=args.num_epochs,
                        eval_mb_size=args.batch_size * 2,
                        evaluator=eval_plugin,
                        device=device)
else: