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:
Aurelien Geron
2017-06-07 17:52:59 +02:00
parent 6689c3a1ef
commit 9938d0686b
3 changed files with 1727 additions and 1279 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",
@@ -209,7 +211,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",
@@ -254,7 +256,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",
@@ -300,15 +302,15 @@
"output_type": "stream",
"text": [
"No more files to read\n",
"[array([[ 4. , 5. ],\n",
" [ 1. , -508.17480469]], dtype=float32), array([1, 0], dtype=int32)]\n",
"[array([[ 4.00000000e+00, 5.00000000e+00],\n",
" [ 1.00000000e+00, 8.62997533e-19]], dtype=float32), array([1, 0], dtype=int32)]\n",
"[array([[ 7., 8.]], dtype=float32), array([0], dtype=int32)]\n",
"No more training instances\n"
]
}
],
"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",
@@ -393,15 +395,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[array([[ 1. , -508.17480469],\n",
" [ 7. , 8. ]], dtype=float32), array([0, 0], dtype=int32)]\n",
"[array([[ 4., 5.]], dtype=float32), array([1], dtype=int32)]\n",
"[array([[ 7., 8.],\n",
" [ 4., 5.]], dtype=float32), array([0, 1], dtype=int32)]\n",
"[array([[ 1.00000000e+00, 8.62997533e-19]], dtype=float32), array([0], dtype=int32)]\n",
"No more training instances\n"
]
}
],
"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",
@@ -451,15 +453,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[array([[ 1. , -508.17480469],\n",
" [ 4. , 5. ]], dtype=float32), array([0, 1], dtype=int32)]\n",
"[array([[ 4.00000000e+00, 5.00000000e+00],\n",
" [ 1.00000000e+00, 8.62997533e-19]], dtype=float32), array([1, 0], dtype=int32)]\n",
"[array([[ 7., 8.]], dtype=float32), array([0], dtype=int32)]\n",
"No more training instances\n"
]
}
],
"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",
@@ -529,7 +531,7 @@
}
],
"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",
@@ -577,7 +579,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {
"collapsed": true,
"deletable": true,