(spec, length, hparams, is_training)
return frame_logits, onset_logits, offset_logits, velocity_values
Builds a raw, API-independent onsets & frames.
Builds a raw, API-independent onsets & frames.
Builds a raw API - independent onsets & frames .
def build_model(spec, length, hparams, is_training):
  """Builds a raw, API-independent onsets & frames."""

  if hparams.stop_activation_gradient and not hparams.activation_loss:
    raise ValueError(
        'If stop_activation_gradient is true, activation_loss must be true.')

  with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training):
    with tf.variable_scope('onsets'):
      onset_outputs = acoustic_model(
          spec,
          hparams,
          lstm_units=hparams.onset_lstm_units,
          lengths=length,
          is_training=is_training)
      onset_logits = slim.fully_connected(
          onset_outputs,
          constants.MIDI_PITCHES,
          activation_fn=None,
          scope='onset_logits')

    offset_logits = []
    if hparams.offset_network:
      with tf.variable_scope('offsets'):
        offset_outputs = acoustic_model(
            spec,
            hparams,
            lstm_units=hparams.offset_lstm_units,
            lengths=length,
            is_training=is_training)
        offset_logits = slim.fully_connected(
            offset_outputs,
            constants.MIDI_PITCHES,
            activation_fn=None,
            scope='offset_logits')

    with tf.variable_scope('velocity'):
      velocity_outputs = acoustic_model(
          spec,
          hparams,
          lstm_units=hparams.velocity_lstm_units,
          lengths=length,
          is_training=is_training)
      velocity_values = slim.fully_connected(
          velocity_outputs,
          constants.MIDI_PITCHES,
          activation_fn=None,
          scope='onset_velocities')

    with tf.variable_scope('frame'):
      if not hparams.share_conv_features:
        # TODO(eriche): this is broken when hparams.frame_lstm_units > 0
        activation_outputs = acoustic_model(
            spec,
            hparams,
            lstm_units=hparams.frame_lstm_units,
            lengths=length,
            is_training=is_training)
        activation_logits = slim.fully_connected(
            activation_outputs,
            constants.MIDI_PITCHES,
            activation_fn=None,
            scope='activation_logits')
      else:
        activation_logits = slim.fully_connected(
            onset_outputs,
            constants.MIDI_PITCHES,
            activation_fn=None,
            scope='activation_logits')

      logits = []
      if hparams.stop_onset_gradient:
        logits.append(tf.stop_gradient(onset_logits))
      else:
        logits.append(onset_logits)

      if hparams.stop_activation_gradient:
        logits.append(tf.stop_gradient(activation_logits))
      else:
        logits.append(activation_logits)

      if hparams.offset_network:
        if hparams.stop_offset_gradient:
          logits.append(tf.stop_gradient(offset_logits))
        else:
          logits.append(offset_logits)

      combined_logits = tf.concat(logits, 2)

      if hparams.combined_lstm_units > 0:
        if hparams.use_tflite_compatible:
          lstm_layer_builder = lstm_layer_static_for_tflite
        else:
          lstm_layer_builder = lstm_layer

        outputs = lstm_layer_builder(
            tf.sigmoid(combined_logits),
            hparams.combined_lstm_units,
            hparams.bidirectional,
            is_training=is_training,
            lengths=length if hparams.use_lengths else None,
            stack_size=hparams.combined_rnn_stack_size,
            dropout_keep_prob=hparams.combined_rnn_dropout_keep_prob)
      else:
        outputs = combined_logits

      frame_logits = slim.fully_connected(
          outputs,
          constants.MIDI_PITCHES,
          activation_fn=None,
          scope='frame_logits')

  return frame_logits, onset_logits, offset_logits, velocity_values
def build_model ( spec , length , hparams , is_training ) : if hparams . stop_activation_gradient and not hparams . activation_loss : raise ValueError ( 'If stop_activation_gradient is true, activation_loss must be true.' ) with slim . arg_scope ( [ slim . batch_norm , slim . dropout ] , is_training = is_training ) : with tf . variable_scope ( 'onsets' ) : onset_outputs = acoustic_model ( spec , hparams , lstm_units = hparams . onset_lstm_units , lengths = length , is_training = is_training ) onset_logits = slim . fully_connected ( onset_outputs , constants . MIDI_PITCHES , activation_fn = None , scope = 'onset_logits' ) offset_logits = [ ] if hparams . offset_network : with tf . variable_scope ( 'offsets' ) : offset_outputs = acoustic_model ( spec , hparams , lstm_units = hparams . offset_lstm_units , lengths = length , is_training = is_training ) offset_logits = slim . fully_connected ( offset_outputs , constants . MIDI_PITCHES , activation_fn = None , scope = 'offset_logits' ) with tf . variable_scope ( 'velocity' ) : velocity_outputs = acoustic_model ( spec , hparams , lstm_units = hparams . velocity_lstm_units , lengths = length , is_training = is_training ) velocity_values = slim . fully_connected ( velocity_outputs , constants . MIDI_PITCHES , activation_fn = None , scope = 'onset_velocities' ) with tf . variable_scope ( 'frame' ) : if not hparams . share_conv_features : # TODO(eriche): this is broken when hparams.frame_lstm_units > 0 activation_outputs = acoustic_model ( spec , hparams , lstm_units = hparams . frame_lstm_units , lengths = length , is_training = is_training ) activation_logits = slim . fully_connected ( activation_outputs , constants . MIDI_PITCHES , activation_fn = None , scope = 'activation_logits' ) else : activation_logits = slim . fully_connected ( onset_outputs , constants . MIDI_PITCHES , activation_fn = None , scope = 'activation_logits' ) logits = [ ] if hparams . stop_onset_gradient : logits . append ( tf . stop_gradient ( onset_logits ) ) else : logits . append ( onset_logits ) if hparams . stop_activation_gradient : logits . append ( tf . stop_gradient ( activation_logits ) ) else : logits . append ( activation_logits ) if hparams . offset_network : if hparams . stop_offset_gradient : logits . append ( tf . stop_gradient ( offset_logits ) ) else : logits . append ( offset_logits ) combined_logits = tf . concat ( logits , 2 ) if hparams . combined_lstm_units > 0 : if hparams . use_tflite_compatible : lstm_layer_builder = lstm_layer_static_for_tflite else : lstm_layer_builder = lstm_layer outputs = lstm_layer_builder ( tf . sigmoid ( combined_logits ) , hparams . combined_lstm_units , hparams . bidirectional , is_training = is_training , lengths = length if hparams . use_lengths else None , stack_size = hparams . combined_rnn_stack_size , dropout_keep_prob = hparams . combined_rnn_dropout_keep_prob ) else : outputs = combined_logits frame_logits = slim . fully_connected ( outputs , constants . MIDI_PITCHES , activation_fn = None , scope = 'frame_logits' ) return frame_logits , onset_logits , offset_logits , velocity_values