我想制作两个汇总,它们采用不同的输入张量var_a_smooth
和var_b_smooth
,但共享相同的摘要名称范围,因此它们共享例如张量板表示。
我试图用相同的名称声明它们,但是按照预期,tensorflow在摘要名称中添加了“ _1”。
var_a = tf.random.normal([1], 0 , 1)
var_b = tf.random.normal([1], 0 , 5)
var_a = tf.get_variable(name="variable_a", dtype=tf.float32, initializer=tf.constant(0.), trainable=False)
val_a_smooth = var.assign(var * 0.99 + 0.01 * var_a)
var_b = tf.get_variable(name="variable_b", dtype=tf.float32, initializer=tf.constant(2.), trainable=False)
val_b_smooth = var.assign(var * 0.99 + 0.01 * var_b)
tf.summary.scalar("metric", val_a_smooth, collections=["train"])
tf.summary.scalar("metric", val_b_smooth, collections=["valid"])
train_writer = tf.summary.FileWriter("train_writer"), sess.graph)
valid_writer = tf.summary.FileWriter("valid_writer")
merged_tr = tf.summary.merge([tf.get_collection("train")])
merged_vl = tf.summary.merge([tf.get_collection("valid")])
for i in range(20):
if i % 5 == 0:
vl = sess.run(merged_vl)
valid_writer.add_summary(vl, i)
else:
tr = sess.run(merged_tr)
train_writer.add_summary(tr, i)