Skip to content

Commit 5b9aef4

Browse files
Refactor tensorboard_basic for TF1.0
Signed-off-by: Norman Heckscher <norman.heckscher@gmail.com>
1 parent 6985952 commit 5b9aef4

File tree

2 files changed

+43
-54
lines changed

2 files changed

+43
-54
lines changed

examples/4_Utils/tensorboard_basic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
init = tf.initialize_all_variables()
5353

5454
# Create a summary to monitor cost tensor
55-
tf.scalar_summary("loss", cost)
55+
tf.summary.scalar("loss", cost)
5656
# Create a summary to monitor accuracy tensor
57-
tf.scalar_summary("accuracy", acc)
57+
tf.summary.scalar("accuracy", acc)
5858
# Merge all summaries into a single op
59-
merged_summary_op = tf.merge_all_summaries()
59+
merged_summary_op = tf.summary.merge_all()
6060

6161
# Launch the graph
6262
with tf.Session() as sess:
6363
sess.run(init)
6464

6565
# op to write logs to Tensorboard
66-
summary_writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph())
66+
summary_writer = tf.summary.FileWriter(logs_path, graph=tf.get_default_graph())
6767

6868
# Training cycle
6969
for epoch in range(training_epochs):

notebooks/4_Utils/tensorboard_basic.ipynb

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,22 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 1,
23+
"execution_count": null,
2424
"metadata": {
2525
"collapsed": false
2626
},
27-
"outputs": [
28-
{
29-
"name": "stdout",
30-
"output_type": "stream",
31-
"text": [
32-
"Extracting /tmp/data/train-images-idx3-ubyte.gz\n",
33-
"Extracting /tmp/data/train-labels-idx1-ubyte.gz\n",
34-
"Extracting /tmp/data/t10k-images-idx3-ubyte.gz\n",
35-
"Extracting /tmp/data/t10k-labels-idx1-ubyte.gz\n"
36-
]
37-
}
38-
],
27+
"outputs": [],
3928
"source": [
4029
"import tensorflow as tf\n",
4130
"\n",
4231
"# Import MINST data\n",
4332
"from tensorflow.examples.tutorials.mnist import input_data\n",
44-
"mnist = input_data.read_data_sets(\"/tmp/data/\", one_hot=True)"
33+
"mnist = input_data.read_data_sets(\"MNIST_data/\", one_hot=True)"
4534
]
4635
},
4736
{
4837
"cell_type": "code",
49-
"execution_count": 2,
38+
"execution_count": 6,
5039
"metadata": {
5140
"collapsed": true
5241
},
@@ -72,9 +61,9 @@
7261
},
7362
{
7463
"cell_type": "code",
75-
"execution_count": 3,
64+
"execution_count": 9,
7665
"metadata": {
77-
"collapsed": true
66+
"collapsed": false
7867
},
7968
"outputs": [],
8069
"source": [
@@ -95,19 +84,19 @@
9584
" acc = tf.reduce_mean(tf.cast(acc, tf.float32))\n",
9685
"\n",
9786
"# Initializing the variables\n",
98-
"init = tf.initialize_all_variables()\n",
87+
"init = tf.global_variables_initializer()\n",
9988
"\n",
10089
"# Create a summary to monitor cost tensor\n",
101-
"tf.scalar_summary(\"loss\", cost)\n",
90+
"tf.summary.scalar(\"loss\", cost)\n",
10291
"# Create a summary to monitor accuracy tensor\n",
103-
"tf.scalar_summary(\"accuracy\", acc)\n",
92+
"tf.summary.scalar(\"accuracy\", acc)\n",
10493
"# Merge all summaries into a single op\n",
105-
"merged_summary_op = tf.merge_all_summaries()"
94+
"merged_summary_op = tf.summary.merge_all()"
10695
]
10796
},
10897
{
10998
"cell_type": "code",
110-
"execution_count": 4,
99+
"execution_count": 11,
111100
"metadata": {
112101
"collapsed": false
113102
},
@@ -116,31 +105,31 @@
116105
"name": "stdout",
117106
"output_type": "stream",
118107
"text": [
119-
"Epoch: 0001 cost= 1.182138957\n",
120-
"Epoch: 0002 cost= 0.664735104\n",
121-
"Epoch: 0003 cost= 0.552622685\n",
122-
"Epoch: 0004 cost= 0.498596912\n",
123-
"Epoch: 0005 cost= 0.465510372\n",
124-
"Epoch: 0006 cost= 0.442504281\n",
125-
"Epoch: 0007 cost= 0.425473650\n",
126-
"Epoch: 0008 cost= 0.412175615\n",
127-
"Epoch: 0009 cost= 0.401374554\n",
128-
"Epoch: 0010 cost= 0.392403109\n",
129-
"Epoch: 0011 cost= 0.384748503\n",
130-
"Epoch: 0012 cost= 0.378154479\n",
131-
"Epoch: 0013 cost= 0.372405099\n",
132-
"Epoch: 0014 cost= 0.367272844\n",
133-
"Epoch: 0015 cost= 0.362745077\n",
134-
"Epoch: 0016 cost= 0.358575674\n",
135-
"Epoch: 0017 cost= 0.354862829\n",
136-
"Epoch: 0018 cost= 0.351437834\n",
137-
"Epoch: 0019 cost= 0.348300697\n",
138-
"Epoch: 0020 cost= 0.345401101\n",
139-
"Epoch: 0021 cost= 0.342762216\n",
140-
"Epoch: 0022 cost= 0.340199728\n",
141-
"Epoch: 0023 cost= 0.337916089\n",
142-
"Epoch: 0024 cost= 0.335764083\n",
143-
"Epoch: 0025 cost= 0.333645939\n",
108+
"Epoch: 0001 cost= 1.182138961\n",
109+
"Epoch: 0002 cost= 0.664609327\n",
110+
"Epoch: 0003 cost= 0.552565036\n",
111+
"Epoch: 0004 cost= 0.498541865\n",
112+
"Epoch: 0005 cost= 0.465393374\n",
113+
"Epoch: 0006 cost= 0.442491178\n",
114+
"Epoch: 0007 cost= 0.425474149\n",
115+
"Epoch: 0008 cost= 0.412152022\n",
116+
"Epoch: 0009 cost= 0.401320939\n",
117+
"Epoch: 0010 cost= 0.392305281\n",
118+
"Epoch: 0011 cost= 0.384732356\n",
119+
"Epoch: 0012 cost= 0.378109478\n",
120+
"Epoch: 0013 cost= 0.372409370\n",
121+
"Epoch: 0014 cost= 0.367236996\n",
122+
"Epoch: 0015 cost= 0.362727492\n",
123+
"Epoch: 0016 cost= 0.358627345\n",
124+
"Epoch: 0017 cost= 0.354815522\n",
125+
"Epoch: 0018 cost= 0.351413656\n",
126+
"Epoch: 0019 cost= 0.348314827\n",
127+
"Epoch: 0020 cost= 0.345429416\n",
128+
"Epoch: 0021 cost= 0.342749324\n",
129+
"Epoch: 0022 cost= 0.340224642\n",
130+
"Epoch: 0023 cost= 0.337897302\n",
131+
"Epoch: 0024 cost= 0.335720168\n",
132+
"Epoch: 0025 cost= 0.333691911\n",
144133
"Optimization Finished!\n",
145134
"Accuracy: 0.9143\n",
146135
"Run the command line:\n",
@@ -155,7 +144,7 @@
155144
" sess.run(init)\n",
156145
"\n",
157146
" # op to write logs to Tensorboard\n",
158-
" summary_writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph())\n",
147+
" summary_writer = tf.summary.FileWriter(logs_path, graph=tf.get_default_graph())\n",
159148
"\n",
160149
" # Training cycle\n",
161150
" for epoch in range(training_epochs):\n",
@@ -234,7 +223,7 @@
234223
],
235224
"metadata": {
236225
"kernelspec": {
237-
"display_name": "IPython (Python 2.7)",
226+
"display_name": "Python 2",
238227
"language": "python",
239228
"name": "python2"
240229
},
@@ -248,7 +237,7 @@
248237
"name": "python",
249238
"nbconvert_exporter": "python",
250239
"pygments_lexer": "ipython2",
251-
"version": "2.7.11"
240+
"version": "2.7.13"
252241
}
253242
},
254243
"nbformat": 4,

0 commit comments

Comments
 (0)