Skip to content

Instantly share code, notes, and snippets.

@ypwhs
Created September 23, 2016 17:34
Show Gist options
  • Save ypwhs/64b3c8c80157d502987bc59d5e6a1ac3 to your computer and use it in GitHub Desktop.
Save ypwhs/64b3c8c80157d502987bc59d5e6a1ac3 to your computer and use it in GitHub Desktop.
tflearn vs tensorflow
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Extracting mnist/train-images-idx3-ubyte.gz\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gzip.py:275: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
" chunk = self.extrabuf[offset: offset + size]\n",
"/usr/local/lib/python2.7/site-packages/tflearn/datasets/mnist.py:52: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
" data = data.reshape(num_images, rows, cols, 1)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Extracting mnist/train-labels-idx1-ubyte.gz\n",
"Extracting mnist/t10k-images-idx3-ubyte.gz\n",
"Extracting mnist/t10k-labels-idx1-ubyte.gz\n"
]
}
],
"source": [
"import tflearn\n",
"import tflearn.datasets.mnist as mnist\n",
"X, Y, testX, testY = mnist.load_data(one_hot=True)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training Step: 6880 | total loss: \u001b[1m\u001b[32m0.29894\u001b[0m\u001b[0m\n",
"| RMSProp | epoch: 016 | loss: 0.29894 - acc: 0.9752 | val_loss: 0.06902 - val_acc: 0.9801 -- iter: 55000/55000\n",
"Training Step: 6880 | total loss: \u001b[1m\u001b[32m0.29894\u001b[0m\u001b[0m\n",
"| RMSProp | epoch: 016 | loss: 0.29894 - acc: 0.9752 | val_loss: 0.06902 - val_acc: 0.9801 -- iter: 55000/55000\n",
"--\n"
]
}
],
"source": [
"input_layer = tflearn.input_data(shape=[None, 784])\n",
"dense1 = tflearn.fully_connected(input_layer, 512, activation='tanh')\n",
"dropout1 = tflearn.dropout(dense1, 0.8)\n",
"dense2 = tflearn.fully_connected(dropout1, 512, activation='tanh')\n",
"dropout2 = tflearn.dropout(dense2, 0.8)\n",
"softmax = tflearn.fully_connected(dropout2, 10, activation='softmax')\n",
"\n",
"net = tflearn.regression(softmax, optimizer=tflearn.RMSProp(), loss='categorical_crossentropy')\n",
"\n",
"# Training\n",
"model = tflearn.DNN(net, tensorboard_verbose=0)\n",
"model.fit(X, Y, n_epoch=16, batch_size=128, validation_set=(testX, testY), \n",
" show_metric=True, shuffle=True, run_id=\"dense_model\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment