Tensorflow:将输入传递给迭代程序的有效方法

时间:2016-09-16 18:35:23

标签: tensorflow

以下是我的代码的样子:

N = 16, num_ckfs = 5
init_variances = tf.placeholder(tf.float64, shape=[ num_ckfs, N],name='inital_variances')

init_states = tf.placeholder(tf.float64, shape=[num_ckfs, N], name='init_states')

#some more code

predicted_state =  prior_state_expanded + kalman_gain * diff_expanded

error_covariance = sum_cov_cholesky + tf.batch_matmul(kg , kalman_gain, adj_x=True)


projected_output = tf.batch_matmul(predicted_state,input_vectors_extra, adj_y=True)

session = tf.Session()  


init_var = [10 for i in range(N)]
init_var_ckfs = [init_var for i in range(num_ckfs)]



init_state = [0 for i in range(N)]
init_state_ckfs = [init_state for i in range(num_ckfs)]

for timestep in range(10):

   out= session.run([projected_output, predicted_state, error_covariance], {init_variances:init_var_ckfs, init_states:init_state_ckfs })

   #for the next tilmestep, I want to initialize init_state_ckfs with the predicted_state, and the init_var_ckfs with error_covariance.
   #predicted_state is a tensor with shape (num_ckfs, 1, N)
   #error_covariance is a tensor with shape (num_ckfs, N, N): I just need the diagonal elements from each of the N X N matrices

虽然我在代码中已将此作为评论提及,但我将在此再次提及。我想知道如何使用上一个时间步骤中更新的张量,将它们转换为列表并将它们作为输入提供给下一个时间步。有人可以帮助我。

1 个答案:

答案 0 :(得分:1)

使用tf.assign为占位符分配变量的最后一个值。只要会话处于活动状态,就会保留状态