- What if I do argmax(r) = ||r||2 s.t. f(x+r)f(x) >= 0
Last active
August 31, 2016 03:47
-
-
Save act65/a034327ed0fce17abff315c0c2ed0e3b to your computer and use it in GitHub Desktop.
Adversarial examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"ename": "ImportError", | |
"evalue": "No module named 'tflearn'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-2-358489b846ed>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mtflearn\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtflearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0minput_data\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdropout\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfully_connected\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtflearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconv\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mconv_2d\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmax_pool_2d\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtflearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnormalization\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mlocal_response_normalization\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtflearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mestimator\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mregression\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;31mImportError\u001b[0m: No module named 'tflearn'" | |
] | |
} | |
], | |
"source": [ | |
"import tflearn\n", | |
"from tflearn.layers.core import input_data, dropout, fully_connected\n", | |
"from tflearn.layers.conv import conv_2d, max_pool_2d\n", | |
"from tflearn.layers.normalization import local_response_normalization\n", | |
"from tflearn.layers.estimator import regression\n", | |
"\n", | |
"# Data loading and preprocessing\n", | |
"import tflearn.datasets.mnist as mnist\n", | |
"X, Y, testX, testY = mnist.load_data(one_hot=True)\n", | |
"X = X.reshape([-1, 28, 28, 1])\n", | |
"testX = testX.reshape([-1, 28, 28, 1])\n", | |
"\n", | |
"# Building convolutional network\n", | |
"network = input_data(shape=[None, 28, 28, 1], name='input')\n", | |
"network = conv_2d(network, 32, 3, activation='relu', regularizer=\"L2\")\n", | |
"network = max_pool_2d(network, 2)\n", | |
"network = local_response_normalization(network)\n", | |
"network = conv_2d(network, 64, 3, activation='relu', regularizer=\"L2\")\n", | |
"network = max_pool_2d(network, 2)\n", | |
"network = local_response_normalization(network)\n", | |
"network = fully_connected(network, 128, activation='tanh')\n", | |
"network = dropout(network, 0.8)\n", | |
"network = fully_connected(network, 256, activation='tanh')\n", | |
"network = dropout(network, 0.8)\n", | |
"network = fully_connected(network, 10, activation='softmax')\n", | |
"network = regression(network, optimizer='adam', learning_rate=0.01,\n", | |
" loss='categorical_crossentropy', name='target')\n", | |
"\n", | |
"# Training\n", | |
"model = tflearn.DNN(network, tensorboard_verbose=0)\n", | |
"model.fit({'input': X}, {'target': Y}, n_epoch=20,\n", | |
" validation_set=({'input': testX}, {'target': testY}),\n", | |
" snapshot_step=100, show_metric=True, run_id='convnet_mnist')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment