基于学习变量的tf步进函数

时间:2018-12-08 20:28:07

标签: tensorflow

我正在尝试基于学习变量构建移位的反向步进函数:
例如

step_length = 8
learn_point = tf.Variable(step_length/2) #initial value
step = tf.Variable(np.ones(step_length),dtype=tf.float32,trainable=False)
step = tf.scatter_update(step,tf.range(learn_point,step_length),tf.zeros(tf.reshape(learn_point,[1])))

    #will generate 
    # step = [1,1,1,1,0,0,0,0] -> for learn_point = 4
    # step = [1,1,1,1,1,0,0,0] -> for learn_point = 5

我尝试使用上面的代码实现这一目标,但是由于散点更新没有指定渐变,因此返回了错误

LookupError: No gradient defined for operation 'ScatterUpdate_4' (op type: ScatterUpdate)

1 个答案:

答案 0 :(得分:0)

我最终使用了不同的方法,因为大多数稀疏函数还没有为操作定义梯度。

    step = tf.concat([tf.ones(given_axis - weight_param,dtype=tf.float32),
    tf.zeros(weight_param,dtype=tf.float32)],axis=-1)

实现相同的功能