Tensorflow - 统计batch中数据的长度.

就是记录一下,这个用于统计batch中数据的长度,用于RNN或者LSTM的输入,由于使用了0进行数据填充,因此统计实际数据长度,输入到RNN的length中,其中输入为一个batch,输出为(batch_size,)为一个batch中所有数据的长度。

def compute_mask(batch_index):
    c_mask = tf.cast(batch_index, tf.bool)
    index_len = tf.reshape(tf.reduce_sum(tf.cast(c_mask, tf.int32), axis=-1),[-1])
    return index_len

猜你喜欢

转载自blog.csdn.net/maka_uir/article/details/85061317
今日推荐