老师您好,我在跑以下方程时遇到 “TypeError: must be real number, not Tensor” 的问题 我现在tensorflow的版本是1.13, python版本是3. 您知道该如何解决这个问题吗?
我的代码为:
init = tf.global_variables_initializer()
batch_size = 20
train_steps = 1000
with tf.Session() as sess:
sess.run(init)
for i in range(0, train_steps):
batch_data, batch_lables = train_data.next_batch(batch_size)
loss_val, accur_val, _ = sess.run([loss, accuracy, train_op],
feed_dict = {x: batch_data, y: batch_lables})
if i % 500 == 0:
print ('[Train] Step: %d, loss: %4.5f, acc: %4.5f' \
% (i, loss_val, accuracy))
以下是报错信息
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/folders/ht/s_lk_n7j245dpr0sk715tk500000gn/T/ipykernel_47765/1309685021.py in <module>
12 if i % 500 == 0:
13 print ('[Train] Step: %d, loss: %4.5f, acc: %4.5f' \
---> 14 % (i, loss_val, accuracy))
TypeError: must be real number, not Tensor