def run_jsma(weight_fpath): 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, 'Nb of test inputs to attack') flags.DEFINE_float('learning_rate', LEARNING_RATE, 'Learning rate for training') mnist_tutorial_jsma(weight_fpath, 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)
import matplotlib.pyplot as plt plt.close(figure) _ = grid_visual(grid_viz_data) return report def main(argv=None): from cleverhans_tutorials import check_installation check_installation(__file__) mnist_tutorial_jsma(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) 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, 'Nb of test inputs to attack') flags.DEFINE_float('learning_rate', LEARNING_RATE, 'Learning rate for training') tf.app.run()
def main(argv=None): from cleverhans_tutorials import check_installation 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()
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()
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()
check_installation(__file__) 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()
f = {x: flags.FLAGS[x].value for x in dir(flags.FLAGS)} HParams = namedtuple('HParams', f.keys()) hparams = HParams(**f) 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.')
return report def main(argv=None): from cleverhans_tutorials import check_installation check_installation(__file__) mnist_tutorial_jsma( 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, ) 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, "Nb of test inputs to attack") flags.DEFINE_float("learning_rate", LEARNING_RATE, "Learning rate for training") tf.app.run()