state_dict = torch.load(args.eval_poison_path)
        poison_tuple_list, base_idx_list = state_dict['poison'], state_dict[
            'idx']
        print("=" * 100)
        print("=" * 100)
        print("Poisons loaded")
        print("Now evaluating on the target nets")
        t = 0
        tt = 0
    else:
        print(args)
        print("Path: {}".format(chk_path))
        # Otherwise, we craft new poisons
        if args.nearest:
            base_tensor_list, base_idx_list = fetch_nearest_poison_bases(
                sub_net_list, target, args.poison_num, args.poison_label,
                args.num_per_class, 'others', args.train_data_path,
                transform_test)

        else:
            # just fetch the first poison_num samples
            base_tensor_list, base_idx_list = fetch_poison_bases(
                args.poison_label,
                args.poison_num,
                subset='others',
                path=args.train_data_path,
                transforms=transform_test)
        base_tensor_list = [bt.to('cuda') for bt in base_tensor_list]
        print("Selected base image indices: {}".format(base_idx_list))

        if args.resume_poison_ite > 0:
            state_dict = torch.load(
Beispiel #2
0
        print("=" * 100)
        print("=" * 100)
        print("Poisons loaded")
        print("Now evaluating on the target nets")
        t = 0
        tt = 0
        assert False, "ToDo: check here!"
    else:
        print(args)
        print("Path: {}".format(chk_path))

        # Otherwise, we craft new poisons
        if args.nearest:
            base_tensor_list, base_idx_list = \
                fetch_nearest_poison_bases(sub_net_list, targets, args.poison_num,
                                           args.poison_label, args.num_per_class, subset='others',
                                           train_data_path=args.train_data_path, transforms=transform_test, )

        else:
            # just fetch the first poison_num samples
            base_tensor_list, base_idx_list = fetch_poison_bases(args.poison_label, args.poison_num, subset='others',
                                                                 path=args.train_data_path, transforms=transform_test)
        base_tensor_list = [bt.to(args.device) for bt in base_tensor_list]
        print("Selected base image indices: {}".format(base_idx_list))
        print("Target indices: {}".format(targets_indices))
        print("# Targets: {}, # Poisons: {}".format(len(targets), len(base_tensor_list)))

        if args.resume_poison_ite > 0:
            state_dict = torch.load(os.path.join(chk_path, "poison_%05d.pth" % args.resume_poison_ite))
            poison_tuple_list, base_idx_list = state_dict['poison'], state_dict['idx']
            poison_init = [pt.to('cuda') for pt, _ in poison_tuple_list]