lingvo/tasks/asr/frontend.py
def FProp(self, theta, input_batch):
    """Perform signal processing on a sequence of PCM data.

    NOTE: This implementation does not currently support paddings, and they
    are accepted for compatibility with the super-class.

    TODO(laurenzo): Rework this to support paddings.

    Args:
      theta: Layer theta.
      input_batch: PCM input map:

        - 'src_inputs': int16 or float32 tensor of PCM audio data, scaled to
          +/-32768 (versus [-1..1)!). Shaped: [batch, frame_count].
        - 'paddings': per frame 0/1 paddings. Shaped: [batch, frame].
    Returns:
      NestedMap of encoder inputs which can be passed directly to a
      compatible encoder and contains:

        - 'src_inputs': inputs to the encoder, minimally of shape
          [batch, time, ...].
        - 'paddings': a 0/1 tensor of shape [batch, time].
    """
    p = self.params
    pcm_audio_data = input_batch.src_inputs
    pcm_audio_paddings = input_batch.paddings
    batch_size = py_utils.GetShape(pcm_audio_data)[0]
    mel_spectrogram, mel_spectrogram_paddings = self._FPropChunk(
        theta, pcm_audio_data, pcm_audio_paddings)

    # Stack and sub-sample. Only subsampling with a stride of the stack size
    # is supported.
    if p.stack_left_context > 0:
      # Since left context is leading, pad the left by duplicating the first
      # frame.
      stack_size = 1 + p.stack_left_context
      mel_spectrogram = tf.concat(
          [mel_spectrogram[:, 0:1, :]] * p.stack_left_context +
          [mel_spectrogram],
          axis=1)
      mel_spectrogram_paddings = tf.concat(
          [mel_spectrogram_paddings[:, 0:1]] * p.stack_left_context +
          [mel_spectrogram_paddings],
          axis=1)

      # Note that this is the maximum number of frames. Actual frame count
      # depends on padding.
      stacked_frame_dim = tf.shape(mel_spectrogram)[1] // stack_size
      mel_spectrogram = tf.reshape(
          mel_spectrogram[:, 0:(stack_size) * stacked_frame_dim, :],
          [batch_size, stacked_frame_dim, stack_size * p.num_bins])
      # After stacking paddings, pad if any source frame was padded.
      # Staks into [batch_size, stacked_frame_dim, stack_size] like the
      # spectrogram stacking above, and then reduces the stack_size dim
      # to the max (effectively, making padding = 1.0 if any of the pre-stacked
      # frames were 1.0). Final shape is [batch_size, stacked_frame_dim].
      mel_spectrogram_paddings = tf.reshape(
          mel_spectrogram_paddings[:, 0:(stack_size) * stacked_frame_dim],
          [batch_size, stacked_frame_dim, stack_size])
      mel_spectrogram_paddings = tf.reduce_max(mel_spectrogram_paddings, axis=2)

    # Add feature dim. Shape = [batch, time, features, 1]
    mel_spectrogram = tf.expand_dims(mel_spectrogram, -1)

    return py_utils.NestedMap(
        src_inputs=mel_spectrogram, paddings=mel_spectrogram_paddings)
Perform signal processing on a sequence of PCM data.

    NOTE: This implementation does not currently support paddings, and they
    are accepted for compatibility with the super-class.

    TODO(laurenzo): Rework this to support paddings.

    Args:
      theta: Layer theta.
      input_batch: PCM input map:

        - 'src_inputs': int16 or float32 tensor of PCM audio data, scaled to
          +/-32768 (versus [-1..1)!). Shaped: [batch, frame_count].
        - 'paddings': per frame 0/1 paddings. Shaped: [batch, frame].
    Returns:
      NestedMap of encoder inputs which can be passed directly to a
      compatible encoder and contains:

        - 'src_inputs': inputs to the encoder, minimally of shape
          [batch, time, ...].
        - 'paddings': a 0/1 tensor of shape [batch, time].
    
Perform signal processing on a sequence of PCM data.
NOTE: This implementation does not currently support paddings, and they
are accepted for compatibility with the super-class.

Rework this to support paddings.
Perform signal processing on a sequence of PCM data . NOTE : This implementation does not currently support paddings and they are accepted for compatibility with the super - class . Rework this to support paddings .
def FProp(self, theta, input_batch):
    p = self.params
    pcm_audio_data = input_batch.src_inputs
    pcm_audio_paddings = input_batch.paddings
    batch_size = py_utils.GetShape(pcm_audio_data)[0]
    mel_spectrogram, mel_spectrogram_paddings = self._FPropChunk(
        theta, pcm_audio_data, pcm_audio_paddings)
    if p.stack_left_context > 0:
      stack_size = 1 + p.stack_left_context
      mel_spectrogram = tf.concat(
          [mel_spectrogram[:, 0:1, :]] * p.stack_left_context +
          [mel_spectrogram],
          axis=1)
      mel_spectrogram_paddings = tf.concat(
          [mel_spectrogram_paddings[:, 0:1]] * p.stack_left_context +
          [mel_spectrogram_paddings],
          axis=1)
      stacked_frame_dim = tf.shape(mel_spectrogram)[1] // stack_size
      mel_spectrogram = tf.reshape(
          mel_spectrogram[:, 0:(stack_size) * stacked_frame_dim, :],
          [batch_size, stacked_frame_dim, stack_size * p.num_bins])
      mel_spectrogram_paddings = tf.reshape(
          mel_spectrogram_paddings[:, 0:(stack_size) * stacked_frame_dim],
          [batch_size, stacked_frame_dim, stack_size])
      mel_spectrogram_paddings = tf.reduce_max(mel_spectrogram_paddings, axis=2)
    mel_spectrogram = tf.expand_dims(mel_spectrogram, -1)
    return py_utils.NestedMap(
        src_inputs=mel_spectrogram, paddings=mel_spectrogram_paddings)
