Skip to content

Commit cd04b76

Browse files
committedJan 14, 2017
delete
1 parent 361b9fe commit cd04b76

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed
 

‎tensorflowTUT/tf14_tensorboard/full_code.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4747
sess = tf.Session()
4848

4949
# tf.train.SummaryWriter soon be deprecated, use following
50-
writer = tf.summary.FileWriter("logs/", sess.graph)
50+
if int((tf.__version__).split('.')[1]) < 12: # tensorflow version < 0.12
51+
writer = tf.train.SummaryWriter('logs/', sess.graph)
52+
else: # tensorflow version >= 0.12
53+
writer = tf.summary.FileWriter("logs/", sess.graph)
5154

5255
# tf.initialize_all_variables() no long valid from
5356
# 2017-03-02 if using tensorflow >= 0.12

‎tensorflowTUT/tf15_tensorboard/full_code.py

+44-17
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,38 @@
1414
def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
1515
# add one more layer and return the output of this layer
1616
layer_name = 'layer%s' % n_layer
17-
with tf.name_scope(layer_name):
18-
with tf.name_scope('weights'):
19-
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
20-
tf.histogram_summary(layer_name + '/weights', Weights)
21-
with tf.name_scope('biases'):
22-
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
23-
tf.histogram_summary(layer_name + '/biases', biases)
24-
with tf.name_scope('Wx_plus_b'):
25-
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
26-
if activation_function is None:
27-
outputs = Wx_plus_b
28-
else:
29-
outputs = activation_function(Wx_plus_b, )
30-
tf.histogram_summary(layer_name + '/outputs', outputs)
17+
18+
# for tensorflow version < 0.12
19+
if int((tf.__version__).split('.')[1]) < 12:
20+
with tf.name_scope(layer_name):
21+
with tf.name_scope('weights'):
22+
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
23+
tf.histogram_summary(layer_name + '/weights', Weights)
24+
with tf.name_scope('biases'):
25+
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
26+
tf.histogram_summary(layer_name + '/biases', biases)
27+
with tf.name_scope('Wx_plus_b'):
28+
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
29+
if activation_function is None:
30+
outputs = Wx_plus_b
31+
else:
32+
outputs = activation_function(Wx_plus_b, )
33+
tf.histogram_summary(layer_name + '/outputs', outputs)
34+
else: # tensorflow version >= 0.12
35+
with tf.name_scope(layer_name):
36+
with tf.name_scope('weights'):
37+
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
38+
tf.summary.histogram(layer_name + '/weights', Weights)
39+
with tf.name_scope('biases'):
40+
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
41+
tf.summary.histogram(layer_name + '/biases', biases)
42+
with tf.name_scope('Wx_plus_b'):
43+
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
44+
if activation_function is None:
45+
outputs = Wx_plus_b
46+
else:
47+
outputs = activation_function(Wx_plus_b, )
48+
tf.summary.histogram(layer_name + '/outputs', outputs)
3149
return outputs
3250

3351

@@ -50,16 +68,25 @@ def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
5068
with tf.name_scope('loss'):
5169
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),
5270
reduction_indices=[1]))
53-
tf.scalar_summary('loss', loss)
71+
if int((tf.__version__).split('.')[1]) < 12: # tensorflow version < 0.12
72+
tf.scalar_summary('loss', loss)
73+
else: # tensorflow version >= 0.12
74+
tf.summary.scalar('loss', loss)
5475

5576
with tf.name_scope('train'):
5677
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
5778

5879
sess = tf.Session()
59-
merged = tf.merge_all_summaries()
80+
if int((tf.__version__).split('.')[1]) < 12: # tensorflow version < 0.12
81+
merged = tf.merge_all_summaries()
82+
else: # tensorflow version >= 0.12
83+
merged = tf.summary.merge_all()
6084

6185
# tf.train.SummaryWriter soon be deprecated, use following
62-
writer = tf.summary.FileWriter("logs/", sess.graph)
86+
if int((tf.__version__).split('.')[1]) < 12: # tensorflow version < 0.12
87+
writer = tf.train.SummaryWriter('logs/', sess.graph)
88+
else: # tensorflow version >= 0.12
89+
writer = tf.summary.FileWriter("logs/", sess.graph)
6390

6491
# tf.initialize_all_variables() no long valid from
6592
# 2017-03-02 if using tensorflow >= 0.12

0 commit comments

Comments
 (0)
Please sign in to comment.