有没有办法用tf扫描?具体地说,我有这个代码用于Theano,我无法将此代码转换为Tensorflow。我尝试过使用标准的循环和张量切片和连接,但我认为它在优化中无法获得梯度。在
stick_segment = theano.shared(value=np.zeros((batch_size,), dtype=theano.config.floatX), name='stick_segment')
remaining_stick = theano.shared(value=np.ones((batch_size,), dtype=theano.config.floatX), name='remaining_stick')
def compute_latent_vars(i, stick_segment, remaining_stick, v_samples):
# compute stick segment
stick_segment = v_samples[:,i] * remaining_stick
remaining_stick *= (1-v_samples[:,i])
return (stick_segment, remaining_stick)
(stick_segments, remaining_sticks), updates = theano.scan(fn=compute_latent_vars,
outputs_info=[stick_segment, remaining_stick],sequences=T.arange(latent_size-1),
non_sequences=[v_samples], strict=True)
我能够将Theano代码转换为Tensorflow,但是我无法得到梯度。也就是说,代码是:
^{pr2}$但当我看到π或rem的梯度时,它们是非零的。但是当我看到z的梯度时,所有的都是0。是因为concat公司?有什么方法可以防止这个问题吗?在
目前没有回答
相关问题 更多 >
编程相关推荐