tf.summary内部不同的函数如何正确地合并它们?

时间:2019-06-16 18:59:20

标签: python tensorflow

我想通过调用适当的函数动态创建诸如权重和偏差之类的变量,为每个函数获取tf.summary,然后将它们合并 同时使用两个FileWriter,一个用于训练集,另一个用于验证

我在模型定义后尝试了tf.summary.merge_all(),但它不起作用

例如:

def weight_dict(shape,name):
    init = tf.truncated_normal(shape, stddev=0.1)
return(tf.Variable(init,name=name))

def bias_dict(shape,name):
    init = tf.constant(0.1, shape=shape)
return(tf.Variable(init,name=name))

def conv_layer(inp, shape,name):
    W = weight_dict(shape,(name+'_w'))
    b = bias_dict([shape[3]],(name+'_b'))

    weigth_summ = tf.summary.histogram('weigths',W,collections=['weigths'])
    bias_summ = tf.summary.histogram('biases',b,collections=['biases'])

 return (conv2d(inp,W,b,name))

class CNN():
    def model():
        conv_layer_1 = conv_layer()
        #..............
        conv_layer_n = conv_layer()

network = model()
init = tf.global_variable_initializer()
merged = tf.summary.merge_all()

with tf.Session() as sess:
  sess.run(init)
 # .......

0 个答案:

没有答案