Use np.random.set_seed(42) and tf.set_random_seed(42) to make notebook's output constant, and simplify code in notebook 15

This commit is contained in:
Aurélien Geron
2017-06-07 17:52:59 +02:00
parent 045150bd95
commit 74794da1de
3 changed files with 957 additions and 648 deletions

View File

@@ -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",
@@ -201,7 +203,7 @@
},
"outputs": [],
"source": [
"tf.reset_default_graph()\n",
"reset_graph()\n",
"\n",
"with tf.device(\"/job:ps\"):\n",
" a = tf.Variable(1.0, name=\"a\")\n",
@@ -238,7 +240,7 @@
},
"outputs": [],
"source": [
"tf.reset_default_graph()\n",
"reset_graph()\n",
"\n",
"with tf.device(tf.train.replica_device_setter(\n",
" ps_tasks=2,\n",
@@ -280,7 +282,7 @@
},
"outputs": [],
"source": [
"tf.reset_default_graph()\n",
"reset_graph()\n",
"\n",
"test_csv = open(\"my_test.csv\", \"w\")\n",
"test_csv.write(\"x1, x2 , target\\n\")\n",
@@ -362,7 +364,7 @@
},
"outputs": [],
"source": [
"tf.reset_default_graph()\n",
"reset_graph()\n",
"\n",
"filename_queue = tf.FIFOQueue(capacity=10, dtypes=[tf.string], shapes=[()])\n",
"filename = tf.placeholder(tf.string)\n",
@@ -409,7 +411,7 @@
},
"outputs": [],
"source": [
"tf.reset_default_graph()\n",
"reset_graph()\n",
"\n",
"def read_and_push_instance(filename_queue, instance_queue):\n",
" reader = tf.TextLineReader(skip_header_lines=1)\n",
@@ -467,7 +469,7 @@
},
"outputs": [],
"source": [
"tf.reset_default_graph()\n",
"reset_graph()\n",
"\n",
"q = tf.FIFOQueue(capacity=10, dtypes=[tf.float32], shapes=[()])\n",
"v = tf.placeholder(tf.float32)\n",
@@ -515,7 +517,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {
"collapsed": true,
"deletable": true,