コード例 #1
0
    from cleverhans_tutorials import check_installation

    check_installation(__file__)

    cifar10_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"),
    )

    tf.app.run()
コード例 #2
0
  return report


def main(argv=None):
  """
  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'))

  tf.app.run()
コード例 #3
0
        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()
コード例 #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()
コード例 #5
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()
コード例 #6
0
                                      sweep_eps=FLAGS.sweep_eps,
                                      model_key=key,
                                      eval_model_keys=eval_model_keys,
                                      attacker_keys=attacker_keys,
                                      threat_model=FLAGS.threat_model,
                                      generate_examples=True)

        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'