tf.while_loop 的用法

def get_non_zero_rawdata(new_features):

    raw_pos_tan = new_features['raw_pos_tan']
    raw_sita = tf.atan(raw_pos_tan)
    raw_sita_Euler = raw_sita * 180/ math.pi
    raw_pos_relative_point = new_features['raw_pos_relative_point']
    raw_sita_Euler = tf.Print(raw_sita_Euler, [raw_pos_relative_point], 'reshape_raw_pos_relative_point_original0=',summarize=1000)
    raw_pos_relative_point = tf.reshape(raw_pos_relative_point, [-1, 8])
    raw_num_pos_grasp = new_features['raw_num_pos_grasp']

    raw_sita_Euler = tf.Print(raw_sita_Euler, [raw_pos_relative_point], 'reshape_raw_pos_relative_point_original=',summarize=1000)
    raw_sita_Euler = tf.Print(raw_sita_Euler, [raw_sita_Euler], 'raw_sita_Euler_origina;=', summarize=1000)

    index = tf.constant(0,dtype=tf.int64)
    new_raw_sita_Euler = tf.reshape(tf.constant([], dtype=tf.float32), [-1])
    new_raw_pos_relative_point = tf.reshape(tf.constant([], dtype=tf.float32), [-1,8])
    all_step = raw_num_pos_grasp#[0]
    # all_step = tf.constant(10, dtype=tf.int64)
    def condition(index, all_step, raw_sita_Euler, raw_pos_relative_point, new_raw_sita_Euler, new_raw_pos_relative_point):
        return tf.less(index, all_step)
    def body(index, all_step, raw_sita_Euler, raw_pos_relative_point, new_raw_sita_Euler, new_raw_pos_relative_point):
        # new_raw_sita_Euler = tf.concat([new_raw_sita_Euler,raw_sita_Euler[index]],axis=0)
        raw_sita_Euler_one = tf.expand_dims(raw_sita_Euler[index],axis=0)
        raw_pos_relative_point_one = tf.expand_dims(raw_pos_relative_point[index],axis=0)
        new_raw_sita_Euler = tf.concat([new_raw_sita_Euler,raw_sita_Euler_one],axis=0)
        new_raw_pos_relative_point = tf.concat([new_raw_pos_relative_point,raw_pos_relative_point_one],axis=0)
        return index + 1, all_step, raw_sita_Euler, raw_pos_relative_point, new_raw_sita_Euler, new_raw_pos_relative_point

    [index, all_step, raw_sita_Euler, raw_pos_relative_point, new_raw_sita_Euler, new_raw_pos_relative_point] = tf.while_loop(condition, body,
                            [index, all_step, raw_sita_Euler, raw_pos_relative_point, new_raw_sita_Euler, new_raw_pos_relative_point],
                            shape_invariants=[index.get_shape(), all_step.get_shape(),raw_sita_Euler.get_shape(),raw_pos_relative_point.get_shape(),
                                              tf.TensorShape([None]), tf.TensorShape([None, 8])])
    return new_raw_sita_Euler,new_raw_pos_relative_point

 

你可能感兴趣的:(tensorflow)