我看了视频刚学习到 tensorboard,感觉是视频所用的 TF 版本过低的原因,我用新版本的 TF,命名之后的权重、偏置值之类的怎么看着这么啰嗦(命名都重复了,然后我去掉了命名代码,这些图又出不来了,蛋疼)…代码如下:
def add_layer (inputs, in_size, out_size, n_layer, actvation_faction=None):
layer_name = 'n_layer%s' % n_layer
with tf.name_scope (layer_name):
with tf.name_scope ('weights'):
Weights = tf.Variable (tf.random_normal ([in_size, out_size]), name='w')
tf.summary.histogram (layer_name+'/weights', Weights)
with tf.name_scope ('biases'):
biases = tf.Variable (tf.zeros ([1, out_size])+0.1, name='b')
tf.summary.histogram (layer_name+'/biases', biases)
with tf.name_scope ('Wx_plus_b'):
Wx_plus_b = tf.add (tf.matmul (inputs, Weights), biases)
if actvation_faction is None:
outputs = Wx_plus_b
else:
outputs = actvation_faction (Wx_plus_b,)
tf.summary.histogram (layer_name+'/outputs', outputs)
return outputs
上述问题在 Zerone01 的帮助下现已解决,理解了之后,现将代码改为:
def add_layer (inputs, in_size, out_size, n_layer, actvation_faction=None):
layer_name ='Layer_%s' % n_layer
with tf.name_scope (layer_name):
Weights = tf.Variable (tf.random_normal ([in_size, out_size]), name='w')
tf.summary.histogram ('/weights', Weights)
biases = tf.Variable (tf.zeros ([1, out_size])+0.1, name='b')
tf.summary.histogram ('/biases', biases)
Wx_plus_b = tf.add (tf.matmul (inputs, Weights), biases, name='wx_plus_b')
if actvation_faction is None:
outputs = Wx_plus_b
else:
outputs = actvation_faction (Wx_plus_b)
tf.summary.histogram ('/outputs', outputs)
return outputs
提问者:M 丶 Sulayman,发帖时间: 2018-4-27 11:16:26