用于在张量流中调试的打印变量

时间:2018-02-12 16:06:24

标签: python tensorflow

我正在尝试在此代码中打印“kl_term”的值

x = tf.placeholder('float', [None, num_l1])
y = tf.placeholder('float')

l1, prediction = nn_model(x,num_l1,num_l2)
ro = float(sparcity_parm)
ro_h = tf.reduce_mean(l1+1e-15)

kl_term = tf.reduce_sum(beta * ( ( ro * tf.log(ro/ro_h) ) + ( (1 - ro) * tf.log((1-ro)/(1-ro_h)) ) ))

a3_yy = tf.reduce_mean((prediction - x)**2 ,axis=0)

cost = tf.reduce_mean(0.5 * a3_yy) + kl_term

optimizer = tf.train.AdamOptimizer().minimize(cost)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
for epoch in range(hm_epochs):
    epoch_loss = 0
    for i in range(int(data.shape[0]/batch_size)):
        epoch_x = data[i * batch_size : i * batch_size + batch_size,:]
        outt, c = sess.run([optimizer, cost], feed_dict={x: epoch_x, y: epoch_x})
        epoch_loss += c
        print("kl_term:", tf.Print(kl_term,[kl_term]))

所有打印出来的都是:

'kl_term:', <tf.Tensor 'Print_3:0' shape=() dtype=float32>

如何获得kl_term的实际值?

0 个答案:

没有答案