我有以下基本tensorflow应用程序。它给我执行时的错误:
TypeError: Fetch argument None has invalid type <class 'NoneType'>
张量板说:"No scalar data was found."
我猜测应该将square, power, sqrt, final_sum
中的一个或全部明确添加到摘要中,但我不知道该怎么做。
import tensorflow as tf
a = tf.constant(6, name='constant_a')
b = tf.constant(3, name='constant_b')
c = tf.constant(10, name='constant_c')
d = tf.constant(5.0, name='constant_d')
mul = tf.multiply(a,b, name='mul')
square = tf.square(a, name="square_a")
power = tf.pow(b, c, name="pow_b_c")
sqrt = tf.sqrt(d, name="sqrt_d")
final_sum = tf.add_n([square, power, tf.to_int32(sqrt)], name="final_sum")
sess = tf.Session()
print("Square of a: ", sess.run(square))
print("power of b, c: ", sess.run(power))
print("Square root of of d: ", sess.run(sqrt))
print("Final sum of square, power, and square root: ", sess.run(final_sum))
writer = tf.summary.FileWriter('./m2_example2', sess.graph)
# Creates a TensorFlow tensor that includes information from all summaries
# defined in the current graph.
summary_t = tf.summary.merge_all()
# Computes the current value of all summaries in the current graph.
summary_val = sess.run(summary_t)
writer.add_summary(summary_val)
writer.close()
sess.close()