Example #1
0
        "train_start",
        TRAIN_START,
        "Starting point (inclusive)"
        "of range of train examples to use",
    )
    flags.DEFINE_integer(
        "train_end",
        TRAIN_END,
        "Ending point (non-inclusive) "
        "of range of train examples to use",
    )
    flags.DEFINE_integer(
        "test_start",
        TEST_START,
        "Starting point (inclusive) "
        "of range of test examples to use",
    )
    flags.DEFINE_integer(
        "test_end",
        TEST_END,
        "End point (non-inclusive) of "
        "range of test examples to use",
    )
    flags.DEFINE_string("recipe", RECIPE,
                        "Name of function from attack_bundling"
                        " to run")
    flags.DEFINE_string("which_set", WHICH_SET, '"train" or "test"')
    flags.DEFINE_string("report_path", REPORT_PATH, "Report path")
    flags.DEFINE_integer("batch_size", BATCH_SIZE, "Batch size")
    tf.app.run()
                    "This might mean you generated them for a model with "
                    "inputs in [0, 1] and are now using them for a model "
                    "with inputs in [0, 255] or something like that. "
                    "Or it could be OK if you're evaluating on a very small "
                    "batch.")

  report_path = FLAGS.report_path
  if report_path is None:
    suffix = "_bundled_examples_report.joblib"
    assert model_filepath.endswith('.joblib')
    report_path = model_filepath[:-len('.joblib')] + suffix

  goal = MaxConfidence()
  bundle_examples_with_goal(sess, model, adv_x_list, y, goal,
                            report_path, batch_size=FLAGS.batch_size)


if __name__ == '__main__':
  flags.DEFINE_string('report_path', None, 'Report path')
  flags.DEFINE_integer('train_start', TRAIN_START, 'Starting point (inclusive)'
                       'of range of train examples to use')
  flags.DEFINE_integer('train_end', TRAIN_END, 'Ending point (non-inclusive) '
                       'of range of train examples to use')
  flags.DEFINE_integer('test_start', TEST_START, 'Starting point '
                       '(inclusive) of range of test examples to use')
  flags.DEFINE_integer('test_end', TEST_END, 'End point (non-inclusive) of '
                       'range of test examples to use')
  flags.DEFINE_string('which_set', WHICH_SET, '"train" or "test"')
  flags.DEFINE_integer('batch_size', BATCH_SIZE, 'batch size')
  tf.app.run()
Example #3
0
    run_trainer(hparams)


if __name__ == '__main__':
    flags.DEFINE_integer('train_start', 0,
                         'Index of first training set example.')
    flags.DEFINE_integer('train_end', 60000,
                         'Index of last training set example.')
    flags.DEFINE_integer('test_start', 0, 'Index of first test set example.')
    flags.DEFINE_integer('test_end', 10000, 'Index of last test set example.')
    flags.DEFINE_integer('nb_epochs', 6, 'Number of epochs to train model.')
    flags.DEFINE_integer('batch_size', 128, 'Size of training batches.')
    flags.DEFINE_boolean('adv_train', False,
                         'Whether to do adversarial training.')
    flags.DEFINE_boolean('save', True, 'Whether to save from a checkpoint.')
    flags.DEFINE_string('save_dir', 'runs/X', 'Location to store logs/model.')
    flags.DEFINE_string('model_type', 'madry',
                        'Model type: basic|madry|resnet_tf.')
    flags.DEFINE_string(
        'attack_type_train', 'MadryEtAl_y_multigpu',
        'Attack type for adversarial training:\
                        FGSM|MadryEtAl{,_y}{,_multigpu}.')
    flags.DEFINE_string('attack_type_test', 'FGSM',
                        'Attack type for test: FGSM|MadryEtAl{,_y}.')
    flags.DEFINE_string('dataset', 'mnist', 'Dataset mnist|cifar10.')
    flags.DEFINE_boolean(
        'only_adv_train', False,
        'Do not train with clean examples when adv training.')
    flags.DEFINE_integer('save_steps', 50, 'Save model per X steps.')
    flags.DEFINE_integer('attack_nb_iter_train', None,
                         'Number of iterations of training attack.')
