Repository: tensorflow/models
File: research/audioset/vggish/vggish_slim.py (Python)

Code before:
# ==============================================================================

"""Defines the 'VGGish' model used to generate AudioSet embedding features.

The public AudioSet release (https://research.google.com/audioset/download.html)
includes 128-D features extracted from the embedding layer of a VGG-like model
that was trained on a large Google-internal YouTube dataset. Here we provide
a TF-Slim definition of the same model, without any dependences on libraries
internal to Google. We call it 'VGGish'.

Note that we only define the model up to the embedding layer, which is the
penultimate layer before the final classifier layer. We also provide various
hyperparameter values (in vggish_params.py) that were used to train this model
internally.

For comparison, here is TF-Slim's VGG definition:
https://github.com/tensorflow/models/blob/master/research/slim/nets/vgg.py
"""

import tensorflow.compat.v1 as tf
import tf_slim as slim

import vggish_params as params


def define_vggish_slim(features=None, training=False):
  """Defines the VGGish TensorFlow model.

  All ops are created in the current default graph, under the scope 'vggish/'.

  The input is either a tensor passed in via the optional 'features' argument or
  a placeholder created below named 'vggish/input_features'. The input is
  expected to have dtype float32 and shape [batch_size, num_frames, num_bands]
  where batch_size is variable and num_frames and num_bands are constants, and
  [num_frames, num_bands] represents a log-mel-scale spectrogram patch covering
  num_bands frequency bands and num_frames time frames (where each frame step is
  usually 10ms). This is produced by computing the stabilized
  log(mel-spectrogram + params.LOG_OFFSET).  The output is a tensor  named
  'vggish/embedding' which produces the activations of a 128-D embedding layer,
  which is usually the penultimate layer when used as part of a full model with
  a final classifier layer.

  Args:
    features: If not None, the tensor containing the input features. If None,
      a placeholder input is created.
    training: If true, all parameters are marked trainable.

  Returns:
    The op 'vggish/embeddings'.
  """
  # Defaults:

Review comment (suggestion):
When I read this, I assumed it was a way to pass in actual values.  You could call it features_tensor.  In the context of the original function, it was obviously a tensor, but promoted to visibility outside the function, it's more ambiguous.

Code after:
# ==============================================================================

"""Defines the 'VGGish' model used to generate AudioSet embedding features.

The public AudioSet release (https://research.google.com/audioset/download.html)
includes 128-D features extracted from the embedding layer of a VGG-like model
that was trained on a large Google-internal YouTube dataset. Here we provide
a TF-Slim definition of the same model, without any dependences on libraries
internal to Google. We call it 'VGGish'.

Note that we only define the model up to the embedding layer, which is the
penultimate layer before the final classifier layer. We also provide various
hyperparameter values (in vggish_params.py) that were used to train this model
internally.

For comparison, here is TF-Slim's VGG definition:
https://github.com/tensorflow/models/blob/master/research/slim/nets/vgg.py
"""

import tensorflow.compat.v1 as tf
import tf_slim as slim

import vggish_params as params


def define_vggish_slim(features_tensor=None, training=False):
  """Defines the VGGish TensorFlow model.

  All ops are created in the current default graph, under the scope 'vggish/'.

  The input is either a tensor passed in via the optional 'features_tensor'
  argument or a placeholder created below named 'vggish/input_features'. The
  input is expected to have dtype float32 and shape [batch_size, num_frames,
  num_bands] where batch_size is variable and num_frames and num_bands are
  constants, and [num_frames, num_bands] represents a log-mel-scale spectrogram
  patch covering num_bands frequency bands and num_frames time frames (where
  each frame step is usually 10ms). This is produced by computing the stabilized
  log(mel-spectrogram + params.LOG_OFFSET).  The output is a tensor named
  'vggish/embedding' which produces the activations of a 128-D embedding layer,
  which is usually the penultimate layer when used as part of a full model with
  a final classifier layer.

  Args:
    features_tensor: If not None, the tensor containing the input features.
      If None, a placeholder input is created.
    training: If true, all parameters are marked trainable.

  Returns:
    The op 'vggish/embeddings'.
  """
  # Defaults: