diff --git a/11_deep_learning.ipynb b/11_deep_learning.ipynb index 90c320a..b4bc4b3 100644 --- a/11_deep_learning.ipynb +++ b/11_deep_learning.ipynb @@ -55,11 +55,13 @@ "\n", "# Common imports\n", "import numpy as np\n", - "import numpy.random as rnd\n", "import os\n", "\n", "# to make this notebook's output stable across runs\n", - "rnd.seed(42)\n", + "def reset_graph(seed=42):\n", + " tf.reset_default_graph()\n", + " tf.set_random_seed(seed)\n", + " np.random.seed(seed)\n", "\n", "# To plot pretty figures\n", "%matplotlib inline\n", @@ -181,7 +183,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -281,7 +283,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "X = tf.placeholder(tf.float32, shape=(None, n_inputs), name=\"X\")" ] @@ -322,7 +324,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -540,7 +542,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "X = tf.placeholder(tf.float32, shape=(None, n_inputs), name=\"X\")" ] @@ -596,7 +598,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "import tensorflow as tf\n", "\n", @@ -632,7 +634,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "X = tf.placeholder(tf.float32, shape=(None, n_inputs), name=\"X\")\n", "training = tf.placeholder_with_default(False, shape=(), name='training')" @@ -693,7 +695,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "batch_norm_momentum = 0.9\n", "\n", @@ -886,7 +888,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -1070,7 +1072,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()" + "reset_graph()" ] }, { @@ -1336,7 +1338,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -1431,7 +1433,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_hidden4 = 20 # new layer\n", "n_outputs = 10 # new layer\n", @@ -1517,7 +1519,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300 # reused\n", @@ -1622,7 +1624,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 2\n", "n_hidden1 = 3" @@ -1690,7 +1692,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 2\n", "n_hidden1 = 3\n", @@ -1802,7 +1804,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300 # reused\n", @@ -1904,7 +1906,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300 # reused\n", @@ -2026,7 +2028,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300 # reused\n", @@ -2104,7 +2106,7 @@ " h2_cache_test = sess.run(hidden2, feed_dict={X: mnist.test.images}) # not shown in the book\n", "\n", " for epoch in range(n_epochs):\n", - " shuffled_idx = rnd.permutation(mnist.train.num_examples)\n", + " shuffled_idx = np.random.permutation(mnist.train.num_examples)\n", " hidden2_batches = np.array_split(h2_cache[shuffled_idx], n_batches)\n", " y_batches = np.array_split(mnist.train.labels[shuffled_idx], n_batches)\n", " for hidden2_batch, y_batch in zip(hidden2_batches, y_batches):\n", @@ -2265,7 +2267,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -2390,7 +2392,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -2518,7 +2520,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28 # MNIST\n", "n_hidden1 = 300\n", @@ -2694,7 +2696,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "X = tf.placeholder(tf.float32, shape=(None, n_inputs), name=\"X\")\n", "y = tf.placeholder(tf.int64, shape=(None), name=\"y\")" @@ -2807,7 +2809,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28\n", "n_hidden1 = 300\n", @@ -3012,7 +3014,7 @@ }, "outputs": [], "source": [ - "tf.reset_default_graph()\n", + "reset_graph()\n", "\n", "n_inputs = 28 * 28\n", "n_hidden1 = 300\n",