diff --git a/3_NeuralNetworks/recurrent_network.ipynb b/3_NeuralNetworks/recurrent_network.ipynb index f5f44d6..539e32c 100644 --- a/3_NeuralNetworks/recurrent_network.ipynb +++ b/3_NeuralNetworks/recurrent_network.ipynb @@ -18,11 +18,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Extracting MNIST_data/train-images-idx3-ubyte.gz\n", + "Extracting MNIST_data/train-labels-idx1-ubyte.gz\n", + "Extracting MNIST_data/t10k-images-idx3-ubyte.gz\n", + "Extracting MNIST_data/t10k-labels-idx1-ubyte.gz\n" + ] + } + ], "source": [ "import tensorflow as tf\n", "from tensorflow.contrib import rnn\n", @@ -30,7 +39,14 @@ "\n", "# Import MINST data\n", "from tensorflow.examples.tutorials.mnist import input_data\n", - "mnist = input_data.read_data_sets(\"MNIST_data/\", one_hot=True)" + "mnist = input_data.read_data_sets(\"MNIST_data/\", one_hot=True)\n", + "\n", + "# for plotting graphs:\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "\n", + "# Import the os module:\n", + "import os" ] }, { @@ -49,9 +65,20 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, + "outputs": [], + "source": [ + "# Important paths:\n", + "base_models_path = \"Models\"\n", + "log_dir = os.path.join(base_models_path, \"RNN\", \"logdir\")\n", + "\n", + "model_name = \"Model1\"" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [], "source": [ "# Parameters\n", @@ -64,163 +91,232 @@ "n_input = 28 # MNIST data input (img shape: 28*28)\n", "n_steps = 28 # timesteps\n", "n_hidden = 128 # hidden layer num of features\n", - "n_classes = 10 # MNIST total classes (0-9 digits)\n", - "\n", - "# tf Graph input\n", - "x = tf.placeholder(\"float\", [None, n_steps, n_input])\n", - "y = tf.placeholder(\"float\", [None, n_classes])\n", + "n_classes = 10 # MNIST total classes (0-9 digits)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAEVCAYAAAAvoDOaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAECtJREFUeJzt3X+QVfV5x/H3R8RfBCuI4g74W0zKOFNMNmhGkmIxqTpN\n0Ta1cRpLGivpTGx1qknV6mjT1tGmMU1GxxYjEa3RZKIONmVsDNPKGI11VVREo1YhQlFUpIAoAvv0\nj3vMrLj3u+vu/bX7fF4zd/buec7Z8+yd/ew593zvvV9FBGaWz27tbsDM2sPhN0vK4TdLyuE3S8rh\nN0vK4TdLyuFPQNJ/SfrTVm9rnc3hH0EkrZJ0Urv7qEfSFyXtlLSlz212u/uy/u3e7gZs1HkwIma1\nuwkbmI/8o4CkCZJ+LOlVSW9U96fustqRkv5b0iZJiyVN7LP98ZIekLRR0uM+Wufg8I8OuwHfAw4F\nDgHeAq7dZZ0/Br4EdAE7gO8ASJoC/Dvwd8BE4ELgDkkH7LoTSYdU/yAOKfRyrKTXJD0r6TJJPrvs\nUA7/KBARr0fEHRGxNSI2A38P/OYuq90SESsi4k3gMuAMSWOALwBLImJJRPRGxL1AD3BqP/v5ZUTs\nFxG/rNPKMuAY4EDg94Ezga825Je0hnP4RwFJ+0j6F0mrJW2iFsL9qnC/66U+91cDY4FJ1M4W/qA6\nom+UtBGYRe0M4QOJiBci4sXqn8iTwNeBzw3197Lm8inZ6HAB8GHguIh4WdIM4DFAfdY5uM/9Q4Dt\nwGvU/incEhHnNKGv2KUH6yA+8o88YyXt1ee2OzCe2vP8jdWFvMv72e4LkqZL2ofaEflHEbET+Ffg\ns5J+W9KY6mfO7ueC4YAknSJpcnX/I9SeXiwe4u9pTebwjzxLqAX93dsVwD8Be1M7kv8cuKef7W4B\nbgJeBvYC/gIgIl4C5gKXAK9SOxP4Kv38bVQX/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sAzbssngusKi6v4jaH0/L1emtI0TEuoh4tLq/\nGXh3Zum2PnaFvtqiHeGfArzU5/s1dNaU3wH8RNIjkua3u5l+TK6mTQd4GZjczmb6MeDMza20y8zS\nHfPYDWXG60bzBb/3mxURHwVOAb5Snd52pKg9Z+uk4ZpBzdzcKv3MLP0r7XzshjrjdaO1I/xrgYP7\nfD+1WtYRImJt9XU9cBedN/vwK+9Oklp9Xd/mfn6lk2Zu7m9maTrgseukGa/bEf6HgWmSDpe0B/B5\n4O429PE+ksZVF2KQNA74DJ03+/DdwLzq/jxgcRt7eY9Ombm53szStPmx67gZryOi5TfgVGpX/P8H\n+Ot29FCnryOAx6vbU+3uDbiN2mngdmrXRs4G9geWAs8BPwUmdlBvtwBPAk9QC1pXm3qbRe2U/glg\neXU7td2PXaGvtjxufoWfWVK+4GeWlMNvlpTDb5aUw2+WlMNvlpTDb5aUw2+WlMNvltT/A5Dp9ON/\ngPCwAAAAAElFTkSuQmCC\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAEVCAYAAAAvoDOaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD+9JREFUeJzt3X2QVfV9x/HPB0QQxAGiIkGJSjUNtRPMbNWqTeiYWmXa\nUWPjiBPF0YZ0qmnSqK21sdr0YayTaDW1KkmoD7UaW3SkLU1imVgnDVFWowIaH0IhSkC0alUIz9/+\ncQ/OSvb+dt37uHzfr5k7e/Z8z7nnyx0+e8495577c0QIQD4jOt0AgM4g/EBShB9IivADSRF+ICnC\nDyRF+BOw/ZDt3233uuhuhH8Ysb3a9sc73Uc9ts+3vcP2230eszrdF/q3V6cbwB5naUSc2OkmMDD2\n/HsA2xNt/5vtV2y/Xk0fvNti020/avtN2w/YntRn/eNsf9/2G7afZG+dA+HfM4yQ9A+SPiBpmqSf\nSfq73ZY5T9IFkqZI2i7pRkmyPV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QFOEHkiL8QFKEH0jKEdG+jdmvSFrTZ9b+kl5tWwPvTbf21q19SfQ2VM3s7QMR\nccBgFmxr+H9u43ZvRPR0rIGCbu2tW/uS6G2oOtUbh/1AUoQfSKrT4Z/f4e2XdGtv3dqXRG9D1ZHe\nOvqeH0DndHrPD6BDOhJ+26fYftb2C7Yv70QP9dhebXt5NfJwb4d7WWB7g+0VfeZNsv2g7eern/0O\nk9ah3rpi5ObCyNIdfe26bcTrth/22x4p6TlJvyHpJUnLJM2JiKfb2kgdtldL6omIjl8Ttv1RSW9L\nuiMijqrmXSvptYi4pvrDOTEi/rhLerta0tudHrm5GlBmSt+RpSWdLul8dfC1K/R1ljrwunViz3+M\npBciYlVEbJV0j6TTOtBH14uIhyW9ttvs0yTdXk3frtp/nrar01tXiIh1EfF4Nf2WpF0jS3f0tSv0\n1RGdCP9USS/2+f0lddeQ3yHpO7Yfsz2v0830Y3I1bLokrZc0uZPN9GPAkZvbabeRpbvmtRvKiNfN\nxgm/n3diRHxE0qmSLqoOb7tS1N6zddPlmkGN3Nwu/Yws/Y5OvnZDHfG62ToR/rWSDunz+8HVvK4Q\nEWurnxsk3a/uG3345V2DpFY/N3S4n3d008jN/Y0srS547bppxOtOhH+ZpCNsH2Z7b0lnS1rUgT5+\nju1x1YkY2R4n6WR13+jDiyTNrabnSnqgg728S7eM3FxvZGl1+LXruhGvI6LtD0mzVTvj/2NJf9qJ\nHur0dbikJ6vHyk73Julu1Q4Dt6l2buRCSe+TtETS85L+U9KkLurtTknLJT2lWtCmdKi3E1U7pH9K\n0hPVY3anX7tCXx153fiEH5AUJ/yApAg/kBThB5Ii/EBShB9IivADSRF+ICnCDyT1/+/s0eZvDtgt\nAAAAAElFTkSuQmCC\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAEVCAYAAAAvoDOaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALE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4t1q1pbe2vuc3s/Zp95bfzNqkLeGXdLykRyWtkPTVdvRQRtJKSQ9KWiKpt829zJW0\nTtKyAdPGS7pV0uPF90GHSWtTb+dLWl28dkskndim3iZLuk3Sw5IekvSlYnpbX7tEX2153Vq+2y9p\nBPAY8D5gFbAYOCUiHm5pIyUkrQR6IqLt54QlvQd4EbgyIt5eTPsnYENEXFj84xwXEX/XIb2dD7zY\n7pGbiwFlJg4cWRr4EHA6bXztEn2dTBtet3Zs+acDKyLiiYh4Ffg5MLMNfXS8iLgd2LDD5JnAvOLx\nPCp/PC1X0ltHiIg1EXF/8fgFYPvI0m197RJ9tUU7wj8JeGrAz6vorCG/A7hF0n2SZre7mUFMKIZN\nB3gamNDOZgZRdeTmVtphZOmOee1qGfG60XzA708dHRGHAScAXyh2bztSVN6zddLpmiGN3Nwqg4ws\n/UftfO1qHfG60doR/tXA5AE/71tM6wgRsbr4vg64ns4bfXjt9kFSi+/r2tzPH3XSyM2DjSxNB7x2\nnTTidTvCvxiYIukASbsDHwduaEMff0LS6OJADJJGA8fReaMP3wDMKh7PAua3sZfX6JSRm8tGlqbN\nr13HjXgdES3/Ak6kcsT/D8DX2tFDSV9/DjxQfD3U7t6An1HZDeyjcmzk08AbgIXA48DvgPEd1NtV\nwIPAUipBm9im3o6msku/FFhSfJ3Y7tcu0VdbXjdf4WeWKR/wM8uUw2+WKYffLFMOv1mmHH6zTDn8\nZply+M0y5fCbZer/ASucPrmrSFxRAAAAAElFTkSuQmCC\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# view a few random images from the dataset\n", + "images = mnist.train.images.reshape(-1, n_input, n_steps)\n", + "labels = mnist.train.labels\n", "\n", - "# Define weights\n", - "weights = {\n", - " 'out': tf.Variable(tf.random_normal([n_hidden, n_classes]))\n", - "}\n", - "biases = {\n", - " 'out': tf.Variable(tf.random_normal([n_classes]))\n", - "}" + "# we display 3 random images from this sample\n", + "for _ in range(3):\n", + " random_index = np.random.randint(images.shape[0])\n", + " random_image = images[random_index]; label = np.where(labels[random_index] == 1)[0][0]\n", + " \n", + " # plot the image:\n", + " plt.figure().suptitle(\"Label: \" + str(label))\n", + " plt.imshow(random_image)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run the above cell a few times to see different results." ] }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, + "execution_count": 7, + "metadata": {}, "outputs": [], "source": [ - "def RNN(x, weights, biases):\n", + "RNN_GRAPH = tf.Graph()\n", "\n", - " # Prepare data shape to match `rnn` function requirements\n", - " # Current data input shape: (batch_size, n_steps, n_input)\n", - " # Required shape: 'n_steps' tensors list of shape (batch_size, n_input)\n", + "with RNN_GRAPH.as_default():\n", " \n", - " # Permuting batch_size and n_steps\n", - " x = tf.transpose(x, [1, 0, 2])\n", - " # Reshaping to (n_steps*batch_size, n_input)\n", - " x = tf.reshape(x, [-1, n_input])\n", - " # Split to get a list of 'n_steps' tensors of shape (batch_size, n_input)\n", - " x = tf.split(x, n_steps, 0)\n", + " # tf Graph input\n", + " x = tf.placeholder(\"float\", [None, n_steps, n_input], name=\"Input_data\")\n", + " y = tf.placeholder(\"float\", [None, n_classes], name=\"Input_labels\")\n", + "\n", + " # Define weights\n", + " weights = {\n", + " 'out': tf.Variable(tf.random_normal([n_hidden, n_classes]))\n", + " }\n", + " biases = {\n", + " 'out': tf.Variable(tf.random_normal([n_classes]))\n", + " }\n", + " \n", + " def RNN(x, weights, biases):\n", + "\n", + " # Prepare data shape to match `rnn` function requirements\n", + " # Current data input shape: (batch_size, n_steps, n_input)\n", + " # Required shape: 'n_steps' tensors list of shape (batch_size, n_input)\n", + "\n", + " # Permuting batch_size and n_steps\n", + " x = tf.transpose(x, [1, 0, 2])\n", + " # Reshaping to (n_steps*batch_size, n_input)\n", + " x = tf.reshape(x, [-1, n_input])\n", + " # Split to get a list of 'n_steps' tensors of shape (batch_size, n_input)\n", + " x = tf.split(x, n_steps, 0)\n", "\n", - " # Define a lstm cell with tensorflow\n", - " lstm_cell = rnn.BasicLSTMCell(n_hidden, forget_bias=1.0)\n", + " # Define a lstm cell with tensorflow\n", + " lstm_cell = rnn.BasicLSTMCell(n_hidden, forget_bias=1.0)\n", "\n", - " # Get lstm cell output\n", - " outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)\n", + " # Get lstm cell output\n", + " outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)\n", "\n", - " # Linear activation, using rnn inner loop last output\n", - " return tf.matmul(outputs[-1], weights['out']) + biases['out']\n", + " # Linear activation, using rnn inner loop last output\n", + " return tf.matmul(outputs[-1], weights['out']) + biases['out']\n", "\n", - "pred = RNN(x, weights, biases)\n", + " pred = RNN(x, weights, biases)\n", "\n", - "# Define loss and optimizer\n", - "cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))\n", - "optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)\n", + " # Define loss and optimizer\n", + " cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))\n", "\n", - "# Evaluate model\n", - "correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))\n", - "accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))\n", + " # summary for visualizing the cost \n", + " cost_summary = tf.summary.scalar(\"Loss\", cost)\n", "\n", - "# Initializing the variables\n", - "init = tf.global_variables_initializer()" + " optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)\n", + "\n", + " # Evaluate model\n", + " correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))\n", + " accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))\n", + "\n", + " # summary for accuracy\n", + " accuracy_summary = tf.summary.scalar(\"Accuracy\", accuracy)\n", + "\n", + " # merged summary:\n", + " all_summaries = tf.summary.merge_all()" ] }, { "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, + "execution_count": 10, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Iter 1280, Minibatch Loss= 1.576423, Training Accuracy= 0.51562\n", - "Iter 2560, Minibatch Loss= 1.450179, Training Accuracy= 0.53906\n", - "Iter 3840, Minibatch Loss= 1.160066, Training Accuracy= 0.64844\n", - "Iter 5120, Minibatch Loss= 0.898589, Training Accuracy= 0.73438\n", - "Iter 6400, Minibatch Loss= 0.685712, Training Accuracy= 0.75781\n", - "Iter 7680, Minibatch Loss= 1.085666, Training Accuracy= 0.64844\n", - "Iter 8960, Minibatch Loss= 0.681488, Training Accuracy= 0.73438\n", - "Iter 10240, Minibatch Loss= 0.557049, Training Accuracy= 0.82812\n", - "Iter 11520, Minibatch Loss= 0.340857, Training Accuracy= 0.92188\n", - "Iter 12800, Minibatch Loss= 0.596482, Training Accuracy= 0.78906\n", - "Iter 14080, Minibatch Loss= 0.486564, Training Accuracy= 0.84375\n", - "Iter 15360, Minibatch Loss= 0.302493, Training Accuracy= 0.90625\n", - "Iter 16640, Minibatch Loss= 0.334277, Training Accuracy= 0.92188\n", - "Iter 17920, Minibatch Loss= 0.222026, Training Accuracy= 0.90625\n", - "Iter 19200, Minibatch Loss= 0.228581, Training Accuracy= 0.92188\n", - "Iter 20480, Minibatch Loss= 0.150356, Training Accuracy= 0.96094\n", - "Iter 21760, Minibatch Loss= 0.415417, Training Accuracy= 0.86719\n", - "Iter 23040, Minibatch Loss= 0.159742, Training Accuracy= 0.94531\n", - "Iter 24320, Minibatch Loss= 0.333764, Training Accuracy= 0.89844\n", - "Iter 25600, Minibatch Loss= 0.379070, Training Accuracy= 0.88281\n", - "Iter 26880, Minibatch Loss= 0.241612, Training Accuracy= 0.91406\n", - "Iter 28160, Minibatch Loss= 0.200397, Training Accuracy= 0.93750\n", - "Iter 29440, Minibatch Loss= 0.197994, Training Accuracy= 0.93750\n", - "Iter 30720, Minibatch Loss= 0.330214, Training Accuracy= 0.89062\n", - "Iter 32000, Minibatch Loss= 0.174626, Training Accuracy= 0.92969\n", - "Iter 33280, Minibatch Loss= 0.202369, Training Accuracy= 0.93750\n", - "Iter 34560, Minibatch Loss= 0.240835, Training Accuracy= 0.94531\n", - "Iter 35840, Minibatch Loss= 0.207867, Training Accuracy= 0.93750\n", - "Iter 37120, Minibatch Loss= 0.313306, Training Accuracy= 0.90625\n", - "Iter 38400, Minibatch Loss= 0.089850, Training Accuracy= 0.96875\n", - "Iter 39680, Minibatch Loss= 0.184803, Training Accuracy= 0.92188\n", - "Iter 40960, Minibatch Loss= 0.236523, Training Accuracy= 0.92969\n", - "Iter 42240, Minibatch Loss= 0.174834, Training Accuracy= 0.94531\n", - "Iter 43520, Minibatch Loss= 0.127905, Training Accuracy= 0.93750\n", - "Iter 44800, Minibatch Loss= 0.120045, Training Accuracy= 0.96875\n", - "Iter 46080, Minibatch Loss= 0.068337, Training Accuracy= 0.98438\n", - "Iter 47360, Minibatch Loss= 0.141118, Training Accuracy= 0.95312\n", - "Iter 48640, Minibatch Loss= 0.182404, Training Accuracy= 0.92188\n", - "Iter 49920, Minibatch Loss= 0.176778, Training Accuracy= 0.93750\n", - "Iter 51200, Minibatch Loss= 0.098927, Training Accuracy= 0.97656\n", - "Iter 52480, Minibatch Loss= 0.158776, Training Accuracy= 0.96094\n", - "Iter 53760, Minibatch Loss= 0.031863, Training Accuracy= 0.99219\n", - "Iter 55040, Minibatch Loss= 0.101799, Training Accuracy= 0.96094\n", - "Iter 56320, Minibatch Loss= 0.176387, Training Accuracy= 0.96094\n", - "Iter 57600, Minibatch Loss= 0.096277, Training Accuracy= 0.96875\n", - "Iter 58880, Minibatch Loss= 0.137416, Training Accuracy= 0.94531\n", - "Iter 60160, Minibatch Loss= 0.062801, Training Accuracy= 0.97656\n", - "Iter 61440, Minibatch Loss= 0.036346, Training Accuracy= 0.98438\n", - "Iter 62720, Minibatch Loss= 0.153030, Training Accuracy= 0.92969\n", - "Iter 64000, Minibatch Loss= 0.117716, Training Accuracy= 0.95312\n", - "Iter 65280, Minibatch Loss= 0.048387, Training Accuracy= 0.99219\n", - "Iter 66560, Minibatch Loss= 0.070802, Training Accuracy= 0.97656\n", - "Iter 67840, Minibatch Loss= 0.221085, Training Accuracy= 0.96875\n", - "Iter 69120, Minibatch Loss= 0.184049, Training Accuracy= 0.93750\n", - "Iter 70400, Minibatch Loss= 0.094883, Training Accuracy= 0.95312\n", - "Iter 71680, Minibatch Loss= 0.087278, Training Accuracy= 0.96875\n", - "Iter 72960, Minibatch Loss= 0.153267, Training Accuracy= 0.95312\n", - "Iter 74240, Minibatch Loss= 0.161794, Training Accuracy= 0.94531\n", - "Iter 75520, Minibatch Loss= 0.103779, Training Accuracy= 0.96875\n", - "Iter 76800, Minibatch Loss= 0.165586, Training Accuracy= 0.96094\n", - "Iter 78080, Minibatch Loss= 0.137721, Training Accuracy= 0.95312\n", - "Iter 79360, Minibatch Loss= 0.124014, Training Accuracy= 0.96094\n", - "Iter 80640, Minibatch Loss= 0.051460, Training Accuracy= 0.99219\n", - "Iter 81920, Minibatch Loss= 0.185836, Training Accuracy= 0.96094\n", - "Iter 83200, Minibatch Loss= 0.147694, Training Accuracy= 0.94531\n", - "Iter 84480, Minibatch Loss= 0.061550, Training Accuracy= 0.98438\n", - "Iter 85760, Minibatch Loss= 0.093457, Training Accuracy= 0.96875\n", - "Iter 87040, Minibatch Loss= 0.094497, Training Accuracy= 0.98438\n", - "Iter 88320, Minibatch Loss= 0.093934, Training Accuracy= 0.96094\n", - "Iter 89600, Minibatch Loss= 0.061550, Training Accuracy= 0.96875\n", - "Iter 90880, Minibatch Loss= 0.082452, Training Accuracy= 0.97656\n", - "Iter 92160, Minibatch Loss= 0.087423, Training Accuracy= 0.97656\n", - "Iter 93440, Minibatch Loss= 0.032694, Training Accuracy= 0.99219\n", - "Iter 94720, Minibatch Loss= 0.069597, Training Accuracy= 0.97656\n", - "Iter 96000, Minibatch Loss= 0.193636, Training Accuracy= 0.96094\n", - "Iter 97280, Minibatch Loss= 0.134405, Training Accuracy= 0.96094\n", - "Iter 98560, Minibatch Loss= 0.072992, Training Accuracy= 0.96875\n", - "Iter 99840, Minibatch Loss= 0.041049, Training Accuracy= 0.99219\n", + "Iter 1280, Minibatch Loss= 1.869755, Training Accuracy= 0.38281\n", + "Iter 2560, Minibatch Loss= 1.398164, Training Accuracy= 0.52344\n", + "Iter 3840, Minibatch Loss= 1.290797, Training Accuracy= 0.59375\n", + "Iter 5120, Minibatch Loss= 0.938388, Training Accuracy= 0.65625\n", + "Iter 6400, Minibatch Loss= 1.046592, Training Accuracy= 0.71094\n", + "Iter 7680, Minibatch Loss= 0.808783, Training Accuracy= 0.75000\n", + "Iter 8960, Minibatch Loss= 0.654342, Training Accuracy= 0.78906\n", + "Iter 10240, Minibatch Loss= 0.519232, Training Accuracy= 0.82031\n", + "Iter 11520, Minibatch Loss= 0.412831, Training Accuracy= 0.85156\n", + "Iter 12800, Minibatch Loss= 0.354895, Training Accuracy= 0.89062\n", + "Iter 14080, Minibatch Loss= 0.278876, Training Accuracy= 0.89844\n", + "Iter 15360, Minibatch Loss= 0.473290, Training Accuracy= 0.83594\n", + "Iter 16640, Minibatch Loss= 0.364607, Training Accuracy= 0.87500\n", + "Iter 17920, Minibatch Loss= 0.452570, Training Accuracy= 0.88281\n", + "Iter 19200, Minibatch Loss= 0.187583, Training Accuracy= 0.96094\n", + "Iter 20480, Minibatch Loss= 0.231178, Training Accuracy= 0.93750\n", + "Iter 21760, Minibatch Loss= 0.293958, Training Accuracy= 0.92188\n", + "Iter 23040, Minibatch Loss= 0.201631, Training Accuracy= 0.91406\n", + "Iter 24320, Minibatch Loss= 0.389085, Training Accuracy= 0.90625\n", + "Iter 25600, Minibatch Loss= 0.196597, Training Accuracy= 0.92188\n", + "Iter 26880, Minibatch Loss= 0.313393, Training Accuracy= 0.92188\n", + "Iter 28160, Minibatch Loss= 0.278469, Training Accuracy= 0.92969\n", + "Iter 29440, Minibatch Loss= 0.156926, Training Accuracy= 0.95312\n", + "Iter 30720, Minibatch Loss= 0.153846, Training Accuracy= 0.97656\n", + "Iter 32000, Minibatch Loss= 0.240066, Training Accuracy= 0.92188\n", + "Iter 33280, Minibatch Loss= 0.083468, Training Accuracy= 0.98438\n", + "Iter 34560, Minibatch Loss= 0.447905, Training Accuracy= 0.90625\n", + "Iter 35840, Minibatch Loss= 0.173490, Training Accuracy= 0.96094\n", + "Iter 37120, Minibatch Loss= 0.193683, Training Accuracy= 0.95312\n", + "Iter 38400, Minibatch Loss= 0.196895, Training Accuracy= 0.96094\n", + "Iter 39680, Minibatch Loss= 0.128602, Training Accuracy= 0.96875\n", + "Iter 40960, Minibatch Loss= 0.059578, Training Accuracy= 0.98438\n", + "Iter 42240, Minibatch Loss= 0.146358, Training Accuracy= 0.94531\n", + "Iter 43520, Minibatch Loss= 0.208118, Training Accuracy= 0.92188\n", + "Iter 44800, Minibatch Loss= 0.186589, Training Accuracy= 0.94531\n", + "Iter 46080, Minibatch Loss= 0.142762, Training Accuracy= 0.95312\n", + "Iter 47360, Minibatch Loss= 0.162604, Training Accuracy= 0.96875\n", + "Iter 48640, Minibatch Loss= 0.104353, Training Accuracy= 0.96094\n", + "Iter 49920, Minibatch Loss= 0.172098, Training Accuracy= 0.94531\n", + "Iter 51200, Minibatch Loss= 0.115274, Training Accuracy= 0.96094\n", + "Iter 52480, Minibatch Loss= 0.116284, Training Accuracy= 0.95312\n", + "Iter 53760, Minibatch Loss= 0.107263, Training Accuracy= 0.96875\n", + "Iter 55040, Minibatch Loss= 0.109971, Training Accuracy= 0.95312\n", + "Iter 56320, Minibatch Loss= 0.126310, Training Accuracy= 0.94531\n", + "Iter 57600, Minibatch Loss= 0.156627, Training Accuracy= 0.93750\n", + "Iter 58880, Minibatch Loss= 0.133786, Training Accuracy= 0.95312\n", + "Iter 60160, Minibatch Loss= 0.136292, Training Accuracy= 0.93750\n", + "Iter 61440, Minibatch Loss= 0.114681, Training Accuracy= 0.95312\n", + "Iter 62720, Minibatch Loss= 0.195986, Training Accuracy= 0.96094\n", + "Iter 64000, Minibatch Loss= 0.095622, Training Accuracy= 0.96094\n", + "Iter 65280, Minibatch Loss= 0.254895, Training Accuracy= 0.92188\n", + "Iter 66560, Minibatch Loss= 0.191213, Training Accuracy= 0.93750\n", + "Iter 67840, Minibatch Loss= 0.079783, Training Accuracy= 0.97656\n", + "Iter 69120, Minibatch Loss= 0.088695, Training Accuracy= 0.96875\n", + "Iter 70400, Minibatch Loss= 0.151131, Training Accuracy= 0.92188\n", + "Iter 71680, Minibatch Loss= 0.107769, Training Accuracy= 0.96875\n", + "Iter 72960, Minibatch Loss= 0.073408, Training Accuracy= 0.96094\n", + "Iter 74240, Minibatch Loss= 0.073091, Training Accuracy= 0.99219\n", + "Iter 75520, Minibatch Loss= 0.175502, Training Accuracy= 0.96094\n", + "Iter 76800, Minibatch Loss= 0.079902, Training Accuracy= 0.96875\n", + "Iter 78080, Minibatch Loss= 0.090703, Training Accuracy= 0.96875\n", + "Iter 79360, Minibatch Loss= 0.053114, Training Accuracy= 0.97656\n", + "Iter 80640, Minibatch Loss= 0.072113, Training Accuracy= 0.99219\n", + "Iter 81920, Minibatch Loss= 0.075527, Training Accuracy= 0.96875\n", + "Iter 83200, Minibatch Loss= 0.094112, Training Accuracy= 0.97656\n", + "Iter 84480, Minibatch Loss= 0.053958, Training Accuracy= 0.97656\n", + "Iter 85760, Minibatch Loss= 0.117017, Training Accuracy= 0.96094\n", + "Iter 87040, Minibatch Loss= 0.061720, Training Accuracy= 0.98438\n", + "Iter 88320, Minibatch Loss= 0.180723, Training Accuracy= 0.92969\n", + "Iter 89600, Minibatch Loss= 0.122451, Training Accuracy= 0.95312\n", + "Iter 90880, Minibatch Loss= 0.093231, Training Accuracy= 0.97656\n", + "Iter 92160, Minibatch Loss= 0.092867, Training Accuracy= 0.97656\n", + "Iter 93440, Minibatch Loss= 0.092796, Training Accuracy= 0.96875\n", + "Iter 94720, Minibatch Loss= 0.094593, Training Accuracy= 0.97656\n", + "Iter 96000, Minibatch Loss= 0.035997, Training Accuracy= 0.99219\n", + "Iter 97280, Minibatch Loss= 0.070153, Training Accuracy= 0.99219\n", + "Iter 98560, Minibatch Loss= 0.091219, Training Accuracy= 0.96875\n", + "Iter 99840, Minibatch Loss= 0.113301, Training Accuracy= 0.96094\n", "Optimization Finished!\n", - "Testing Accuracy: 0.960938\n" + "Testing Accuracy: 0.984375\n" ] } ], "source": [ "# Launch the graph\n", - "with tf.Session() as sess:\n", - " sess.run(init)\n", + "with tf.Session(graph=RNN_GRAPH) as sess:\n", + " # create the writer object for this session\n", + " log_path = os.path.join(log_dir, model_name)\n", + " tensorboard_writer = tf.summary.FileWriter(log_path, graph=sess.graph)\n", + " \n", + " sess.run(tf.global_variables_initializer())\n", " step = 1\n", " # Keep training until reach max iterations\n", " while step * batch_size < training_iters:\n", @@ -231,9 +327,11 @@ " sess.run(optimizer, feed_dict={x: batch_x, y: batch_y})\n", " if step % display_step == 0:\n", " # Calculate batch accuracy\n", - " acc = sess.run(accuracy, feed_dict={x: batch_x, y: batch_y})\n", - " # Calculate batch loss\n", - " loss = sess.run(cost, feed_dict={x: batch_x, y: batch_y})\n", + " acc, loss, summ = sess.run([accuracy, cost, all_summaries], feed_dict={x: batch_x, y: batch_y})\n", + " \n", + " # record the summaries:\n", + " tensorboard_writer.add_summary(summ, step)\n", + " \n", " print \"Iter \" + str(step*batch_size) + \", Minibatch Loss= \" + \\\n", " \"{:.6f}\".format(loss) + \", Training Accuracy= \" + \\\n", " \"{:.5f}\".format(acc)\n", @@ -249,13 +347,14 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# To visualize the Above RNN in tensorboard, run the following command:\n", + "-------------------------------------------------------------------------------------------------------------------\n", + "\n", + "## $: tensorboard --logdir=[path to the logdir]" + ] } ], "metadata": { @@ -278,5 +377,5 @@ } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 }