Skip to content

Commit

Permalink
Update 2. 改造后的mnist_train.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
perhapszzy authored Aug 31, 2017
1 parent e8c6c92 commit e480af0
Showing 1 changed file with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
Expand Down Expand Up @@ -46,9 +44,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"def train(mnist):\n",
Expand Down Expand Up @@ -83,11 +79,12 @@
"\n",
" with tf.control_dependencies([train_step, variables_averages_op]):\n",
" train_op = tf.no_op(name='train')\n",
" \n",
" \n",
" writer = tf.summary.FileWriter(\"/log/modified_mnist_train.log\", tf.get_default_graph())\n",
" \n",
" # 训练模型。\n",
" with tf.Session() as sess:\n",
" tf.global_variables_initializer().run()\n",
" writer = tf.summary.FileWriter(\"/log/modified_mnist_train.log\", tf.get_default_graph())\n",
" for i in range(TRAINING_STEPS):\n",
" xs, ys = mnist.train.next_batch(BATCH_SIZE)\n",
"\n",
Expand All @@ -99,14 +96,12 @@
" _, loss_value, step = sess.run(\n",
" [train_op, loss, global_step], feed_dict={x: xs, y_: ys},\n",
" options=run_options, run_metadata=run_metadata)\n",
" writer.add_run_metadata(run_metadata=run_metadata, tag=(\"tag%d\"%i), global_step=i),\n",
" writer.add_run_metadata(run_metadata=run_metadata, tag=(\"tag%d\" % i), global_step=i)\n",
" print(\"After %d training step(s), loss on training batch is %g.\" % (step, loss_value))\n",
" else:\n",
" _, loss_value, step = sess.run([train_op, loss, global_step], feed_dict={x: xs, y_: ys})\n",
"\n",
"\n",
"
" writer.close()"
" \n",
" writer.close()"
]
},
{
Expand All @@ -119,9 +114,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -163,7 +156,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
"version": "2.7.13"
}
},
"nbformat": 4,
Expand Down

0 comments on commit e480af0

Please sign in to comment.