def FProp ( self , theta , input_batch ) : p = self . params pcm_audio_data = input_batch . src_inputs pcm_audio_paddings = input_batch . paddings batch_size = py_utils . GetShape ( pcm_audio_data ) [ 0 ] mel_spectrogram , mel_spectrogram_paddings = self . _FPropChunk ( theta , pcm_audio_data , pcm_audio_paddings ) if p . stack_left_context > 0 : stack_size = 1 + p . stack_left_context mel_spectrogram = tf . concat ( [ mel_spectrogram [ : , 0 : 1 , : ] ] * p . stack_left_context + [ mel_spectrogram ] , axis = 1 ) mel_spectrogram_paddings = tf . concat ( [ mel_spectrogram_paddings [ : , 0 : 1 ] ] * p . stack_left_context + [ mel_spectrogram_paddings ] , axis = 1 ) stacked_frame_dim = tf . shape ( mel_spectrogram ) [ 1 ] // stack_size mel_spectrogram = tf . reshape ( mel_spectrogram [ : , 0 : ( stack_size ) * stacked_frame_dim , : ] , [ batch_size , stacked_frame_dim , stack_size * p . num_bins ] ) mel_spectrogram_paddings = tf . reshape ( mel_spectrogram_paddings [ : , 0 : ( stack_size ) * stacked_frame_dim ] , [ batch_size , stacked_frame_dim , stack_size ] ) mel_spectrogram_paddings = tf . reduce_max ( mel_spectrogram_paddings , axis = 2 ) mel_spectrogram = tf . expand_dims ( mel_spectrogram , - 1 ) return py_utils . NestedMap ( src_inputs = mel_spectrogram , paddings = mel_spectrogram_paddings )
Perform signal processing on a sequence of PCM data.
Perform signal processing on a sequence of PCM data .
"""Perform signal processing on a sequence of PCM data.

    NOTE: This implementation does not currently support paddings, and they
    are accepted for compatibility with the super-class.

    TODO(laurenzo): Rework this to support paddings.

    Args:
      theta: Layer theta.
      input_batch: PCM input map:

        - 'src_inputs': int16 or float32 tensor of PCM audio data, scaled to
          +/-32768 (versus [-1..1)!). Shaped: [batch, frame_count].
        - 'paddings': per frame 0/1 paddings. Shaped: [batch, frame].
    Returns:
      NestedMap of encoder inputs which can be passed directly to a
      compatible encoder and contains:

        - 'src_inputs': inputs to the encoder, minimally of shape
          [batch, time, ...].
        - 'paddings': a 0/1 tensor of shape [batch, time].
    """ # Stack and sub-sample. Only subsampling with a stride of the stack size # is supported. # Since left context is leading, pad the left by duplicating the first # frame. # Note that this is the maximum number of frames. Actual frame count # depends on padding. # After stacking paddings, pad if any source frame was padded. # Staks into [batch_size, stacked_frame_dim, stack_size] like the # spectrogram stacking above, and then reduces the stack_size dim # to the max (effectively, making padding = 1.0 if any of the pre-stacked # frames were 1.0). Final shape is [batch_size, stacked_frame_dim]. # Add feature dim. Shape = [batch, time, features, 1]
NestedMap of encoder inputs which can be passed directly to a
compatible encoder and contains.

'src_inputs': inputs to the encoder, minimally of shape
[batch, time, ...].
'paddings': a 0/1 tensor of shape [batch, time].
NestedMap of encoder inputs which can be passed directly to a compatible encoder and contains . ' src_inputs ' : inputs to the encoder minimally of shape [ batch time ... ] . ' paddings ' : a 0 / 1 tensor of shape [ batch time ] .
self
theta
None
input_batch
PCM input map:
'src_inputs': int16 or float32 tensor of PCM audio data, scaled to
+/-32768 (versus [-1..1)!). Shaped: [batch, frame_count].
'paddings': per frame 0/1 paddings. Shaped: [batch, frame].
PCM input map : ' src_inputs ' : int16 or float32 tensor of PCM audio data scaled to + / - 32768 ( versus [ - 1 .. 1 ) ! ) . Shaped : [ batch frame_count ] . ' paddings ' : per frame 0 / 1 paddings . Shaped : [ batch frame ] .