tf.shape返回类型是Tensor,可以转换为list类型tensor.shape返回类型是TensorShape,无法转换为list类型,会报错
import tensorflow as tf
tensor = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
shape_tensor = tf.shape(tensor)
# error: cannot convert TensorShape into Tensor or List
test = tensor.shape
# 在会话中运行以获取形状值
with tf.Session() as sess:
shape_tensor_v = sess.run(shape_tensor)
tensor_shape_list = shape_tensor_v.tolist()
print("tensor shape:", tensor_shape_list)
# test_value = sess.run(test)
# print("test type: ", type(test_value))
7290

被折叠的 条评论
为什么被折叠?