Example #4
0
    check_installation(__file__)

    mnist_tutorial(
        nb_epochs=FLAGS.nb_epochs,
        batch_size=FLAGS.batch_size,
        learning_rate=FLAGS.learning_rate,
        clean_train=FLAGS.clean_train,
        backprop_through_attack=FLAGS.backprop_through_attack,
        nb_filters=FLAGS.nb_filters,
        attack_string=FLAGS.attack,
    )


if __name__ == "__main__":
    flags.DEFINE_integer("nb_filters", NB_FILTERS, "Model size multiplier")
    flags.DEFINE_integer("nb_epochs", NB_EPOCHS,
                         "Number of epochs to train model")
    flags.DEFINE_integer("batch_size", BATCH_SIZE, "Size of training batches")
    flags.DEFINE_float("learning_rate", LEARNING_RATE,
                       "Learning rate for training")
    flags.DEFINE_bool("clean_train", True, "Train on clean examples")
    flags.DEFINE_bool(
        "backprop_through_attack",
        False,
        ("If True, backprop through adversarial example "
         "construction process during adversarial training"),
    )
    flags.DEFINE_string("attack", "fgsm",
                        "Adversarial attack crafted and used for training")
    tf.app.run()
    except ValueError:
        raise ValueError(argv)
    print(filepath)
    make_confidence_report_bundled(filepath=filepath,
                                   test_start=FLAGS.test_start,
                                   test_end=FLAGS.test_end,
                                   which_set=FLAGS.which_set,
                                   recipe=FLAGS.recipe,
                                   report_path=FLAGS.report_path)


if __name__ == '__main__':
    flags.DEFINE_integer(
        'train_start', TRAIN_START, 'Starting point (inclusive)'
        'of range of train examples to use')
    flags.DEFINE_integer(
        'train_end', TRAIN_END, 'Ending point (non-inclusive) '
        'of range of train examples to use')
    flags.DEFINE_integer(
        'test_start', TEST_START, 'Starting point (inclusive) '
        'of range of test examples to use')
    flags.DEFINE_integer(
        'test_end', TEST_END, 'End point (non-inclusive) of '
        'range of test examples to use')
    flags.DEFINE_string('recipe', RECIPE,
                        'Name of function from attack_bundling'
                        ' to run')
    flags.DEFINE_string('which_set', WHICH_SET, '"train" or "test"')
    flags.DEFINE_string('report_path', REPORT_PATH, 'Report path')
    tf.app.run()
Example #6
0
        "TSNE of Sign of Adv Gradients, SNNLCrossEntropy Model, factor:" +
        str(FLAGS.SNNL_factor),
        fontsize=42)
    imscatter(X_embedded, x_test[:batch_size], zoom=2, cmap="Purples")
    plt.savefig(output_dir + 'adversarial_gradients_SNNL_factor_' +
                str(SNNL_factor) + '.png')


def main(argv=None):
    SNNL_example(nb_epochs=FLAGS.nb_epochs,
                 batch_size=FLAGS.batch_size,
                 learning_rate=FLAGS.learning_rate,
                 nb_filters=FLAGS.nb_filters,
                 SNNL_factor=FLAGS.SNNL_factor,
                 output_dir=FLAGS.output_dir)


if __name__ == '__main__':
    flags.DEFINE_integer('nb_filters', NB_FILTERS, 'Model size multiplier')
    flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                         'Number of epochs to train model')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches')
    flags.DEFINE_float('SNNL_factor', SNNL_FACTOR,
                       'Multiplier for Soft Nearest Neighbor Loss')
    flags.DEFINE_float('learning_rate', LEARNING_RATE,
                       'Learning rate for training')
    flags.DEFINE_string('output_dir', OUTPUT_DIR,
                        'output directory for saving figures')

    tf.app.run()
Example #7
0
                   batch_size=FLAGS.batch_size, 
                   num_capsules_output=FLAGS.num_capsules_output, 
                   output_atoms=FLAGS.output_atoms,
                   num_routing=FLAGS.num_routing,
                   learning_rate=FLAGS.learning_rate,
                   nb_filters=FLAGS.nb_filters)


if __name__ == '__main__':  
  flags.DEFINE_integer('train_end', TRAIN_END,
                       'Number of training data')
  flags.DEFINE_integer('test_end', TEST_END,
                       'Number of test data')
  flags.DEFINE_integer('nb_filters', NB_FILTERS,
                       'Model size multiplier')
  flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                       'Number of epochs to train model')
  flags.DEFINE_integer('batch_size', BATCH_SIZE,
                       'Size of training batches')
  flags.DEFINE_integer('num_capsules_output', NUM_CAPSULES_OUTPUT,
                       'Number of class capsules and background capsules')
  flags.DEFINE_integer('output_atoms', OUTPUT_ATOMS,
                       'Size of each capsule')
  flags.DEFINE_integer('num_routing', NUM_ROUTING,
                       'Number of routing in capsule layer')
  flags.DEFINE_float('learning_rate', LEARNING_RATE,
                     'Learning rate for training')
  flags.DEFINE_string('dataset', DATASET, 'SVHN or CIFAR10')

  tf.app.run()
        report.train_adv_train_adv_eval = accuracy
    return report


def main(argv=None):
    from cleverhans_tutorials import check_installation
    check_installation(__file__)

    mnist_tutorial(
        nb_epochs=FLAGS.nb_epochs, batch_size=FLAGS.batch_size,
        learning_rate=FLAGS.learning_rate, clean_train=FLAGS.clean_train,
        backprop_through_attack=FLAGS.backprop_through_attack,
        nb_filters=FLAGS.nb_filters, attack_string=FLAGS.attack)


if __name__ == '__main__':
    flags.DEFINE_integer('nb_filters', NB_FILTERS,
                         'Model size multiplier')
    flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                         'Number of epochs to train model')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches')
    flags.DEFINE_float('learning_rate', LEARNING_RATE,
                       'Learning rate for training')
    flags.DEFINE_bool('clean_train', True, 'Train on clean examples')
    flags.DEFINE_bool('backprop_through_attack', False,
                      ('If True, backprop through adversarial example '
                       'construction process during adversarial training'))
    flags.DEFINE_string('attack', 'fgsm',
                        'Adversarial attack crafted and used for training')
    tf.app.run()
Example #9
0
  Run the tutorial using command line flags.
  """
    from cleverhans_tutorials import check_installation
    check_installation(__file__)

    mnist_tutorial(nb_epochs=FLAGS.nb_epochs,
                   batch_size=FLAGS.batch_size,
                   learning_rate=FLAGS.learning_rate,
                   clean_train=FLAGS.clean_train,
                   backprop_through_attack=FLAGS.backprop_through_attack,
                   nb_filters=FLAGS.nb_filters)


if __name__ == '__main__':
    flags.DEFINE_integer('nb_filters', NB_FILTERS, 'Model size multiplier')
    flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                         'Number of epochs to train model')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches')
    flags.DEFINE_float('learning_rate', LEARNING_RATE,
                       'Learning rate for training')
    flags.DEFINE_bool('clean_train', CLEAN_TRAIN, 'Train on clean examples')
    flags.DEFINE_bool('backprop_through_attack', BACKPROP_THROUGH_ATTACK,
                      ('If True, backprop through adversarial example '
                       'construction process during adversarial training'))
    flags.DEFINE_string('train1', '', '')
    flags.DEFINE_string('train2', '', '')
    flags.DEFINE_string('test1', '', '')
    flags.DEFINE_string('test2', '', '')
    flags.DEFINE_string('adv', '', '')
    main()
# silence call must precede this imports. pylint doesn't like that
# pylint: disable=C0413
from cleverhans.compat import flags
from cleverhans.plot.success_fail import DEFAULT_FAIL_NAMES
from cleverhans.plot.success_fail import plot_report_from_path
FLAGS = flags.FLAGS


def main(argv=None):
    """Takes the path to a directory with reports and renders success fail plots."""
    report_paths = argv[1:]

    fail_names = FLAGS.fail_names.split(',')

    for report_path in report_paths:
        plot_report_from_path(report_path,
                              label=report_path,
                              fail_names=fail_names)
    pyplot.legend()

    pyplot.xlim(-.01, 1.)
    pyplot.ylim(0., 1.)

    pyplot.show()


if __name__ == '__main__':
    flags.DEFINE_string('fail_names', ','.join(DEFAULT_FAIL_NAMES),
                        'Names of adversarial datasets for failure rate')
    tf.app.run()
Example #11
0
    mnist_tutorial_cw(
        viz_enabled=FLAGS.viz_enabled,
        nb_epochs=FLAGS.nb_epochs,
        batch_size=FLAGS.batch_size,
        source_samples=FLAGS.source_samples,
        learning_rate=FLAGS.learning_rate,
        attack_iterations=FLAGS.attack_iterations,
        model_path=FLAGS.model_path,
        targeted=FLAGS.targeted,
    )


if __name__ == "__main__":
    flags.DEFINE_boolean("viz_enabled", VIZ_ENABLED, "Visualize adversarial ex.")
    flags.DEFINE_integer("nb_epochs", NB_EPOCHS, "Number of epochs to train model")
    flags.DEFINE_integer("batch_size", BATCH_SIZE, "Size of training batches")
    flags.DEFINE_integer(
        "source_samples", SOURCE_SAMPLES, "Number of test inputs to attack"
    )
    flags.DEFINE_float("learning_rate", LEARNING_RATE, "Learning rate for training")
    flags.DEFINE_string("model_path", MODEL_PATH, "Path to save or load the model file")
    flags.DEFINE_integer(
        "attack_iterations",
        ATTACK_ITERATIONS,
        "Number of iterations to run attack; 1000 is good",
    )
    flags.DEFINE_boolean("targeted", TARGETED, "Run the tutorial in targeted mode?")

    tf.app.run()
Example #12
0
          train_set.discard('white_box')
          train_set = train_set - child_set

    if not(adv_training or testing):
      continue
    for tm in train_set:
      print('running',tm) #for each threat model availible
      report=cifar10_train_on_untargeted(nb_epochs=FLAGS.nb_epochs, 
                     batch_size=FLAGS.batch_size, learning_rate=FLAGS.learning_rate, 
                     testing=testing, adv_training=adv_training,
                     model_key=FLAGS.model_key, attacker_key=key,threat_model=tm,
                     backprop_through_attack=FLAGS.backprop_through_attack)
if __name__ == '__main__':
  flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                       'Number of epochs to train model')
  flags.DEFINE_integer('batch_size', BATCH_SIZE,
                       'Size of training batches'                     'Learning rate for training')
  flags.DEFINE_bool('backprop_through_attack', BACKPROP_THROUGH_ATTACK,
                    ('If True, backprop through adversarial example '
                     'construction process during adversarial training'))
  flags.DEFINE_bool('adv_training', ADV_TRAINING,
                    'If True, train the classifier on the adversarial examples.')
  flags.DEFINE_bool('testing', TESTING,
                    'If True, test the trained classifier on the adversarial training examples.')
  flags.DEFINE_string('model_key', MODEL_KEY,
                    'model key for the model to be adversarially trained. See meta.json')
  flags.DEFINE_float('learning_rate',LEARNING_RATE,
                      'The starting learning rate for adversarial training')
  flags.DEFINE_list('attacker_keys',ATTACKER_KEYS,'list of attacker keys to train as defined in meta file')
  tf.app.run()
Example #13
0
        with open(report_path, 'w') as fp:
            deep_update(report_update, {key: report})
            json.dump(report_update, fp, indent=4, skipkeys=True)
        if FLAGS.create_reports:
            create_reports(model['folder_path'], targeted=FLAGS.targeted)


if __name__ == '__main__':
    flags.DEFINE_bool('sweep_eps', SWEEP_EPS,
                      'Flag to sweep epsilon in evaluation')
    flags.DEFINE_bool('targeted', TARGETED, 'Flag for targeted attack')
    flags.DEFINE_bool(
        'reeval', REEVAL,
        ('Flag for reevaluating all attackers'
         'regardless of whether they have been previously computed'))
    flags.DEFINE_string('dataset', DATASET,
                        'flag for dataset to eval. Options are CIFAR10')
    flags.DEFINE_bool('create_reports', CREATE_REPORTS,
                      'Flag whether to create reports')
    flags.DEFINE_list(
        'attacker_keys', ATTACKER_KEYS,
        'list of attacker keys to evaluate as defined in meta file')
    flags.DEFINE_list(
        'model_keys', MODEL_KEYS,
        'list of model keys to evaluate as defined in meta file'
        'If threat_model is "black_box" this is a list of surrogate models')
    flags.DEFINE_list(
        'eval_model_keys', EVAL_MODEL_KEYS, "if threat_model is 'black_box' "
        "evaluate adversarial examples on each compatable model in this list."
        "These are your black box models")
    flags.DEFINE_string(
        'threat_model', THREAT_MODEL,
Example #14
0
                           batch_size=FLAGS.batch_size,
                           save_advx=FLAGS.save_advx)


if __name__ == '__main__':
    flags.DEFINE_integer(
        'train_start', TRAIN_START, 'Starting point (inclusive)'
        'of range of train examples to use')
    flags.DEFINE_integer(
        'train_end', TRAIN_END, 'Ending point (non-inclusive) '
        'of range of train examples to use')
    flags.DEFINE_integer(
        'test_start', TEST_START, 'Starting point (inclusive) '
        'of range of test examples to use')
    flags.DEFINE_integer(
        'test_end', TEST_END, 'End point (non-inclusive) of '
        'range of test examples to use')
    flags.DEFINE_integer('nb_iter', NB_ITER, 'Number of iterations of PGD')
    flags.DEFINE_string('which_set', WHICH_SET, '"train" or "test"')
    flags.DEFINE_string('report_path', REPORT_PATH, 'Path to save to')
    flags.DEFINE_integer('mc_batch_size', MC_BATCH_SIZE,
                         'Batch size for MaxConfidence')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Batch size for most jobs')
    flags.DEFINE_float('base_eps_iter', BASE_EPS_ITER,
                       'epsilon per iteration, if data were in [0, 1]')
    flags.DEFINE_integer(
        'save_advx', SAVE_ADVX,
        'If True, saves the adversarial examples to the '
        'filesystem.')
    tf.app.run()
    generate_adv_images(gpu=FLAGS.gpus,
                        attack_algo=FLAGS.attack,
                        dataset=FLAGS.dataset,
                        source_data_dir=DATASET_SOURCE_PATH[FLAGS.dataset],
                        nb_epochs=FLAGS.nb_epochs,
                        batch_size=FLAGS.batch_size,
                        learning_rate=FLAGS.learning_rate,
                        testing=True,
                        args=FLAGS)


if __name__ == '__main__':
    flags.DEFINE_integer('nb_filters', NB_FILTERS, 'Model size multiplier')
    flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                         'Number of epochs to train model')
    flags.DEFINE_integer('batch_size', config.BATCH_SIZE,
                         'Size of training batches')
    flags.DEFINE_float('learning_rate', 1e-3, 'Learning rate for training')
    flags.DEFINE_string('gpus', "0", 'GPU for training')
    flags.DEFINE_enum("attack", "FGSM", META_ATTACKER_INDEX,
                      "the attack method")
    flags.DEFINE_enum("dataset", "CIFAR10", [
        "CIFAR10", "CIFAR100", "TinyImageNet", "CIFAR100_coarse_label",
        "MNIST", "FashionMNIST", "ImageNet", "SVHN", "AWA2", "CUB"
    ], "the dataset we want to generate")
    flags.DEFINE_enum("arch", "conv4", [
        "conv10", "conv4", "vgg16", "vgg16small", "resnet10", "resnet18",
        "resnet50", "resnet101"
    ], "the network be used to generate adversarial examples")
    tf.app.run()
    bim_test = np.expand_dims(bim_test, axis=3)
    bim_test_decoded = model.predict(bim_test)
    eval(bim_test)
    eval(bim_test_decoded)


def main(argv=None):
    from cleverhans_tutorials import check_installation
    check_installation(__file__)

    mnist_tutorial(nb_epochs=FLAGS.nb_epochs,
                   batch_size=FLAGS.batch_size,
                   learning_rate=FLAGS.learning_rate,
                   train_dir=FLAGS.train_dir,
                   filename=FLAGS.filename,
                   load_model=FLAGS.load_model)


if __name__ == '__main__':
    flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                         'Number of epochs to train model')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches')
    flags.DEFINE_float('learning_rate', LEARNING_RATE,
                       'Learning rate for training')
    flags.DEFINE_string('train_dir', TRAIN_DIR,
                        'Directory where to save model.')
    flags.DEFINE_string('filename', FILENAME, 'Checkpoint filename.')
    flags.DEFINE_boolean('load_model', LOAD_MODEL,
                         'Load saved model or train.')
    tf.app.run()
Example #17
0
                     filename=FLAGS.filename,
                     train_dir_ae=FLAGS.train_dir_ae,
                     train_dir_cl=FLAGS.train_dir_cl)


if __name__ == '__main__':
    flags.DEFINE_boolean('viz_enabled', VIZ_ENABLED,
                         'Visualize adversarial ex.')
    flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                         'Number of epochs to train model')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches')
    flags.DEFINE_integer('source_samples', SOURCE_SAMPLES,
                         'Number of test inputs to attack')
    flags.DEFINE_float('learning_rate', LEARNING_RATE,
                       'Learning rate for training')
    flags.DEFINE_string('model_path', MODEL_PATH,
                        'Path to save or load the model file')
    flags.DEFINE_integer('attack_iterations', ATTACK_ITERATIONS,
                         'Number of iterations to run attack; 1000 is good')
    flags.DEFINE_boolean('targeted', TARGETED,
                         'Run the tutorial in targeted mode?')
    flags.DEFINE_integer('nb_filters', NB_FILTERS, 'Model size multiplier')
    flags.DEFINE_string('train_dir_ae', TRAIN_DIR_AE,
                        'Directory where to save AE model.')
    flags.DEFINE_string('train_dir_cl', TRAIN_DIR_CL,
                        'Directory where to save Classifier model.')
    flags.DEFINE_string('filename', FILENAME,
                        'filename where to save Classifier model.')

    tf.app.run()
  check_installation(__file__)

  mnist_tutorial_fgsm(viz_enabled=FLAGS.viz_enabled,
                    nb_epochs=FLAGS.nb_epochs,
                    batch_size=FLAGS.batch_size,
                    source_samples=FLAGS.source_samples,
                    learning_rate=FLAGS.learning_rate,
                    attack_iterations=FLAGS.attack_iterations,
                    model_path=FLAGS.model_path,
                    targeted=FLAGS.targeted)


if __name__ == '__main__':
  flags.DEFINE_boolean('viz_enabled', VIZ_ENABLED,
                       'Visualize adversarial ex.')
  flags.DEFINE_integer('nb_epochs', NB_EPOCHS,
                       'Number of epochs to train model')
  flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Size of training batches')
  flags.DEFINE_integer('source_samples', SOURCE_SAMPLES,
                       'Number of test inputs to attack')
  flags.DEFINE_float('learning_rate', LEARNING_RATE,
                     'Learning rate for training')
  flags.DEFINE_string('model_path', MODEL_PATH,
                      'Path to save or load the model file')
  flags.DEFINE_integer('attack_iterations', ATTACK_ITERATIONS,
                       'Number of iterations to run attack; 1000 is good')
  flags.DEFINE_boolean('targeted', TARGETED,
                       'Run the tutorial in targeted mode?')

  tf.app.run()
        fontsize=42,
    )
    imscatter(X_embedded, x_test[:batch_size], zoom=2, cmap="Purples")
    plt.savefig(
        output_dir + "adversarial_gradients_SNNL_factor_" + str(SNNL_factor) + ".png"
    )


def main(argv=None):
    SNNL_example(
        nb_epochs=FLAGS.nb_epochs,
        batch_size=FLAGS.batch_size,
        learning_rate=FLAGS.learning_rate,
        nb_filters=FLAGS.nb_filters,
        SNNL_factor=FLAGS.SNNL_factor,
        output_dir=FLAGS.output_dir,
    )


if __name__ == "__main__":
    flags.DEFINE_integer("nb_filters", NB_FILTERS, "Model size multiplier")
    flags.DEFINE_integer("nb_epochs", NB_EPOCHS, "Number of epochs to train model")
    flags.DEFINE_integer("batch_size", BATCH_SIZE, "Size of training batches")
    flags.DEFINE_float(
        "SNNL_factor", SNNL_FACTOR, "Multiplier for Soft Nearest Neighbor Loss"
    )
    flags.DEFINE_float("learning_rate", LEARNING_RATE, "Learning rate for training")
    flags.DEFINE_string("output_dir", OUTPUT_DIR, "output directory for saving figures")

    tf.app.run()
Example #20
0
    except ValueError:
        raise ValueError(argv)
    print_accuracies(filepath=filepath,
                     test_start=FLAGS.test_start,
                     test_end=FLAGS.test_end,
                     which_set=FLAGS.which_set,
                     nb_iter=FLAGS.nb_iter,
                     base_eps_iter=FLAGS.base_eps_iter,
                     batch_size=FLAGS.batch_size)


if __name__ == '__main__':
    flags.DEFINE_integer(
        'train_start', TRAIN_START, 'Starting point (inclusive)'
        'of range of train examples to use')
    flags.DEFINE_integer(
        'train_end', TRAIN_END, 'Ending point (non-inclusive) '
        'of range of train examples to use')
    flags.DEFINE_integer(
        'test_start', TEST_START, 'Starting point (inclusive) '
        'of range of test examples to use')
    flags.DEFINE_integer(
        'test_end', TEST_END, 'End point (non-inclusive) of '
        'range of test examples to use')
    flags.DEFINE_integer('nb_iter', NB_ITER, 'Number of iterations of PGD')
    flags.DEFINE_string('which_set', WHICH_SET, '"train" or "test"')
    flags.DEFINE_integer('batch_size', BATCH_SIZE, 'Batch size for most jobs')
    flags.DEFINE_float('base_eps_iter', BASE_EPS_ITER,
                       'epsilon per iteration, if data were in [0, 1]')
    tf.compat.v1.app.run()
            sess, x, y, preds_2_adv, x_train, y_train, args=eval_params
        )
        report.train_adv_train_adv_eval = accuracy

    return report


def main(argv=None):
    from cleverhans_tutorials import check_installation

    check_installation(__file__)

    mnist_tutorial(
        nb_epochs=FLAGS.nb_epochs,
        batch_size=FLAGS.batch_size,
        learning_rate=FLAGS.learning_rate,
        train_dir=FLAGS.train_dir,
        filename=FLAGS.filename,
        load_model=FLAGS.load_model,
    )


if __name__ == "__main__":
    flags.DEFINE_integer("nb_epochs", NB_EPOCHS, "Number of epochs to train model")
    flags.DEFINE_integer("batch_size", BATCH_SIZE, "Size of training batches")
    flags.DEFINE_float("learning_rate", LEARNING_RATE, "Learning rate for training")
    flags.DEFINE_string("train_dir", TRAIN_DIR, "Directory where to save model.")
    flags.DEFINE_string("filename", FILENAME, "Checkpoint filename.")
    flags.DEFINE_boolean("load_model", LOAD_MODEL, "Load saved model or train.")
    tf.app.run()
from cleverhans.plot.success_fail import plot_report_from_path

FLAGS = flags.FLAGS


def main(argv=None):
    """Takes the path to a directory with reports and renders success fail plots."""
    report_paths = argv[1:]

    fail_names = FLAGS.fail_names.split(",")

    for report_path in report_paths:
        plot_report_from_path(report_path,
                              label=report_path,
                              fail_names=fail_names)
    pyplot.legend()

    pyplot.xlim(-0.01, 1.0)
    pyplot.ylim(0.0, 1.0)

    pyplot.show()


if __name__ == "__main__":
    flags.DEFINE_string(
        "fail_names",
        ",".join(DEFAULT_FAIL_NAMES),
        "Names of adversarial datasets for failure rate",
    )
    tf.app.run()
    )
    flags.DEFINE_integer(
        "train_end",
        TRAIN_END,
        "Ending point (non-inclusive) " "of range of train examples to use",
    )
    flags.DEFINE_integer(
        "test_start",
        TEST_START,
        "Starting point (inclusive) " "of range of test examples to use",
    )
    flags.DEFINE_integer(
        "test_end",
        TEST_END,
        "End point (non-inclusive) of " "range of test examples to use",
    )
    flags.DEFINE_integer("nb_iter", NB_ITER, "Number of iterations of PGD")
    flags.DEFINE_string("which_set", WHICH_SET, '"train" or "test"')
    flags.DEFINE_string("report_path", REPORT_PATH, "Path to save to")
    flags.DEFINE_integer("mc_batch_size", MC_BATCH_SIZE, "Batch size for MaxConfidence")
    flags.DEFINE_integer("batch_size", BATCH_SIZE, "Batch size for most jobs")
    flags.DEFINE_float(
        "base_eps_iter", BASE_EPS_ITER, "epsilon per iteration, if data were in [0, 1]"
    )
    flags.DEFINE_integer(
        "save_advx",
        SAVE_ADVX,
        "If True, saves the adversarial examples to the " "filesystem.",
    )
    tf.app.run()