Skip to content

Commit e480af0

Browse files
authored
Update 2. 改造后的mnist_train.ipynb
1 parent e8c6c92 commit e480af0

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

Deep_Learning_with_TensorFlow/1.0.0/Chapter09/2. 改造后的mnist_train.ipynb

+10-17
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": 1,
6-
"metadata": {
7-
"collapsed": false
8-
},
6+
"metadata": {},
97
"outputs": [],
108
"source": [
119
"import tensorflow as tf\n",
@@ -46,9 +44,7 @@
4644
{
4745
"cell_type": "code",
4846
"execution_count": 3,
49-
"metadata": {
50-
"collapsed": false
51-
},
47+
"metadata": {},
5248
"outputs": [],
5349
"source": [
5450
"def train(mnist):\n",
@@ -83,11 +79,12 @@
8379
"\n",
8480
" with tf.control_dependencies([train_step, variables_averages_op]):\n",
8581
" train_op = tf.no_op(name='train')\n",
86-
" \n",
82+
" \n",
83+
" writer = tf.summary.FileWriter(\"/log/modified_mnist_train.log\", tf.get_default_graph())\n",
84+
" \n",
8785
" # 训练模型。\n",
8886
" with tf.Session() as sess:\n",
8987
" tf.global_variables_initializer().run()\n",
90-
" writer = tf.summary.FileWriter(\"/log/modified_mnist_train.log\", tf.get_default_graph())\n",
9188
" for i in range(TRAINING_STEPS):\n",
9289
" xs, ys = mnist.train.next_batch(BATCH_SIZE)\n",
9390
"\n",
@@ -99,14 +96,12 @@
9996
" _, loss_value, step = sess.run(\n",
10097
" [train_op, loss, global_step], feed_dict={x: xs, y_: ys},\n",
10198
" options=run_options, run_metadata=run_metadata)\n",
102-
" writer.add_run_metadata(run_metadata=run_metadata, tag=(\"tag%d\"%i), global_step=i),\n",
99+
" writer.add_run_metadata(run_metadata=run_metadata, tag=(\"tag%d\" % i), global_step=i)\n",
103100
" print(\"After %d training step(s), loss on training batch is %g.\" % (step, loss_value))\n",
104101
" else:\n",
105102
" _, loss_value, step = sess.run([train_op, loss, global_step], feed_dict={x: xs, y_: ys})\n",
106-
"\n",
107-
"\n",
108-
"
109-
" writer.close()"
103+
" \n",
104+
" writer.close()"
110105
]
111106
},
112107
{
@@ -119,9 +114,7 @@
119114
{
120115
"cell_type": "code",
121116
"execution_count": 4,
122-
"metadata": {
123-
"collapsed": false
124-
},
117+
"metadata": {},
125118
"outputs": [
126119
{
127120
"name": "stdout",
@@ -163,7 +156,7 @@
163156
"name": "python",
164157
"nbconvert_exporter": "python",
165158
"pygments_lexer": "ipython2",
166-
"version": "2.7.10"
159+
"version": "2.7.13"
167160
}
168161
},
169162
"nbformat": 4,

0 commit comments

Comments
 (0)