Python 在图模式下求张量

Python 在图模式下求张量,python,tensorflow2.x,Python,Tensorflow2.x,标题已经说明了这一点:我需要在图形模式下计算张量(通过字符串名访问dict中的值)。不幸的是,这引发了一个错误 有解决办法吗 @tf.function def any_function(a): return a.numpy().tolist() b = tf.constant(2) any_function(b) 提出: “AttributeError:'Tensor'对象没有属性'numpy'”

标题已经说明了这一点:我需要在图形模式下计算张量(通过字符串名访问dict中的值)。不幸的是,这引发了一个错误

有解决办法吗

@tf.function
def any_function(a):
    return a.numpy().tolist()

b = tf.constant(2)
any_function(b)
提出: “AttributeError:'Tensor'对象没有属性'numpy'”