|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 | 5 | "execution_count": 1,
|
6 |
| - "metadata": { |
7 |
| - "collapsed": false |
8 |
| - }, |
| 6 | + "metadata": {}, |
9 | 7 | "outputs": [],
|
10 | 8 | "source": [
|
11 | 9 | "import tensorflow as tf\n",
|
|
46 | 44 | {
|
47 | 45 | "cell_type": "code",
|
48 | 46 | "execution_count": 3,
|
49 |
| - "metadata": { |
50 |
| - "collapsed": false |
51 |
| - }, |
| 47 | + "metadata": {}, |
52 | 48 | "outputs": [],
|
53 | 49 | "source": [
|
54 | 50 | "def train(mnist):\n",
|
|
83 | 79 | "\n",
|
84 | 80 | " with tf.control_dependencies([train_step, variables_averages_op]):\n",
|
85 | 81 | " 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", |
87 | 85 | " # 训练模型。\n",
|
88 | 86 | " with tf.Session() as sess:\n",
|
89 | 87 | " tf.global_variables_initializer().run()\n",
|
90 |
| - " writer = tf.summary.FileWriter(\"/log/modified_mnist_train.log\", tf.get_default_graph())\n", |
91 | 88 | " for i in range(TRAINING_STEPS):\n",
|
92 | 89 | " xs, ys = mnist.train.next_batch(BATCH_SIZE)\n",
|
93 | 90 | "\n",
|
|
99 | 96 | " _, loss_value, step = sess.run(\n",
|
100 | 97 | " [train_op, loss, global_step], feed_dict={x: xs, y_: ys},\n",
|
101 | 98 | " 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", |
103 | 100 | " print(\"After %d training step(s), loss on training batch is %g.\" % (step, loss_value))\n",
|
104 | 101 | " else:\n",
|
105 | 102 | " _, 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()" |
110 | 105 | ]
|
111 | 106 | },
|
112 | 107 | {
|
|
119 | 114 | {
|
120 | 115 | "cell_type": "code",
|
121 | 116 | "execution_count": 4,
|
122 |
| - "metadata": { |
123 |
| - "collapsed": false |
124 |
| - }, |
| 117 | + "metadata": {}, |
125 | 118 | "outputs": [
|
126 | 119 | {
|
127 | 120 | "name": "stdout",
|
|
163 | 156 | "name": "python",
|
164 | 157 | "nbconvert_exporter": "python",
|
165 | 158 | "pygments_lexer": "ipython2",
|
166 |
| - "version": "2.7.10" |
| 159 | + "version": "2.7.13" |
167 | 160 | }
|
168 | 161 | },
|
169 | 162 | "nbformat": 4,
|
|
0 commit comments