浏览代码

improve notebook display

aymericdamien 9 年之前
父节点
当前提交
69f2dc8cc5

+ 1 - 1
examples/3 - Neural Networks/convolutional_network.py

@@ -1,5 +1,5 @@
 '''
-A Multilayer Perceptron implementation example using TensorFlow library.
+A Convolutional Network implementation example using TensorFlow library.
 This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/)
 
 Author: Aymeric Damien

+ 4 - 5
notebooks/1 - Introduction/basic_operations.ipynb

@@ -8,9 +8,9 @@
    },
    "outputs": [],
    "source": [
-    "#Basic Operations example using TensorFlow library.\n",
-    "#Author: Aymeric Damien\n",
-    "#Project: https://github.com/aymericdamien/TensorFlow-Examples/"
+    "# Basic Operations example using TensorFlow library.\n",
+    "# Author: Aymeric Damien\n",
+    "# Project: https://github.com/aymericdamien/TensorFlow-Examples/"
    ]
   },
   {
@@ -192,8 +192,7 @@
     "# The output of the op is returned in 'result' as a numpy `ndarray` object.\n",
     "with tf.Session() as sess:\n",
     "    result = sess.run(product)\n",
-    "    print result\n",
-    "    # ==> [[ 12.]]"
+    "    print result"
    ]
   }
  ],

+ 1 - 1
notebooks/1 - Introduction/helloworld.ipynb

@@ -19,7 +19,7 @@
    },
    "outputs": [],
    "source": [
-    "#Simple hello world using TensorFlow\n",
+    "# Simple hello world using TensorFlow\n",
     "\n",
     "# Create a Constant op\n",
     "# The op is added as a node to the default graph.\n",

+ 7 - 5
notebooks/2 - Basic Classifiers/linear_regression.ipynb

@@ -123,7 +123,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 22,
    "metadata": {
     "collapsed": false
    },
@@ -189,11 +189,13 @@
     "\n",
     "        #Display logs per epoch step\n",
     "        if epoch % display_step == 0:\n",
-    "            print \"Epoch:\", '%04d' % (epoch+1), \"cost=\", \"{:.9f}\".format(sess.run(cost, feed_dict={X: train_X, Y:train_Y})), \\\n",
+    "            print \"Epoch:\", '%04d' % (epoch+1), \"cost=\", \\\n",
+    "                \"{:.9f}\".format(sess.run(cost, feed_dict={X: train_X, Y:train_Y})), \\\n",
     "                \"W=\", sess.run(W), \"b=\", sess.run(b)\n",
     "\n",
     "    print \"Optimization Finished!\"\n",
-    "    print \"cost=\", sess.run(cost, feed_dict={X: train_X, Y: train_Y}), \"W=\", sess.run(W), \"b=\", sess.run(b)\n",
+    "    print \"cost=\", sess.run(cost, feed_dict={X: train_X, Y: train_Y}), \\\n",
+    "          \"W=\", sess.run(W), \"b=\", sess.run(b)\n",
     "\n",
     "    #Graphic display\n",
     "    plt.plot(train_X, train_Y, 'ro', label='Original data')\n",
@@ -204,7 +206,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 18,
+   "execution_count": 23,
    "metadata": {
     "collapsed": false
    },
@@ -216,7 +218,7 @@
        "<IPython.core.display.Image object>"
       ]
      },
-     "execution_count": 18,
+     "execution_count": 23,
      "metadata": {},
      "output_type": "execute_result"
     }

+ 6 - 3
notebooks/2 - Basic Classifiers/logistic_regression.ipynb

@@ -9,7 +9,8 @@
    "outputs": [],
    "source": [
     "# A logistic regression learning algorithm example using TensorFlow library.\n",
-    "# This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/)\n",
+    "# This example is using the MNIST database of handwritten digits \n",
+    "# (http://yann.lecun.com/exdb/mnist/)\n",
     "\n",
     "# Author: Aymeric Damien\n",
     "# Project: https://github.com/aymericdamien/TensorFlow-Examples/"
@@ -114,8 +115,10 @@
    "outputs": [],
    "source": [
     "# Minimize error using cross entropy\n",
-    "cost = -tf.reduce_sum(y*tf.log(activation)) # Cross entropy\n",
-    "optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) # Gradient Descent"
+    "# Cross entropy\n",
+    "cost = -tf.reduce_sum(y*tf.log(activation)) \n",
+    "# Gradient Descent\n",
+    "optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) "
    ]
   },
   {

+ 13 - 2
notebooks/2 - Basic Classifiers/nearest_neighbor.ipynb

@@ -9,7 +9,8 @@
    "outputs": [],
    "source": [
     "# A nearest neighbor learning algorithm example using TensorFlow library.\n",
-    "# This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/)\n",
+    "# This example is using the MNIST database of handwritten digits \n",
+    "# (http://yann.lecun.com/exdb/mnist/)\n",
     "\n",
     "# Author: Aymeric Damien\n",
     "# Project: https://github.com/aymericdamien/TensorFlow-Examples/"
@@ -345,13 +346,23 @@
     "        # Get nearest neighbor\n",
     "        nn_index = sess.run(pred, feed_dict={xtr: Xtr, xte: Xte[i,:]})\n",
     "        # Get nearest neighbor class label and compare it to its true label\n",
-    "        print \"Test\", i, \"Prediction:\", np.argmax(Ytr[nn_index]), \"True Class:\", np.argmax(Yte[i])\n",
+    "        print \"Test\", i, \"Prediction:\", np.argmax(Ytr[nn_index]), \\\n",
+    "              \"True Class:\", np.argmax(Yte[i])\n",
     "        # Calculate accuracy\n",
     "        if np.argmax(Ytr[nn_index]) == np.argmax(Yte[i]):\n",
     "            accuracy += 1./len(Xte)\n",
     "    print \"Done!\"\n",
     "    print \"Accuracy:\", accuracy"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": []
   }
  ],
  "metadata": {

+ 13 - 7
notebooks/3 - Neural Networks/convolutional_network.ipynb

@@ -8,8 +8,9 @@
    },
    "outputs": [],
    "source": [
-    "# A Multilayer Perceptron implementation example using TensorFlow library.\n",
-    "# This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/)\n",
+    "# A Convolutional Networ implementation example using TensorFlow library.\n",
+    "# This example is using the MNIST database of handwritten digits\n",
+    "# (http://yann.lecun.com/exdb/mnist/)\n",
     "\n",
     "# Author: Aymeric Damien\n",
     "# Project: https://github.com/aymericdamien/TensorFlow-Examples/"
@@ -103,7 +104,8 @@
    "source": [
     "# Create model\n",
     "def conv2d(img, w, b):\n",
-    "    return tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(img, w, strides=[1, 1, 1, 1], padding='SAME'),b))\n",
+    "    return tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(img, w, strides=[1, 1, 1, 1], \n",
+    "                                                  padding='SAME'),b))\n",
     "\n",
     "def max_pool(img, k):\n",
     "    return tf.nn.max_pool(img, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME')\n",
@@ -149,10 +151,14 @@
    "source": [
     "# Store layers weight & bias\n",
     "weights = {\n",
-    "    'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])), # 5x5 conv, 1 input, 32 outputs\n",
-    "    'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])), # 5x5 conv, 32 inputs, 64 outputs\n",
-    "    'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])), # fully connected, 7*7*64 inputs, 1024 outputs\n",
-    "    'out': tf.Variable(tf.random_normal([1024, n_classes])) # 1024 inputs, 10 outputs (class prediction)\n",
+    "    # 5x5 conv, 1 input, 32 outputs\n",
+    "    'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])), \n",
+    "    # 5x5 conv, 32 inputs, 64 outputs\n",
+    "    'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])), \n",
+    "    # fully connected, 7*7*64 inputs, 1024 outputs\n",
+    "    'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])), \n",
+    "    # 1024 inputs, 10 outputs (class prediction)\n",
+    "    'out': tf.Variable(tf.random_normal([1024, n_classes])) \n",
     "}\n",
     "\n",
     "biases = {\n",

+ 10 - 5
notebooks/3 - Neural Networks/multilayer_perceptron.ipynb

@@ -9,7 +9,8 @@
    "outputs": [],
    "source": [
     "# A Multilayer Perceptron implementation example using TensorFlow library.\n",
-    "# This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/)\n",
+    "# This example is using the MNIST database of handwritten digits\n",
+    "# (http://yann.lecun.com/exdb/mnist/)\n",
     "\n",
     "# Author: Aymeric Damien\n",
     "# Project: https://github.com/aymericdamien/TensorFlow-Examples/"
@@ -103,8 +104,10 @@
    "source": [
     "# Create model\n",
     "def multilayer_perceptron(_X, _weights, _biases):\n",
-    "    layer_1 = tf.nn.relu(tf.add(tf.matmul(_X, _weights['h1']), _biases['b1'])) #Hidden layer with RELU activation\n",
-    "    layer_2 = tf.nn.relu(tf.add(tf.matmul(layer_1, _weights['h2']), _biases['b2'])) #Hidden layer with RELU activation\n",
+    "    #Hidden layer with RELU activation\n",
+    "    layer_1 = tf.nn.relu(tf.add(tf.matmul(_X, _weights['h1']), _biases['b1'])) \n",
+    "    #Hidden layer with RELU activation\n",
+    "    layer_2 = tf.nn.relu(tf.add(tf.matmul(layer_1, _weights['h2']), _biases['b2'])) \n",
     "    return tf.matmul(layer_2, weights['out']) + biases['out']"
    ]
   },
@@ -150,8 +153,10 @@
    "outputs": [],
    "source": [
     "# Define loss and optimizer\n",
-    "cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y)) # Softmax loss\n",
-    "optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) # Adam Optimizer"
+    "# Softmax loss\n",
+    "cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y)) \n",
+    "# Adam Optimizer\n",
+    "optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) "
    ]
   },
   {

+ 0 - 0
tensorflow_setup.md