if args.model2load.endswith('.ckpt'):
            model = load_ckpt_model(model=model,
                                    name='fc1',
                                    ckpt_file=args.model2load,
                                    device=device,
                                    param2load=None)
        elif args.model2load.endswith('.mat'):
            model = load_mat_model(model=model,
                                   name='fc1',
                                   mat_file=args.model2load,
                                   device=device,
                                   param2load=None)
        elif args.model2load.endswith('.pth'):
            model = load_pth_model(model=model,
                                   name='fc1',
                                   pth_file=args.model2load,
                                   device=device,
                                   param2load=None)
        else:
            raise ValueError('The format of %s is not supported' %
                             args.model2load)

    # Parse the optimizer
    optimizer = parse_optim(policy=args.optim, params=model.parameters())
    # Parse norms
    norm = args.norm if args.norm > 0 else np.inf

    # Parse parameter
    alpha_list = discrete_seq(**args.alpha)
    beta_list = discrete_seq(**args.beta)
    eps_list = discrete_seq(**args.eps)
Beispiel #2
0
    model = MLP(in_dim=args.in_dim,
                hidden_dims=args.hidden_dims,
                out_dim=args.out_dim,
                nonlinearity=args.nonlinearity)
    model = model.cuda(device) if use_gpu else model
    if args.model2load.endswith('.ckpt'):
        ckpt = torch.load(args.model2load)
        model.load_state_dict(ckpt)
    elif args.model2load.endswith('.mat'):
        model = load_mat_model(model=model,
                               name='fc1',
                               mat_file=args.model2load,
                               device=device)
    elif args.model2load.endswith('.pth'):
        model = load_pth_model(model=model,
                               name='fc1',
                               pth_file=args.model2load,
                               device=device)
    else:
        raise ValueError('The format of %s is not supported' % args.model2load)

    # Parse norm
    norm = args.norm if args.norm > 0 else np.inf

    # Prepare the item to save
    configs = {kwarg: value for kwarg, value in args._get_kwargs()}
    tosave = {
        'model_summary': str(model),
        'setup_config': configs,
        'guaranteed_distances': []
    }
Beispiel #3
0
        if args.model2load.endswith('.ckpt'):
            model = load_ckpt_model(model=model,
                                    name='lenet',
                                    ckpt_file=args.model2load,
                                    device=device,
                                    param2load=args.load_mode)
        elif args.model2load.endswith('.mat'):
            model = load_mat_model(model=model,
                                   name='lenet',
                                   mat_file=args.model2load,
                                   device=device,
                                   param2load=args.load_mode)
        elif args.model2load.endswith('.pth'):
            model = load_pth_model(model=model,
                                   name='lenet',
                                   pth_file=args.model2load,
                                   device=device,
                                   param2load=args.load_mode)
        else:
            raise ValueError('The format of %s is not supported' %
                             args.model2load)

    # Parse the optimizer
    if args.frozen_mode == None:
        optimizer = parse_optim(policy=args.optim, params=model.parameters())
    elif args.frozen_mode.lower() in [
            'fc',
    ]:
        for param in model.fc_params():
            param.requires_grad = False
        optimizer = parse_optim(policy=args.optim, params=model.conv_params())