//  [python]
def feature_pick(self, encoder_hidden_states, ctc_outs, max_T=None):
        """Length regulator logic."""

        ctc_arg_out = tf.argmax(ctc_outs, -1)
        durations_gt = tf.where(ctc_arg_out != self.phone_num_classes - 1, 1, 0)
        durations_gt = tf.cast(durations_gt, tf.int32)
        sum_durations = tf.reduce_sum(durations_gt, axis=-1)  # [batch_size]
        max_durations = tf.reduce_max(sum_durations)
        if max_T is not None:
            # label_max_durations = tf.reduce_max(label_lengths)
            max_durations = tf.reduce_max([max_durations, max_T])
        # input_shape = tf.shape(encoder_hidden_states)
        batch_size = tf.shape(encoder_hidden_states)[0]
        hidden_size = tf.shape(encoder_hidden_states)[-1]
        ctc_size = tf.shape(ctc_outs)[-1]
        # initialize output hidden states and encoder masking.
        feature_outputs = tf.zeros(shape=[0, max_durations, hidden_size], dtype=tf.float32)
        ctc_outputs = tf.zeros(shape=[0, max_durations, ctc_size], dtype=tf.float32)

        def condition(i,
                      batch_size,
                      feature_outputs,
                      ctc_outputs,
                      # encoder_masks,
                      encoder_hidden_states,
                      ctc_outs,
                      durations_gt,
                      max_durations):
            return tf.less(i, batch_size)

        def body(i,
                 batch_size,
                 feature_outputs,
                 ctc_outputs,
                 # encoder_masks,
                 encoder_hidden_states,
                 ctc_outs,
                 durations_gt,
                 max_durations):
            repeats = durations_gt[i]
            real_length = tf.reduce_sum(repeats)
            pad_size = max_durations - real_length
            # masks = tf.sequence_mask([real_length], max_durations, dtype=tf.int32)
            repeat_encoder_hidden_states = tf.repeat(
                encoder_hidden_states[i],
                repeats=repeats,
                axis=0
            )
            repeat_ctc_outs = tf.repeat(
                ctc_outs[i],
                repeats=repeats,
                axis=0
            )
            repeat_encoder_hidden_states = tf.expand_dims(
                tf.pad(
                    repeat_encoder_hidden_states, [[0, pad_size], [0, 0]]
                ),
                0)  # [1, max_durations, hidden_size]
            repeat_ctc_outs = tf.expand_dims(
                tf.pad(
                    repeat_ctc_outs, [[0, pad_size], [0, 0]]
                ),
                0)  # [1, max_durations, hidden_size]
            feature_outputs = tf.concat([feature_outputs, repeat_encoder_hidden_states], axis=0)
            ctc_outputs = tf.concat([ctc_outputs, repeat_ctc_outs], axis=0)
            # encoder_masks = tf.concat([encoder_masks, masks], axis=0)
            return [i + 1, batch_size, feature_outputs, ctc_outputs,
                    encoder_hidden_states, ctc_outs, durations_gt, max_durations]

        # initialize iteration i.
        i = tf.constant(0, dtype=tf.int32)
        _, _, feature_outputs, ctc_outputs, _, _, _, _ = tf.while_loop(
            condition,
            body,
            [i, batch_size, feature_outputs, ctc_outputs, encoder_hidden_states, ctc_outs, durations_gt, max_durations],
            shape_invariants=[i.get_shape(),
                              batch_size.get_shape(),
                              tf.TensorShape([None, None, self.dmodel]),
                              tf.TensorShape([None, None, self.phone_num_classes]),
                              # tf.TensorShape([None, None]),
                              encoder_hidden_states.get_shape(),
                              ctc_outs.get_shape(),
                              durations_gt.get_shape(),
                              max_durations.get_shape()],

        )
        return feature_outputs, ctc_outputs