我的代码如下:
import tensorflow as tf
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()
# read data from input file
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 })
init_state_ckfs = np.array([i.tolist()[0] for i in out[1]])
init_var_ckfs = np.array([i.diagonal().tolist() for i in out[2]])
此代码用于以批处理模式运行Cubature卡尔曼滤波器(CKF)。例如:
num_ckfs = 5
表示此代码将并行运行5个CKF。现在,我想要做的是根据num_ckfs的值将工作负载分配到多个节点。例如,如果我将num_ckfs作为参数传递给代码,并将其设置为20,000,那么我会将工作负载分配到4个节点,每个节点运行5000个。
我想使用分布式版本的Tensorflow来做到这一点。有人可以给我一些关于如何实现这一目标的提示吗?理想情况下,我应该在单个节点上执行代码,然后将其分配到
中定义的任意数量的节点tf.train.ClusterSpec