示例#1
0
    parser.add_argument('-d', '--data-configs', required=False,
                        default='../configs/data-minerva-mnist.json',
                        help='Folder where test data stored in.')
    parser.add_argument('-o', '--output-root', required=False,
                        default='../results',
                        help='Folder for outputs.')
    parser.add_argument('--debug', required=False, default=True)
    parser.add_argument('-s', '--save-results', required=False, default=True, help='Save output or not')

    args = parser.parse_args()

    print('------AUGMENT SUMMARY-------')
    print('TRANSFORMATION CONFIGS:', args.trans_configs)
    print('MODEL CONFIGS:', args.model_configs)
    print('DATA CONFIGS:', args.data_configs)
    print('OUTPUT ROOT:', args.output_root)
    print('DEBUGGING MODE:', args.debug)
    print('SAVING OUTPUT:', args.save_results)
    print('----------------------------\n')

    # parse configurations (into a dictionary) from json file
    trans_configs = load_from_json(args.trans_configs)
    model_configs = load_from_json(args.model_configs)
    data_configs = load_from_json(args.data_configs)

    # -------- test transformations -------------
    evaluate(trans_configs=trans_configs,
             model_configs=model_configs,
             data_configs=data_configs,
             save=args.save_results,
             output_dir=args.output_root)
    """

    parser.add_argument('-d',
                        '--data-configs',
                        required=False,
                        default='../configs/demo/data-mnist.json',
                        help='Folder where test data stored in.')
    parser.add_argument('-o',
                        '--output-root',
                        required=False,
                        default='../../task1_data',
                        help='Folder for outputs.')
    parser.add_argument('--debug', required=False, default=True)
    args = parser.parse_args()

    data_configs = load_from_json(args.data_configs)
    # load the benign samples
    bs_file = os.path.join(data_configs.get('dir'),
                           data_configs.get('bs_file'))
    x_bs = np.load(bs_file)
    img_rows, img_cols = x_bs.shape[1], x_bs.shape[2]

    # load the corresponding true labels
    label_file = os.path.join(data_configs.get('dir'),
                              data_configs.get('label_file'))
    labels = np.load(label_file)

    # get random subsamples
    # for MNIST, num_classes is 10
    # files "subsamples-mnist-ratio_0.1-xxxxxx.npy" and "sublabels-mnist-ratio_0.1-xxxxxx.npy"
    # will be generated and saved at "/results" folder, where "xxxxxx" are timestamps.
示例#3
0
    print(f'EXPERIMENT ROOT: {args.experiment_root}')
    print(f'POOL CONFIGS: {args.pool_configs}')
    print(f'SELECTED POOL: {args.selected_pool}')
    print(f'MODEL CONFIGS: {args.model_configs}')
    print(f'DATA CONFIGS: {args.data_configs}')
    print(f'BENIGN SAMPLES: {args.benign_samples}')
    print(f'ATTACK CONFIGS: {args.attack_configs}')
    print(f'SELECTED ATTACK: {args.selected_attacks}')
    print(f'TARGETED MODEL: {args.targeted_model}')
    print(f'EOT or not: {args.eot}')
    print(f'OUTPUT ROOT: {args.output_root}')
    print(f'DEBUGGING MODE: {args.debug}')
    print('-------------------------------\n')

    # parse configurations from json file
    pool_configs = load_from_json(args.pool_configs)
    model_configs = load_from_json(args.model_configs)
    model_configs['wresnet']['dir'] = args.experiment_root + model_configs.get(
        'wresnet').get('dir')
    model_configs['shake26']['dir'] = args.experiment_root + model_configs.get(
        'wresnet').get('dir')
    data_configs = load_from_json(args.data_configs)
    data_configs['dir'] = args.experiment_root + data_configs.get('dir')
    attack_configs = load_from_json(args.attack_configs)

    # load the targeted model
    if args.targeted_model == 'single':
        prefix = f'AE-cifar100-wresnet-{args.targeted_model}'
        model_file = os.path.join(
            model_configs.get('wresnet').get('dir'),
            model_configs.get('wresnet').get('um_file'))
示例#4
0
                        default='../../experiment/demo/results',
                        help='Folder for outputs.')

    args = parser.parse_args()


    print("------AUGMENT SUMMARY-------")
    print("EXPERIMENT ROOT:", args.experiment_root)
    print("MODEL CONFIGS:", args.model_configs)
    print("OUTPUT ROOT:", args.output_root)
    print('----------------------------\n')

    # ----------------------------
    # parse configurations (into a dictionary) from json file
    # ----------------------------
    model_configs = load_from_json(args.model_configs)
    model_configs["wresnet"]["dir"] = args.experiment_root + model_configs.get("wresnet").get("dir")

    # ---------------------------
    # load the targeted model
    # ---------------------------
    # In the context of the adversarially trained model,
    # we use the undefended model as adversary's target model.
    savefile = "AdvTrained-cifar100.pth"
    model_file = os.path.join(model_configs.get("wresnet").get('dir'), model_configs.get("wresnet").get("pgd_trained_cifar"))
    model, _, _ = load_model(file=model_file, model_configs=model_configs.get("wresnet"), trans_configs=None)

    (x_train, y_train), _ = load_data('cifar100')

    pgd_adv_train(model=model,
                  data=(x_train, y_train),