代码之家  ›  专栏  ›  技术社区  ›  DsCpp

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

  •  0
  • DsCpp  · 技术社区  · 7 年前

    我正试图建立一个基于学习变量的移位反步函数:
    例如

    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 回复  |  直到 7 年前
        1
  •  0
  •   DsCpp    7 年前

    最后我使用了另一种方法,因为大多数稀疏函数还没有为操作定义gradiend。

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

    实现相同的功能

    推荐文章