我已经在 tensorflow v2.0 和 v1.12.0(带有tf.enable_eager_execution()
)上尝试过这个。显然,如果我numpy()
在函数中使用下面显示的代码片段进行main()
调用,它会完美运行。但是,如果我在我的估计器模型函数中使用它,model_fn(features, labels, mode, params)
那么它会抱怨'Tensor' object has no attribute 'numpy'
.
ndarray = np.ones([3, 3])
tensor = tf.multiply(ndarray, 42)
print(tensor)
print(tensor.numpy())
有没有其他人遇到过类似的问题?对于 tf.estimator 来说,这似乎是个大问题?