Example #1
0
    current_means = class_means[:, order[:(iteration+1)*nb_cl]]
    causal_embed = np.load(ckp_path+'/causal_embed_run_{}_iteration_{}.npy'.format(args.run_id, iteration))
    causal_embed = torch.from_numpy(causal_embed).to(device)
    causal_embed = causal_embed/(torch.norm(causal_embed, 2, 1, keepdim=True))

    # each task
    for task_i in range(start_iter, iteration+1):
        if task_i == start_iter:
            indices = np.array([i in range(0, (task_i+1)*nb_cl) for i in map_input_labels])
        else:
            indices = np.array([i in range(task_i*nb_cl, (task_i+1)*nb_cl) for i in map_input_labels])
        current_eval_set = merge_images_labels(input_data[indices], map_input_labels[indices])
        evalset.imgs = evalset.samples = current_eval_set
        evalloader = torch.utils.data.DataLoader(evalset, batch_size=128,
            shuffle=False, num_workers=8, pin_memory=True)
        acc = compute_accuracy_TDE(tg_model, tg_feature_model, current_means,
                    evalloader, causal_embed, iteration=iteration-start_iter, print_info=False)
        all_accu_matrix[step_i, task_i-start_iter] = acc

    # cumul
    indices = np.array([i in range(0, (iteration+1)*nb_cl) for i in map_input_labels])
    current_eval_set = merge_images_labels(input_data[indices], map_input_labels[indices])
    evalset.imgs = evalset.samples = current_eval_set
    evalloader = torch.utils.data.DataLoader(evalset, batch_size=128,
        shuffle=False, num_workers=8, pin_memory=True)
    acc = compute_accuracy_TDE(tg_model, tg_feature_model, current_means,
                 evalloader, causal_embed, iteration=iteration-start_iter, print_info=False)
    all_accu_matrix[step_i, all_step_num] = acc
    print(acc)
    step_i += 1

Example #2
0
                    batch_size=eval_batch_size,
                    shuffle=False,
                    num_workers=args.num_workers,
                    pin_memory=True)
                if args.TDE:
                    causal_embed = np.load(
                        ckp_path +
                        '/causal_embed_run_{}_iteration_{}.npy'.format(
                            iteration_total, iteration))
                    causal_embed = torch.from_numpy(causal_embed).to(device)
                    causal_embed = causal_embed / (torch.norm(
                        causal_embed, 2, 1, keepdim=True))
                    ori_acc = compute_accuracy_TDE(tg_model,
                                                   tg_feature_model,
                                                   current_means,
                                                   evalloader,
                                                   causal_embed,
                                                   iteration=iteration -
                                                   start_iter)
                else:
                    ori_acc = compute_accuracy(tg_model, tg_feature_model,
                                               current_means, evalloader)

        ##############################################################
        # Calculate validation error of model on the cumul of classes:
        map_Y_valid_cumul = np.array(
            [order_list.index(i) for i in Y_valid_cumul])
        print('Computing cumulative accuracy...')
        # evalset.test_data = X_valid_cumul.astype('uint8')
        # evalset.test_labels = map_Y_valid_cumul
        current_eval_set = merge_images_labels(X_valid_cumul,