Example #1
0
def yamnet_frames_model(feature_params):
    """Defines the YAMNet waveform-to-class-scores model.

  Args:
    feature_params: An object with parameter fields to control the feature
    calculation.

  Returns:
    A model accepting (1, num_samples) waveform input and emitting a
    (num_patches, num_classes) matrix of class scores per time frame as
    well as a (num_spectrogram_frames, num_mel_bins) spectrogram feature
    matrix.
  """
    print('building frames model')
    waveform = layers.Input(batch_shape=(1, None))
    print('waveform input done')
    # Store the intermediate spectrogram features to use in visualization.
    spectrogram = features_lib.waveform_to_log_mel_spectrogram(
        tf.squeeze(waveform, axis=0), feature_params)
    print('spectrogram output done')
    patches = features_lib.spectrogram_to_patches(spectrogram, feature_params)
    predictions = yamnet(patches)
    print('prediction output done')
    frames_model = Model(name='yamnet_frames',
                         inputs=waveform,
                         outputs=[predictions, spectrogram])
    print('model done')
    return frames_model
def yamnet_frames_model(feature_params, fine_tuning=True):
    """Defines the YAMNet waveform-to-class-scores model.

  Args:
    feature_params: An object with parameter fields to control the feature
    calculation.

  Returns:
    A model accepting (1, num_samples) waveform input and emitting a
    (num_patches, num_classes) matrix of class scores per time frame as
    well as a (num_spectrogram_frames, num_mel_bins) spectrogram feature
    matrix.
  """
    waveform = layers.Input(batch_shape=(None, None))
    # Store the intermediate spectrogram features to use in visualization.
    spectrogram = features_lib.waveform_to_log_mel_spectrogram(
        tf.squeeze(waveform, axis=0), feature_params)
    patches = features_lib.spectrogram_to_patches(spectrogram, feature_params)
    predictions = yamnet(patches, fine_tuning)
    if (not fine_tuning):
        frames_model = Model(name='yamnet_frames',
                             inputs=waveform,
                             outputs=[predictions, spectrogram])
    else:
        output = layers.Dense(100, activation='relu')(predictions)
        output = layers.Dense(4, activation='softmax')(output)

        frames_model = Model(name='yamnet_frames',
                             inputs=waveform,
                             outputs=[output, spectrogram])
    return frames_model
def yamnet_frames_tflite_model(feature_params):
    """Defines the YAMNet waveform-to-class-scores model,
    suitable for tflite conversion.

    Args:
      feature_params: An object with parameter fields to control the feature
      calculation.

    Returns:
      A model accepting (1, num_samples) waveform input and emitting a
      (num_patches, num_classes) matrix of class scores per time frame as
      well as a (num_spectrogram_frames, num_mel_bins) spectrogram feature
      matrix.
    """
    num_samples = int(round(params.SAMPLE_RATE * 0.975))
    waveform = layers.Input(batch_shape=(1, num_samples))
    # Store the intermediate spectrogram features to use in visualization.
    spectrogram = features_tflite_lib.waveform_to_log_mel_spectrogram(
        tf.squeeze(waveform, axis=0), feature_params)
    patches = features_lib.spectrogram_to_patches(spectrogram, feature_params)
    predictions = yamnet(patches)
    frames_model = Model(name='yamnet_frames',
                         inputs=waveform,
                         outputs=[predictions, spectrogram])
    return frames_model
Example #4
0
def yamnet_frames_tflite_model(feature_params):
    num_samples = int(round(params.SAMPLE_RATE * 0.975))
    waveform = layers.Input(batch_shape=(1, num_samples))
    # Store the intermediate spectrogram features to use in visualization.
    spectrogram = features_lib.waveform_to_log_mel_spectrogram(
        tf.squeeze(waveform, axis=0), feature_params)
    patches = features_lib.spectrogram_to_patches(spectrogram, feature_params)
    predictions = yamnet(patches)
    frames_model = Model(name='yamnet_frames',
                         inputs=waveform,
                         outputs=[predictions, spectrogram])
    return frames_model