我用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来说,这似乎是个大问题吗?