【发布时间】:2019-08-13 06:04:23
【问题描述】:
我的目标是将张量转换为不带“运行”或“评估”的 ndarray。 我想执行与示例相同的操作。
A = tf.constant(5)
B = tf.constant([[A, 1], [0,0]])
但是,ndarray 可以在 tf.constant 内部,但 tensor 不能。 因此,我尝试使用以下示例执行操作,但 tf.make_ndarray 不起作用。
A = tf.constant(5)
C = tf.make_ndarray(A)
B = tf.constant([[C, 1], [0,0]])
https://github.com/tensorflow/tensorflow/issues/28840#issuecomment-509551333
如上面的 github 链接中所述,tf.make_ndarray 不起作用。 准确地说,是因为tensorflow需要一个不存在的“tensor_shape”,而不是一个存在的“shape”,所以发生了错误。
在这种情况下如何运行代码?
【问题讨论】:
-
tf.make_ndarray需要TensorProto(例如,从序列化图形中读取或使用tf.make_tensor_proto创建),而不是tf.Tensor。
标签: python tensorflow