Example #1
0
                        type=int,
                        default=40,
                        help='number of attack iterations')

    parser.add_argument('--resume', type=int, default=0)
    parser.add_argument('--save_model_loc', type=str, default=None)

    args = parser.parse_args()

    print(args)

    device = "cuda"

    set_seed(0)

    trainset, normalize, unnormalize = str2dataset(args.dataset, train=True)
    trainloader = torch.utils.data.DataLoader(trainset,
                                              batch_size=args.batch_size,
                                              shuffle=True,
                                              num_workers=2)

    net = str2model(path=args.save_model_loc,
                    dataset=args.dataset,
                    pretrained=args.resume).eval().to(device)

    if args.attack == "frank":
        attacker = FrankWolfe(predict=lambda x: net(normalize(x)),
                              loss_fn=nn.CrossEntropyLoss(reduction="sum"),
                              eps=args.eps,
                              kernel_size=5,
                              nb_iter=args.nb_iter,
Example #2
0
    parser.add_argument('--save_info_loc', type=str_or_none, default=None)

    parser.add_argument('--seed', type=int, default=0)
    parser.add_argument('--postprocess', type=str2bool, default=False)

    # parser.add_argument('--capacity_proj_mod', type=int, default=-1)

    args = parser.parse_args()

    print(args)

    device = "cuda"

    set_seed(args.seed)

    testset, normalize, unnormalize = str2dataset(args.dataset)
    testloader = torch.utils.data.DataLoader(testset,
                                             batch_size=args.batch_size,
                                             shuffle=False,
                                             num_workers=0)

    net = str2model(args.checkpoint, dataset=args.dataset,
                    pretrained=True).eval().to(device)

    for param in net.parameters():
        param.requires_grad = False

    projected_gradient = ProjectedGradient(
        predict=lambda x: net(normalize(x)),
        loss_fn=nn.CrossEntropyLoss(reduction="sum"),
        eps=args.eps,