(self, note_sequence)
return ConverterTensors(inputs=input_seqs, outputs=output_seqs)
Converts NoteSequence to unique sequences.
Converts NoteSequence to unique sequences.
Converts NoteSequence to unique sequences .
def _to_tensors_fn(self, note_sequence):
    """Converts NoteSequence to unique sequences."""
    try:
      quantized_sequence = note_seq.quantize_note_sequence(
          note_sequence, self._steps_per_quarter)
      if (note_seq.steps_per_bar_in_quantized_sequence(quantized_sequence) !=
          self._steps_per_bar):
        return ConverterTensors()
    except (note_seq.BadTimeSignatureError, note_seq.NonIntegerStepsPerBarError,
            note_seq.NegativeTimeError) as e:
      return ConverterTensors()

    new_notes = []
    for n in quantized_sequence.notes:
      if not n.is_drum:
        continue
      if n.pitch not in self._pitch_class_map:
        continue
      n.pitch = self._pitch_class_map[n.pitch]
      new_notes.append(n)
    del quantized_sequence.notes[:]
    quantized_sequence.notes.extend(new_notes)

    event_lists, unused_stats = self._drums_extractor_fn(quantized_sequence)

    if self._pad_to_total_time:
      for e in event_lists:
        e.set_length(len(e) + e.start_step, from_left=True)
        e.set_length(quantized_sequence.total_quantized_steps)
    if self._slice_steps:
      sliced_event_tuples = []
      for l in event_lists:
        for i in range(self._slice_steps, len(l) + 1, self._steps_per_bar):
          sliced_event_tuples.append(tuple(l[i - self._slice_steps: i]))
    else:
      sliced_event_tuples = [tuple(l) for l in event_lists]

    unique_event_tuples = list(set(sliced_event_tuples))
    unique_event_tuples = maybe_sample_items(unique_event_tuples,
                                             self.max_tensors_per_notesequence,
                                             self.is_training)

    rolls = []
    oh_vecs = []
    for t in unique_event_tuples:
      if self._roll_input or self._roll_output:
        if self.end_token is not None:
          t_roll = list(t) + [(self._pr_encoder_decoder.input_size - 1,)]
        else:
          t_roll = t
        rolls.append(np.vstack([
            self._pr_encoder_decoder.events_to_input(t_roll, i).astype(np.bool)
            for i in range(len(t_roll))]))
      if not (self._roll_input and self._roll_output):
        labels = [self._oh_encoder_decoder.encode_event(e) for e in t]
        if self.end_token is not None:
          labels += [self._oh_encoder_decoder.num_classes]
        oh_vecs.append(np_onehot(
            labels,
            self._oh_encoder_decoder.num_classes + (self.end_token is not None),
            np.bool))

    if self._roll_input:
      input_seqs = [
          np.append(roll, np.expand_dims(np.all(roll == 0, axis=1), axis=1),
                    axis=1) for roll in rolls]
    else:
      input_seqs = oh_vecs

    output_seqs = rolls if self._roll_output else oh_vecs

    return ConverterTensors(inputs=input_seqs, outputs=output_seqs)
def _to_tensors_fn ( self , note_sequence ) : try : quantized_sequence = note_seq . quantize_note_sequence ( note_sequence , self . _steps_per_quarter ) if ( note_seq . steps_per_bar_in_quantized_sequence ( quantized_sequence ) != self . _steps_per_bar ) : return ConverterTensors ( ) except ( note_seq . BadTimeSignatureError , note_seq . NonIntegerStepsPerBarError , note_seq . NegativeTimeError ) as e : return ConverterTensors ( ) new_notes = [ ] for n in quantized_sequence . notes : if not n . is_drum : continue if n . pitch not in self . _pitch_class_map : continue n . pitch = self . _pitch_class_map [ n . pitch ] new_notes . append ( n ) del quantized_sequence . notes [ : ] quantized_sequence . notes . extend ( new_notes ) event_lists , unused_stats = self . _drums_extractor_fn ( quantized_sequence ) if self . _pad_to_total_time : for e in event_lists : e . set_length ( len ( e ) + e . start_step , from_left = True ) e . set_length ( quantized_sequence . total_quantized_steps ) if self . _slice_steps : sliced_event_tuples = [ ] for l in event_lists : for i in range ( self . _slice_steps , len ( l ) + 1 , self . _steps_per_bar ) : sliced_event_tuples . append ( tuple ( l [ i - self . _slice_steps : i ] ) ) else : sliced_event_tuples = [ tuple ( l ) for l in event_lists ] unique_event_tuples = list ( set ( sliced_event_tuples ) ) unique_event_tuples = maybe_sample_items ( unique_event_tuples , self . max_tensors_per_notesequence , self . is_training ) rolls = [ ] oh_vecs = [ ] for t in unique_event_tuples : if self . _roll_input or self . _roll_output : if self . end_token is not None : t_roll = list ( t ) + [ ( self . _pr_encoder_decoder . input_size - 1 , ) ] else : t_roll = t rolls . append ( np . vstack ( [ self . _pr_encoder_decoder . events_to_input ( t_roll , i ) . astype ( np . bool ) for i in range ( len ( t_roll ) ) ] ) ) if not ( self . _roll_input and self . _roll_output ) : labels = [ self . _oh_encoder_decoder . encode_event ( e ) for e in t ] if self . end_token is not None : labels += [ self . _oh_encoder_decoder . num_classes ] oh_vecs . append ( np_onehot ( labels , self . _oh_encoder_decoder . num_classes + ( self . end_token is not None ) , np . bool ) ) if self . _roll_input : input_seqs = [ np . append ( roll , np . expand_dims ( np . all ( roll == 0 , axis = 1 ) , axis = 1 ) , axis = 1 ) for roll in rolls ] else : input_seqs = oh_vecs output_seqs = rolls if self . _roll_output else oh_vecs return ConverterTensors ( inputs = input_seqs , outputs = output_seqs )