【发布时间】:2020-01-31 17:24:01
【问题描述】:
我使用 Tensorflow 2.0 并有一个张量 X 我想用 Numpy 处理。
如果我打印张量,我会得到以下信息:
print(X) =
Tensor("mul_1:0", shape=(1000, 64), dtype=float32)
我尝试使用 X.numpy() 和 X.as_numpy() 将张量转换为 numpy 数组,这会引发以下错误:
AttributeError: 'Tensor' object has no attribute 'numpy'
AttributeError: 'Tensor' object has no attribute 'as_numpy'
如何访问张量的值?
编辑:
当我使用print(type(X)) 时,我得到:
<class 'tensorflow.python.framework.ops.Tensor'>
【问题讨论】:
-
您是否禁用了急切执行?
-
@user3483203 没有。但我也尝试在
X.numpy()之前使用tf.executing_eagerly(),但没有解决问题。 -
请给出一个独立的可重现示例,从问题中的信息中我们几乎无法判断。
-
你的
X是什么?它是否存储任何值或者它是一个占位符并且 tf 2.0 不需要急切执行 -
@ShubhamShaswat
X是一个张量。print(X) = Tensor("mul_1:0", shape=(1000, 64), dtype=float32)。 TF 2.0 中没有占位符,对吧?
标签: python numpy tensorflow tensorflow2.0