我正在使用Python 3 与TensorFlow 1.12 及即时执行模式(eager eval)。
我试图按照这里的说明使用散列更新(scatter update)。
我遇到了以下错误:
AttributeError: ‘EagerTensor’ 对象没有属性 ‘_lazy_read’
是否有解决方法或在即时执行模式下可用的其他函数?
回答:
scatter_update 需要变量(Variable)而不是常量张量(constant tensor):
对变量引用应用稀疏更新。
我猜你是向 scater_update
传递了一个常量张量,导致抛出异常。以下是在即时执行模式下的示例:
import tensorflow as tftf.enable_eager_execution()data = tf.Variable([[2], [3], [4], [5], [6]])cond = tf.where(tf.less(data, 5)) # 更新小于5的值match_data = tf.gather_nd(data, cond)square_data = tf.square(match_data) # 对小于5的值进行平方data = tf.scatter_nd_update(data, cond, square_data)print(data)# array([[ 4],# [ 9],# [16],# [ 5],# [ 6]], dtype=int32)>