This error occurs because the input to tf.stack() should be a list of tensors, but in this case, x is already a tensor.

To fix this error, you can simply remove the tf.stack() call and pass x directly to tf.constant().

Here's an example:

import tensorflow as tf

# assume x is a list of tensors
x = [tf.ones((3, 3)), tf.zeros((3, 3))]

# create a constant tensor from x
x_tensor = tf.constant(x)

print(x_tensor)

Output:

tf.Tensor(
[[[1. 1. 1.]
  [1. 1. 1.]
  [1. 1. 1.]]

 [[0. 0. 0.]
  [0. 0. 0.]
  [0. 0. 0.]]], shape=(2, 3, 3), dtype=float32)
x = tfconstanttfstackx TypeError List of Tensors when single Tensor expected

原文地址: https://www.cveoy.top/t/topic/bKVD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录