(sequence_tensor, velocity_range_tensor, hparams)
return res, weighted_res, onsets, offsets, velocities
Transforms a serialized NoteSequence to a pianoroll.
Transforms a serialized NoteSequence to a pianoroll.
Transforms a serialized NoteSequence to a pianoroll .
def sequence_to_pianoroll_op(sequence_tensor, velocity_range_tensor, hparams):
  """Transforms a serialized NoteSequence to a pianoroll."""

  def sequence_to_pianoroll_fn(sequence_tensor, velocity_range_tensor):
    """Converts sequence to pianorolls."""
    velocity_range = music_pb2.VelocityRange.FromString(velocity_range_tensor)
    sequence = music_pb2.NoteSequence.FromString(sequence_tensor)
    sequence = sequences_lib.apply_sustain_control_changes(sequence)
    roll = sequences_lib.sequence_to_pianoroll(
        sequence,
        frames_per_second=hparams_frames_per_second(hparams),
        min_pitch=constants.MIN_MIDI_PITCH,
        max_pitch=constants.MAX_MIDI_PITCH,
        min_frame_occupancy_for_label=hparams.min_frame_occupancy_for_label,
        onset_mode=hparams.onset_mode,
        onset_length_ms=hparams.onset_length,
        offset_length_ms=hparams.offset_length,
        onset_delay_ms=hparams.onset_delay,
        min_velocity=velocity_range.min,
        max_velocity=velocity_range.max)
    return (roll.active, roll.weights, roll.onsets, roll.onset_velocities,
            roll.offsets)

  res, weighted_res, onsets, velocities, offsets = tf.py_func(
      sequence_to_pianoroll_fn, [sequence_tensor, velocity_range_tensor],
      [tf.float32, tf.float32, tf.float32, tf.float32, tf.float32],
      name='sequence_to_pianoroll_op')
  res.set_shape([None, constants.MIDI_PITCHES])
  weighted_res.set_shape([None, constants.MIDI_PITCHES])
  onsets.set_shape([None, constants.MIDI_PITCHES])
  offsets.set_shape([None, constants.MIDI_PITCHES])
  velocities.set_shape([None, constants.MIDI_PITCHES])

  return res, weighted_res, onsets, offsets, velocities
def sequence_to_pianoroll_op ( sequence_tensor , velocity_range_tensor , hparams ) : def sequence_to_pianoroll_fn ( sequence_tensor , velocity_range_tensor ) : """Converts sequence to pianorolls.""" velocity_range = music_pb2 . VelocityRange . FromString ( velocity_range_tensor ) sequence = music_pb2 . NoteSequence . FromString ( sequence_tensor ) sequence = sequences_lib . apply_sustain_control_changes ( sequence ) roll = sequences_lib . sequence_to_pianoroll ( sequence , frames_per_second = hparams_frames_per_second ( hparams ) , min_pitch = constants . MIN_MIDI_PITCH , max_pitch = constants . MAX_MIDI_PITCH , min_frame_occupancy_for_label = hparams . min_frame_occupancy_for_label , onset_mode = hparams . onset_mode , onset_length_ms = hparams . onset_length , offset_length_ms = hparams . offset_length , onset_delay_ms = hparams . onset_delay , min_velocity = velocity_range . min , max_velocity = velocity_range . max ) return ( roll . active , roll . weights , roll . onsets , roll . onset_velocities , roll . offsets ) res , weighted_res , onsets , velocities , offsets = tf . py_func ( sequence_to_pianoroll_fn , [ sequence_tensor , velocity_range_tensor ] , [ tf . float32 , tf . float32 , tf . float32 , tf . float32 , tf . float32 ] , name = 'sequence_to_pianoroll_op' ) res . set_shape ( [ None , constants . MIDI_PITCHES ] ) weighted_res . set_shape ( [ None , constants . MIDI_PITCHES ] ) onsets . set_shape ( [ None , constants . MIDI_PITCHES ] ) offsets . set_shape ( [ None , constants . MIDI_PITCHES ] ) velocities . set_shape ( [ None , constants . MIDI_PITCHES ] ) return res , weighted_res , onsets , offsets , velocities