Merge branch 'master' of github.com:ageron/handson-ml

main
Aurélien Geron 2017-11-09 16:40:44 +01:00
commit b17a6c8e63
10 changed files with 665 additions and 2095 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1494,7 +1494,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"* Yikes, only 48% **Survived**. :( That's close to 50%, so accuracy will be a reasonable metric to evaluate our model.\n", "* Yikes, only 38% **Survived**. :( That's close enough to 40%, so accuracy will be a reasonable metric to evaluate our model.\n",
"* The mean **Fare** was £32.20, which does not seem so expensive (but it was probably a lot of money back then).\n", "* The mean **Fare** was £32.20, which does not seem so expensive (but it was probably a lot of money back then).\n",
"* The mean **Age** was less than 30 years old." "* The mean **Age** was less than 30 years old."
] ]

View File

@ -1017,7 +1017,8 @@
" boundary_x2s = -x1s*(w[0]/w[1])-b/w[1]\n", " boundary_x2s = -x1s*(w[0]/w[1])-b/w[1]\n",
" margin_x2s_1 = -x1s*(w[0]/w[1])-(b-1)/w[1]\n", " margin_x2s_1 = -x1s*(w[0]/w[1])-(b-1)/w[1]\n",
" margin_x2s_2 = -x1s*(w[0]/w[1])-(b+1)/w[1]\n", " margin_x2s_2 = -x1s*(w[0]/w[1])-(b+1)/w[1]\n",
" ax.plot_surface(x1s, x2, 0, color=\"b\", alpha=0.2, cstride=100, rstride=100)\n", " ax.plot_surface(x1s, x2, np.zeros_like(x1),\n",
" color=\"b\", alpha=0.2, cstride=100, rstride=100)\n",
" ax.plot(x1s, boundary_x2s, 0, \"k-\", linewidth=2, label=r\"$h=0$\")\n", " ax.plot(x1s, boundary_x2s, 0, \"k-\", linewidth=2, label=r\"$h=0$\")\n",
" ax.plot(x1s, margin_x2s_1, 0, \"k--\", linewidth=2, label=r\"$h=\\pm 1$\")\n", " ax.plot(x1s, margin_x2s_1, 0, \"k--\", linewidth=2, label=r\"$h=\\pm 1$\")\n",
" ax.plot(x1s, margin_x2s_2, 0, \"k--\", linewidth=2)\n", " ax.plot(x1s, margin_x2s_2, 0, \"k--\", linewidth=2)\n",

View File

@ -2,40 +2,28 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"**Chapter 10 Introduction to Artificial Neural Networks**" "**Chapter 10 Introduction to Artificial Neural Networks**"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"_This notebook contains all the sample code and solutions to the exercises in chapter 10._" "_This notebook contains all the sample code and solutions to the exercises in chapter 10._"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"# Setup" "# Setup"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"First, let's make sure this notebook works well in both python 2 and 3, import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures:" "First, let's make sure this notebook works well in both python 2 and 3, import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures:"
] ]
@ -43,11 +31,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# To support both python 2 and python 3\n", "# To support both python 2 and python 3\n",
@ -85,10 +69,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"# Perceptrons" "# Perceptrons"
] ]
@ -97,9 +78,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -120,11 +99,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"y_pred" "y_pred"
@ -133,11 +108,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = -per_clf.coef_[0][0] / per_clf.coef_[0][1]\n", "a = -per_clf.coef_[0][0] / per_clf.coef_[0][1]\n",
@ -173,10 +144,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"# Activation functions" "# Activation functions"
] ]
@ -185,9 +153,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -204,11 +170,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 6,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"z = np.linspace(-5, 5, 200)\n", "z = np.linspace(-5, 5, 200)\n",
@ -245,9 +207,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 7,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -264,11 +224,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 8,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x1s = np.linspace(-0.2, 1.2, 100)\n", "x1s = np.linspace(-0.2, 1.2, 100)\n",
@ -297,20 +253,14 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"# FNN for MNIST" "# FNN for MNIST"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"## using tf.learn" "## using tf.learn"
] ]
@ -318,11 +268,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 9,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from tensorflow.examples.tutorials.mnist import input_data\n", "from tensorflow.examples.tutorials.mnist import input_data\n",
@ -334,9 +280,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 10,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -349,11 +293,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 11,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf\n", "import tensorflow as tf\n",
@ -370,11 +310,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 12,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from sklearn.metrics import accuracy_score\n", "from sklearn.metrics import accuracy_score\n",
@ -386,11 +322,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 13,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from sklearn.metrics import log_loss\n", "from sklearn.metrics import log_loss\n",
@ -402,9 +334,7 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"source": [ "source": [
"## Using plain TensorFlow" "## Using plain TensorFlow"
@ -413,11 +343,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 14,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf\n", "import tensorflow as tf\n",
@ -431,11 +357,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 15,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -447,11 +369,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 16,
"metadata": { "metadata": {},
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def neuron_layer(X, n_neurons, name, activation=None):\n", "def neuron_layer(X, n_neurons, name, activation=None):\n",
@ -471,11 +389,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 17,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.name_scope(\"dnn\"):\n", "with tf.name_scope(\"dnn\"):\n",
@ -489,11 +403,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 18,
"metadata": { "metadata": {},
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.name_scope(\"loss\"):\n", "with tf.name_scope(\"loss\"):\n",
@ -505,11 +415,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 19,
"metadata": { "metadata": {},
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"learning_rate = 0.01\n", "learning_rate = 0.01\n",
@ -522,11 +428,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 20,
"metadata": { "metadata": {},
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.name_scope(\"eval\"):\n", "with tf.name_scope(\"eval\"):\n",
@ -537,11 +439,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 21,
"metadata": { "metadata": {},
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()\n", "init = tf.global_variables_initializer()\n",
@ -551,11 +449,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 22,
"metadata": { "metadata": {},
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_epochs = 40\n", "n_epochs = 40\n",
@ -565,11 +459,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 23,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.Session() as sess:\n", "with tf.Session() as sess:\n",
@ -579,9 +469,9 @@
" X_batch, y_batch = mnist.train.next_batch(batch_size)\n", " X_batch, y_batch = mnist.train.next_batch(batch_size)\n",
" sess.run(training_op, feed_dict={X: X_batch, y: y_batch})\n", " sess.run(training_op, feed_dict={X: X_batch, y: y_batch})\n",
" acc_train = accuracy.eval(feed_dict={X: X_batch, y: y_batch})\n", " acc_train = accuracy.eval(feed_dict={X: X_batch, y: y_batch})\n",
" acc_test = accuracy.eval(feed_dict={X: mnist.test.images,\n", " acc_val = accuracy.eval(feed_dict={X: mnist.validation.images,\n",
" y: mnist.test.labels})\n", " y: mnist.validation.labels})\n",
" print(epoch, \"Train accuracy:\", acc_train, \"Test accuracy:\", acc_test)\n", " print(epoch, \"Train accuracy:\", acc_train, \"Val accuracy:\", acc_val)\n",
"\n", "\n",
" save_path = saver.save(sess, \"./my_model_final.ckpt\")" " save_path = saver.save(sess, \"./my_model_final.ckpt\")"
] ]
@ -589,11 +479,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 24,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.Session() as sess:\n", "with tf.Session() as sess:\n",
@ -606,11 +492,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": 25,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"print(\"Predicted classes:\", y_pred)\n", "print(\"Predicted classes:\", y_pred)\n",
@ -621,9 +503,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": 26,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -668,11 +548,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 27,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"show_graph(tf.get_default_graph())" "show_graph(tf.get_default_graph())"
@ -680,20 +556,14 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"## Using `dense()` instead of `neuron_layer()`" "## Using `dense()` instead of `neuron_layer()`"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"Note: the book uses `tensorflow.contrib.layers.fully_connected()` rather than `tf.layers.dense()` (which did not exist when this chapter was written). It is now preferable to use `tf.layers.dense()`, because anything in the contrib module may change or be deleted without notice. The `dense()` function is almost identical to the `fully_connected()` function, except for a few minor differences:\n", "Note: the book uses `tensorflow.contrib.layers.fully_connected()` rather than `tf.layers.dense()` (which did not exist when this chapter was written). It is now preferable to use `tf.layers.dense()`, because anything in the contrib module may change or be deleted without notice. The `dense()` function is almost identical to the `fully_connected()` function, except for a few minor differences:\n",
"* several parameters are renamed: `scope` becomes `name`, `activation_fn` becomes `activation` (and similarly the `_fn` suffix is removed from other parameters such as `normalizer_fn`), `weights_initializer` becomes `kernel_initializer`, etc.\n", "* several parameters are renamed: `scope` becomes `name`, `activation_fn` becomes `activation` (and similarly the `_fn` suffix is removed from other parameters such as `normalizer_fn`), `weights_initializer` becomes `kernel_initializer`, etc.\n",
@ -704,11 +574,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 28,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_inputs = 28*28 # MNIST\n", "n_inputs = 28*28 # MNIST\n",
@ -721,9 +587,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 29,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -736,11 +600,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 30,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.name_scope(\"dnn\"):\n", "with tf.name_scope(\"dnn\"):\n",
@ -755,9 +615,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 31,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -770,9 +628,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 32,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -787,9 +643,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 33,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -802,9 +656,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 34,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -815,11 +667,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 35,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_epochs = 20\n", "n_epochs = 20\n",
@ -841,11 +689,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 36,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"show_graph(tf.get_default_graph())" "show_graph(tf.get_default_graph())"
@ -854,9 +698,7 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"source": [ "source": [
"# Exercise solutions" "# Exercise solutions"
@ -864,10 +706,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"## 1. to 8." "## 1. to 8."
] ]
@ -875,9 +714,7 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"source": [ "source": [
"See appendix A." "See appendix A."
@ -885,30 +722,21 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"## 9." "## 9."
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"_Train a deep MLP on the MNIST dataset and see if you can get over 98% precision. Just like in the last exercise of chapter 9, try adding all the bells and whistles (i.e., save checkpoints, restore the last checkpoint in case of an interruption, add summaries, plot learning curves using TensorBoard, and so on)._" "_Train a deep MLP on the MNIST dataset and see if you can get over 98% precision. Just like in the last exercise of chapter 9, try adding all the bells and whistles (i.e., save checkpoints, restore the last checkpoint in case of an interruption, add summaries, plot learning curves using TensorBoard, and so on)._"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"First let's create the deep net. It's exactly the same as earlier, with just one addition: we add a `tf.summary.scalar()` to track the loss and the accuracy during training, so we can view nice learning curves using TensorBoard." "First let's create the deep net. It's exactly the same as earlier, with just one addition: we add a `tf.summary.scalar()` to track the loss and the accuracy during training, so we can view nice learning curves using TensorBoard."
] ]
@ -916,11 +744,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 37,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_inputs = 28*28 # MNIST\n", "n_inputs = 28*28 # MNIST\n",
@ -933,9 +757,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 38,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -948,11 +770,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 39,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.name_scope(\"dnn\"):\n", "with tf.name_scope(\"dnn\"):\n",
@ -967,9 +785,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 40,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -983,9 +799,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 41,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1000,9 +814,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 42,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1016,9 +828,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 43,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1028,10 +838,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"Now we need to define the directory to write the TensorBoard logs to:" "Now we need to define the directory to write the TensorBoard logs to:"
] ]
@ -1040,9 +847,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 44,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1061,9 +866,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 45, "execution_count": 45,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1072,10 +875,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"Now we can create the `FileWriter` that we will use to write the TensorBoard logs:" "Now we can create the `FileWriter` that we will use to write the TensorBoard logs:"
] ]
@ -1084,9 +884,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 46,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1095,10 +893,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"deletable": true,
"editable": true
},
"source": [ "source": [
"Hey! Why don't we implement early stopping? For this, we are going to need a validation set. Luckily, the dataset returned by TensorFlow's `input_data()` function (see above) is already split into a training set (60,000 instances, already shuffled for us), a validation set (5,000 instances) and a test set (5,000 instances). So we can easily define `X_valid` and `y_valid`:" "Hey! Why don't we implement early stopping? For this, we are going to need a validation set. Luckily, the dataset returned by TensorFlow's `input_data()` function (see above) is already split into a training set (60,000 instances, already shuffled for us), a validation set (5,000 instances) and a test set (5,000 instances). So we can easily define `X_valid` and `y_valid`:"
] ]
@ -1106,11 +901,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 47,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_valid = mnist.validation.images\n", "X_valid = mnist.validation.images\n",
@ -1121,9 +912,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 48,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1133,11 +922,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 49,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_epochs = 10001\n", "n_epochs = 10001\n",
@ -1190,11 +975,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 50,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"os.remove(checkpoint_epoch_path)" "os.remove(checkpoint_epoch_path)"
@ -1203,11 +984,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 51,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.Session() as sess:\n", "with tf.Session() as sess:\n",
@ -1218,11 +995,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 52,
"metadata": { "metadata": {},
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"accuracy_val" "accuracy_val"
@ -1232,9 +1005,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": true, "collapsed": true
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [] "source": []
@ -1256,7 +1027,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.3" "version": "3.6.2"
}, },
"nav_menu": { "nav_menu": {
"height": "264px", "height": "264px",
@ -1273,5 +1044,5 @@
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -3312,7 +3312,14 @@
"rnd_search = RandomizedSearchCV(DNNClassifier(random_state=42), param_distribs, n_iter=50,\n", "rnd_search = RandomizedSearchCV(DNNClassifier(random_state=42), param_distribs, n_iter=50,\n",
" fit_params={\"X_valid\": X_valid1, \"y_valid\": y_valid1, \"n_epochs\": 1000},\n", " fit_params={\"X_valid\": X_valid1, \"y_valid\": y_valid1, \"n_epochs\": 1000},\n",
" random_state=42, verbose=2)\n", " random_state=42, verbose=2)\n",
"rnd_search.fit(X_train1, y_train1)" "rnd_search.fit(X_train1, y_train1)\n",
"\n",
"# fit_params as a constructor argument was deprecated in Scikit-Learn version 0.19 and will\n",
"# be removed in version 0.21. Pass fit parameters to the fit() method instead:\n",
"# rnd_search = RandomizedSearchCV(DNNClassifier(random_state=42), param_distribs, n_iter=50,\n",
"# random_state=42, verbose=2)\n",
"# fit_params={\"X_valid\": X_valid1, \"y_valid\": y_valid1, \"n_epochs\": 1000}\n",
"# rnd_search.fit(X_train1, y_train1, **fit_params)\n"
] ]
}, },
{ {
@ -4934,7 +4941,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.3" "version": "3.6.2"
}, },
"nav_menu": { "nav_menu": {
"height": "360px", "height": "360px",

View File

@ -144,7 +144,6 @@
"fmap = np.zeros(shape=(7, 7, 1, 2), dtype=np.float32)\n", "fmap = np.zeros(shape=(7, 7, 1, 2), dtype=np.float32)\n",
"fmap[:, 3, 0, 0] = 1\n", "fmap[:, 3, 0, 0] = 1\n",
"fmap[3, :, 0, 1] = 1\n", "fmap[3, :, 0, 1] = 1\n",
"fmap[:, :, 0, 0]\n",
"plot_image(fmap[:, :, 0, 0])\n", "plot_image(fmap[:, :, 0, 0])\n",
"plt.show()\n", "plt.show()\n",
"plot_image(fmap[:, :, 0, 1])\n", "plot_image(fmap[:, :, 0, 1])\n",
@ -501,6 +500,17 @@
" saver = tf.train.Saver()" " saver = tf.train.Saver()"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Note: if you are using Python 3.6 on OSX, you need to run the following command on terminal to install the certifi package of certificates because Python 3.6 on OSX has no certificates to validate SSL connections (see this [StackOverflow question](https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error)):\n",
"\n",
" $ /Applications/Python\\ 3.6/Install\\ Certificates.command"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 22,
@ -1949,7 +1959,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2" "version": "3.6.2"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {

View File

@ -31,9 +31,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# To support both python 2 and python 3\n", "# To support both python 2 and python 3\n",
@ -79,9 +77,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf" "import tensorflow as tf"
@ -104,9 +100,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -130,9 +124,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
@ -173,9 +165,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 7,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_inputs = 3\n", "n_inputs = 3\n",
@ -185,9 +175,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 8,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -204,9 +192,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 9,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()" "init = tf.global_variables_initializer()"
@ -215,9 +201,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 10,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X0_batch = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 0, 1]])\n", "X0_batch = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 0, 1]])\n",
@ -249,9 +233,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 13,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from IPython.display import clear_output, Image, display, HTML\n", "from IPython.display import clear_output, Image, display, HTML\n",
@ -311,9 +293,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 15,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_steps = 2\n", "n_steps = 2\n",
@ -324,9 +304,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 16,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -343,9 +321,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 17,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()" "init = tf.global_variables_initializer()"
@ -354,9 +330,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 18,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_batch = np.array([\n", "X_batch = np.array([\n",
@ -400,9 +374,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 21,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_steps = 2\n", "n_steps = 2\n",
@ -413,9 +385,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 22,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -429,9 +399,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 23,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()" "init = tf.global_variables_initializer()"
@ -440,9 +408,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 24,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_batch = np.array([\n", "X_batch = np.array([\n",
@ -485,9 +451,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 27,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_steps = 2\n", "n_steps = 2\n",
@ -503,9 +467,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 28,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"seq_length = tf.placeholder(tf.int32, [None])\n", "seq_length = tf.placeholder(tf.int32, [None])\n",
@ -516,9 +478,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 29,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()" "init = tf.global_variables_initializer()"
@ -527,9 +487,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 30,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_batch = np.array([\n", "X_batch = np.array([\n",
@ -545,9 +503,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 31,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.Session() as sess:\n", "with tf.Session() as sess:\n",
@ -593,9 +549,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 34,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -668,9 +622,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 37,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -688,9 +640,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 38,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_neurons = 100\n", "n_neurons = 100\n",
@ -706,9 +656,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 39,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"states_concat = tf.concat(axis=1, values=states)\n", "states_concat = tf.concat(axis=1, values=states)\n",
@ -754,9 +702,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 41,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"t_min, t_max = 0, 30\n", "t_min, t_max = 0, 30\n",
@ -808,9 +754,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 43,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_batch, y_batch = next_batch(1, n_steps)" "X_batch, y_batch = next_batch(1, n_steps)"
@ -842,9 +786,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 45, "execution_count": 45,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -871,9 +813,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 46,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -890,9 +830,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 47,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"cell = tf.contrib.rnn.OutputProjectionWrapper(\n", "cell = tf.contrib.rnn.OutputProjectionWrapper(\n",
@ -903,9 +841,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 48,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"outputs, states = tf.nn.dynamic_rnn(cell, X, dtype=tf.float32)" "outputs, states = tf.nn.dynamic_rnn(cell, X, dtype=tf.float32)"
@ -914,9 +850,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 49,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"learning_rate = 0.001\n", "learning_rate = 0.001\n",
@ -931,9 +865,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 50,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"saver = tf.train.Saver()" "saver = tf.train.Saver()"
@ -1009,9 +941,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": 55,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -1027,9 +957,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 56, "execution_count": 56,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"cell = tf.contrib.rnn.BasicRNNCell(num_units=n_neurons, activation=tf.nn.relu)\n", "cell = tf.contrib.rnn.BasicRNNCell(num_units=n_neurons, activation=tf.nn.relu)\n",
@ -1039,9 +967,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 57,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_outputs = 1\n", "n_outputs = 1\n",
@ -1051,9 +977,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 58,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"stacked_rnn_outputs = tf.reshape(rnn_outputs, [-1, n_neurons])\n", "stacked_rnn_outputs = tf.reshape(rnn_outputs, [-1, n_neurons])\n",
@ -1064,9 +988,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 59,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"loss = tf.reduce_mean(tf.square(outputs - y))\n", "loss = tf.reduce_mean(tf.square(outputs - y))\n",
@ -1216,9 +1138,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 66, "execution_count": 66,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -1232,9 +1152,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 67, "execution_count": 67,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_neurons = 100\n", "n_neurons = 100\n",
@ -1249,9 +1167,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 68, "execution_count": 68,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()" "init = tf.global_variables_initializer()"
@ -1260,9 +1176,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 69, "execution_count": 69,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_batch = np.random.rand(2, n_steps, n_inputs)" "X_batch = np.random.rand(2, n_steps, n_inputs)"
@ -1271,9 +1185,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 70, "execution_count": 70,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.Session() as sess:\n", "with tf.Session() as sess:\n",
@ -1307,9 +1219,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 72, "execution_count": 72,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with tf.device(\"/gpu:0\"): # BAD! This is ignored.\n", "with tf.device(\"/gpu:0\"): # BAD! This is ignored.\n",
@ -1329,9 +1239,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 73, "execution_count": 73,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf\n", "import tensorflow as tf\n",
@ -1357,9 +1265,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 74, "execution_count": 74,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -1374,9 +1280,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 75, "execution_count": 75,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"devices = [\"/cpu:0\", \"/cpu:0\", \"/cpu:0\"] # replace with [\"/gpu:0\", \"/gpu:1\", \"/gpu:2\"] if you have 3 GPUs\n", "devices = [\"/cpu:0\", \"/cpu:0\", \"/cpu:0\"] # replace with [\"/gpu:0\", \"/gpu:1\", \"/gpu:2\"] if you have 3 GPUs\n",
@ -1386,12 +1290,17 @@
"outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)" "outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, since TensorFlow 1.1, you can use the `tf.contrib.rnn.DeviceWrapper` class (alias `tf.nn.rnn_cell.DeviceWrapper` since TF 1.2)."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 76, "execution_count": 76,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"init = tf.global_variables_initializer()" "init = tf.global_variables_initializer()"
@ -1420,9 +1329,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 78, "execution_count": 78,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -1431,22 +1338,33 @@
"n_neurons = 100\n", "n_neurons = 100\n",
"n_layers = 3\n", "n_layers = 3\n",
"n_steps = 20\n", "n_steps = 20\n",
"n_outputs = 1\n", "n_outputs = 1"
"\n",
"X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])\n",
"y = tf.placeholder(tf.float32, [None, n_steps, n_outputs])"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 79, "execution_count": 79,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"keep_prob = 0.5\n", "X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])\n",
"\n", "y = tf.placeholder(tf.float32, [None, n_steps, n_outputs])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: the `input_keep_prob` parameter can be a placeholder, making it possible to set it to any value you want during training, and to 1.0 during testing (effectively turning dropout off). This is a much more elegant solution than what was recommended in earlier versions of the book (i.e., writing your own wrapper class or having a separate model for training and testing). Thanks to Shen Cheng for bringing this to my attention."
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [],
"source": [
"keep_prob = tf.placeholder_with_default(1.0, shape=())\n",
"cells = [tf.contrib.rnn.BasicRNNCell(num_units=n_neurons)\n", "cells = [tf.contrib.rnn.BasicRNNCell(num_units=n_neurons)\n",
" for layer in range(n_layers)]\n", " for layer in range(n_layers)]\n",
"cells_drop = [tf.contrib.rnn.DropoutWrapper(cell, input_keep_prob=keep_prob)\n", "cells_drop = [tf.contrib.rnn.DropoutWrapper(cell, input_keep_prob=keep_prob)\n",
@ -1457,10 +1375,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 80, "execution_count": 81,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"learning_rate = 0.01\n", "learning_rate = 0.01\n",
@ -1477,78 +1393,29 @@
"saver = tf.train.Saver()" "saver = tf.train.Saver()"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unfortunately, this code is only usable for training, because the `DropoutWrapper` class has no `training` parameter, so it always applies dropout, even when the model is not being trained, so we must first train the model, then create a different model for testing, without the `DropoutWrapper`."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 81, "execution_count": 82,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_iterations = 1000\n", "n_iterations = 1500\n",
"batch_size = 50\n", "batch_size = 50\n",
"train_keep_prob = 0.5\n",
"\n", "\n",
"with tf.Session() as sess:\n", "with tf.Session() as sess:\n",
" init.run()\n", " init.run()\n",
" for iteration in range(n_iterations):\n", " for iteration in range(n_iterations):\n",
" X_batch, y_batch = next_batch(batch_size, n_steps)\n", " X_batch, y_batch = next_batch(batch_size, n_steps)\n",
" _, mse = sess.run([training_op, loss], feed_dict={X: X_batch, y: y_batch})\n", " _, mse = sess.run([training_op, loss],\n",
" if iteration % 100 == 0:\n", " feed_dict={X: X_batch, y: y_batch,\n",
" print(iteration, \"Training MSE:\", mse)\n", " keep_prob: train_keep_prob})\n",
" if iteration % 100 == 0: # not shown in the book\n",
" print(iteration, \"Training MSE:\", mse) # not shown\n",
" \n", " \n",
" saver.save(sess, \"./my_dropout_time_series_model\")" " saver.save(sess, \"./my_dropout_time_series_model\")"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that the model is trained, we need to create the model again, but without the `DropoutWrapper` for testing:"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"reset_graph()\n",
"\n",
"n_inputs = 1\n",
"n_neurons = 100\n",
"n_layers = 3\n",
"n_steps = 20\n",
"n_outputs = 1\n",
"\n",
"X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])\n",
"y = tf.placeholder(tf.float32, [None, n_steps, n_outputs])\n",
"\n",
"keep_prob = 0.5\n",
"\n",
"cells = [tf.contrib.rnn.BasicRNNCell(num_units=n_neurons)\n",
" for layer in range(n_layers)]\n",
"multi_layer_cell = tf.contrib.rnn.MultiRNNCell(cells)\n",
"rnn_outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)\n",
"\n",
"learning_rate = 0.01\n",
"\n",
"stacked_rnn_outputs = tf.reshape(rnn_outputs, [-1, n_neurons])\n",
"stacked_outputs = tf.layers.dense(stacked_rnn_outputs, n_outputs)\n",
"outputs = tf.reshape(stacked_outputs, [-1, n_steps, n_outputs])\n",
"\n",
"loss = tf.reduce_mean(tf.square(outputs - y))\n",
"\n",
"init = tf.global_variables_initializer()\n",
"saver = tf.train.Saver()"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 83, "execution_count": 83,
@ -1559,8 +1426,15 @@
" saver.restore(sess, \"./my_dropout_time_series_model\")\n", " saver.restore(sess, \"./my_dropout_time_series_model\")\n",
"\n", "\n",
" X_new = time_series(np.array(t_instance[:-1].reshape(-1, n_steps, n_inputs)))\n", " X_new = time_series(np.array(t_instance[:-1].reshape(-1, n_steps, n_inputs)))\n",
" y_pred = sess.run(outputs, feed_dict={X: X_new})\n", " y_pred = sess.run(outputs, feed_dict={X: X_new})"
"\n", ]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [],
"source": [
"plt.title(\"Testing the model\", fontsize=14)\n", "plt.title(\"Testing the model\", fontsize=14)\n",
"plt.plot(t_instance[:-1], time_series(t_instance[:-1]), \"bo\", markersize=10, label=\"instance\")\n", "plt.plot(t_instance[:-1], time_series(t_instance[:-1]), \"bo\", markersize=10, label=\"instance\")\n",
"plt.plot(t_instance[1:], time_series(t_instance[1:]), \"w*\", markersize=10, label=\"target\")\n", "plt.plot(t_instance[1:], time_series(t_instance[1:]), \"w*\", markersize=10, label=\"target\")\n",
@ -1578,59 +1452,6 @@
"Oops, it seems that Dropout does not help at all in this particular case. :/" "Oops, it seems that Dropout does not help at all in this particular case. :/"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another option is to write a script with a command line argument to specify whether you want to train the mode or use it for making predictions:"
]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [],
"source": [
"reset_graph()\n",
"\n",
"import sys\n",
"training = True # in a script, this would be (sys.argv[-1] == \"train\") instead\n",
"\n",
"X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])\n",
"y = tf.placeholder(tf.float32, [None, n_steps, n_outputs])\n",
"\n",
"cells = [tf.contrib.rnn.BasicRNNCell(num_units=n_neurons)\n",
" for layer in range(n_layers)]\n",
"if training:\n",
" cells = [tf.contrib.rnn.DropoutWrapper(cell, input_keep_prob=keep_prob)\n",
" for cell in cells]\n",
"multi_layer_cell = tf.contrib.rnn.MultiRNNCell(cells)\n",
"rnn_outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)\n",
"\n",
"stacked_rnn_outputs = tf.reshape(rnn_outputs, [-1, n_neurons]) # not shown in the book\n",
"stacked_outputs = tf.layers.dense(stacked_rnn_outputs, n_outputs) # not shown\n",
"outputs = tf.reshape(stacked_outputs, [-1, n_steps, n_outputs]) # not shown\n",
"loss = tf.reduce_mean(tf.square(outputs - y)) # not shown\n",
"optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate) # not shown\n",
"training_op = optimizer.minimize(loss) # not shown\n",
"init = tf.global_variables_initializer() # not shown\n",
"saver = tf.train.Saver() # not shown\n",
"\n",
"with tf.Session() as sess:\n",
" if training:\n",
" init.run()\n",
" for iteration in range(n_iterations):\n",
" X_batch, y_batch = next_batch(batch_size, n_steps) # not shown\n",
" _, mse = sess.run([training_op, loss], feed_dict={X: X_batch, y: y_batch}) # not shown\n",
" if iteration % 100 == 0: # not shown\n",
" print(iteration, \"Training MSE:\", mse) # not shown\n",
" save_path = saver.save(sess, \"/tmp/my_model.ckpt\")\n",
" else:\n",
" saver.restore(sess, \"/tmp/my_model.ckpt\")\n",
" X_new = time_series(np.array(t_instance[:-1].reshape(-1, n_steps, n_inputs))) # not shown\n",
" y_pred = sess.run(outputs, feed_dict={X: X_new}) # not shown"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -2706,7 +2527,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2" "version": "3.6.2"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {

View File

@ -131,6 +131,8 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy.random as rnd\n",
"\n",
"rnd.seed(4)\n", "rnd.seed(4)\n",
"m = 200\n", "m = 200\n",
"w1, w2 = 0.1, 0.3\n", "w1, w2 = 0.1, 0.3\n",

View File

@ -31,9 +31,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# To support both python 2 and python 3\n", "# To support both python 2 and python 3\n",
@ -95,9 +93,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import gym" "import gym"
@ -129,9 +125,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"obs = env.reset()" "obs = env.reset()"
@ -163,9 +157,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 6,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"img = env.render(mode=\"rgb_array\")" "img = env.render(mode=\"rgb_array\")"
@ -226,9 +218,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 9,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def plot_environment(env, figsize=(5,4)):\n", "def plot_environment(env, figsize=(5,4)):\n",
@ -273,9 +263,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 11,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"env.reset()\n", "env.reset()\n",
@ -311,9 +299,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 13,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"obs, reward, done, info = env.step(0)" "obs, reward, done, info = env.step(0)"
@ -393,9 +379,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 18,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"frames = []\n", "frames = []\n",
@ -424,9 +408,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 19,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def update_scene(num, frames, patch):\n", "def update_scene(num, frames, patch):\n",
@ -461,9 +443,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 21,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"env.close()" "env.close()"
@ -502,9 +482,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 23,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"obs = env.reset()" "obs = env.reset()"
@ -547,9 +525,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": 25,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from PIL import Image, ImageDraw\n", "from PIL import Image, ImageDraw\n",
@ -633,9 +609,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 28,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"obs = env.reset()\n", "obs = env.reset()\n",
@ -677,9 +651,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 31,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"obs = env.reset()\n", "obs = env.reset()\n",
@ -722,9 +694,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 33,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"frames = []\n", "frames = []\n",
@ -795,9 +765,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 35,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf\n", "import tensorflow as tf\n",
@ -846,9 +814,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 36,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_max_steps = 1000\n", "n_max_steps = 1000\n",
@ -895,9 +861,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 38,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf\n", "import tensorflow as tf\n",
@ -965,9 +929,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 40,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def render_policy_net(model_path, action, X, n_max_steps = 1000):\n", "def render_policy_net(model_path, action, X, n_max_steps = 1000):\n",
@ -1024,9 +986,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 42,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import tensorflow as tf\n", "import tensorflow as tf\n",
@ -1069,9 +1029,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 43,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def discount_rewards(rewards, discount_rate):\n", "def discount_rewards(rewards, discount_rate):\n",
@ -1157,9 +1115,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 47,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"env.close()" "env.close()"
@ -1309,9 +1265,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 51,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"n_states = 3\n", "n_states = 3\n",
@ -1336,9 +1290,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 52,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def optimal_policy(state):\n", "def optimal_policy(state):\n",
@ -1439,23 +1391,28 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 57,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"mspacman_color = np.array([210, 164, 74]).mean()\n", "mspacman_color = 210 + 164 + 74\n",
"\n", "\n",
"def preprocess_observation(obs):\n", "def preprocess_observation(obs):\n",
" img = obs[1:176:2, ::2] # crop and downsize\n", " img = obs[1:176:2, ::2] # crop and downsize\n",
" img = img.mean(axis=2) # to greyscale\n", " img = img.sum(axis=2) # to greyscale\n",
" img[img==mspacman_color] = 0 # Improve contrast\n", " img[img==mspacman_color] = 0 # Improve contrast\n",
" img = (img - 128) / 128 - 1 # normalize from -1. to 1.\n", " img = (img // 3 - 128).astype(np.int8) # normalize from -128 to 127\n",
" return img.reshape(88, 80, 1)\n", " return img.reshape(88, 80, 1)\n",
"\n", "\n",
"img = preprocess_observation(obs)" "img = preprocess_observation(obs)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: the `preprocess_observation()` function is slightly different from the one in the book: instead of representing pixels as 64-bit floats from -1.0 to 1.0, it represents them as signed bytes (from -128 to 127). The benefit is that the replay memory will take up roughly 8 times less RAM (about 6.5 GB instead of 52 GB). The reduced precision has no visible impact on training."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 58,
@ -1498,9 +1455,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 59,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"reset_graph()\n", "reset_graph()\n",
@ -1520,7 +1475,7 @@
"initializer = tf.contrib.layers.variance_scaling_initializer()\n", "initializer = tf.contrib.layers.variance_scaling_initializer()\n",
"\n", "\n",
"def q_network(X_state, name):\n", "def q_network(X_state, name):\n",
" prev_layer = X_state\n", " prev_layer = X_state / 128.0 # scale pixel intensities to the [-1.0, 1.0] range.\n",
" with tf.variable_scope(name) as scope:\n", " with tf.variable_scope(name) as scope:\n",
" for n_maps, kernel_size, strides, padding, activation in zip(\n", " for n_maps, kernel_size, strides, padding, activation in zip(\n",
" conv_n_maps, conv_kernel_sizes, conv_strides,\n", " conv_n_maps, conv_kernel_sizes, conv_strides,\n",
@ -1545,9 +1500,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 60,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"X_state = tf.placeholder(tf.float32, shape=[None, input_height, input_width,\n", "X_state = tf.placeholder(tf.float32, shape=[None, input_height, input_width,\n",
@ -1572,9 +1525,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 62,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"learning_rate = 0.001\n", "learning_rate = 0.001\n",
@ -1608,9 +1559,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 63, "execution_count": 63,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from collections import deque\n", "from collections import deque\n",
@ -1632,9 +1581,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 64, "execution_count": 64,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"eps_min = 0.1\n", "eps_min = 0.1\n",
@ -1678,9 +1625,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 66, "execution_count": 66,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"loss_val = np.infty\n", "loss_val = np.infty\n",
@ -1970,7 +1915,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2" "version": "3.6.3"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {

File diff suppressed because it is too large Load Diff