没有加下面这条语句的效果
tf.name_scope('relu')
手动整理一下tensorboard的输出
import tensorflow as tf
def relu(X):
with tf.name_scope('relu'):
w_shape = (int(X.get_shape()[1]), 1)
w = tf.Variable(tf.random_normal(w_shape), name="weights")
b = tf.Variable(0.0, name="bias")
z = tf.add(tf.matmul(X, w), b, name="z")
return tf.maximum(z, 0., name="relu")
n_features = 3
X = tf.placeholder(tf.float32, shape=(None, n_features), name="X")
relus = [relu(X) for i in range(5)]
output = tf.add_n(relus, name="output")
file_writer = tf.summary.FileWriter('log/', tf.get_default_graph())
可以看到加了name_scope使得每次循环调用relu的时候,把relu内部的代码全部整合到了一个block里面,每个block用不同的名字区分