code: def input_tensors_to_model_input(
      input_tensors,
      hparams,
      is_training,
      num_classes=constants.MIDI_PITCHES,
  ):
      """Processes an InputTensor into FeatureTensors and LabelTensors."""
      length = tf.cast(input_tensors.length, tf.int32)
      labels = tf.reshape(input_tensors.labels, (-1, num_classes))
      label_weights = tf.reshape(
          input_tensors.label_weights, (-1, num_classes)
      )
      onsets = tf.reshape(input_tensors.onsets, (-1, num_classes))
      offsets = tf.reshape(input_tensors.offsets, (-1, num_classes))
      velocities = tf.reshape(
          input_tensors.velocities, (-1, num_classes)
      )
      spec = tf.reshape(
          input_tensors.spec, (-1, hparams_frame_size(hparams))
      )
  
      # Slice specs and labels tensors so they are no longer than truncated_length.
      hparams_truncated_length = tf.cast(
          hparams.truncated_length_secs
          * hparams_frames_per_second(hparams),
          tf.int32,
      )
      if hparams.truncated_length_secs:
          truncated_length = tf.reduce_min(
              [hparams_truncated_length, length]
          )
      else:
          truncated_length = length
  
      if is_training:
          truncated_note_sequence = tf.constant(0)
      else:
          truncated_note_sequence = truncate_note_sequence_op(
              input_tensors.note_sequence, truncated_length, hparams
          )
  
      # If max_expected_train_example_len is set, ensure that all examples are
      # padded to this length. This results in a fixed shape that can work on TPUs.
      if hparams.max_expected_train_example_len and is_training:
          # In this case, final_length is a constant.
          if hparams.truncated_length_secs:
              assert_op = tf.assert_equal(
                  hparams.max_expected_train_example_len,
                  hparams_truncated_length,
              )
              with tf.control_dependencies([assert_op]):
                  final_length = hparams.max_expected_train_example_len
          else:
              final_length = hparams.max_expected_train_example_len
      else:
          # In this case, it is min(hparams.truncated_length, length)
          final_length = truncated_length
  
      spec_delta = tf.shape(spec)[0] - final_length
      spec = tf.case(
          [
              (
                  spec_delta < 0,
                  lambda: tf.pad(
                      spec, tf.stack([(0, -spec_delta), (0, 0)])
                  ),
              ),
              (spec_delta > 0, lambda: spec[0:-spec_delta]),
          ],
          default=lambda: spec,
      )
      labels_delta = tf.shape(labels)[0] - final_length
      labels = tf.case(
          [
              (
                  labels_delta < 0,
                  lambda: tf.pad(
                      labels, tf.stack([(0, -labels_delta), (0, 0)])
                  ),
              ),
              (labels_delta > 0, lambda: labels[0:-labels_delta]),
          ],
          default=lambda: labels,
      )
      label_weights = tf.case(
          [
              (
                  labels_delta < 0,
                  lambda: tf.pad(
                      label_weights,
                      tf.stack([(0, -labels_delta), (0, 0)]),
                  ),
              ),
              (
                  labels_delta > 0,
                  lambda: label_weights[0:-labels_delta],
              ),
          ],
          default=lambda: label_weights,
      )
      onsets = tf.case(
          [
              (
                  labels_delta < 0,
                  lambda: tf.pad(
                      onsets, tf.stack([(0, -labels_delta), (0, 0)])
                  ),
              ),
              (labels_delta > 0, lambda: onsets[0:-labels_delta]),
          ],
          default=lambda: onsets,
      )
      offsets = tf.case(
          [
              (
                  labels_delta < 0,
                  lambda: tf.pad(
                      offsets, tf.stack([(0, -labels_delta), (0, 0)])
                  ),
              ),
              (labels_delta > 0, lambda: offsets[0:-labels_delta]),
          ],
          default=lambda: offsets,
      )
      velocities = tf.case(
          [
              (
                  labels_delta < 0,
                  lambda: tf.pad(
                      velocities, tf.stack([(0, -labels_delta), (0, 0)])
                  ),
              ),
              (labels_delta > 0, lambda: velocities[0:-labels_delta]),
          ],
          default=lambda: velocities,
      )
  
      features = FeatureTensors(
          spec=tf.reshape(
              spec, (final_length, hparams_frame_size(hparams), 1)
          ),
          length=truncated_length,
          sequence_id=tf.constant(0)
          if is_training
          else input_tensors.sequence_id,
      )
      labels = LabelTensors(
          labels=tf.reshape(labels, (final_length, num_classes)),
          label_weights=tf.reshape(
              label_weights, (final_length, num_classes)
          ),
          onsets=tf.reshape(onsets, (final_length, num_classes)),
          offsets=tf.reshape(offsets, (final_length, num_classes)),
          velocities=tf.reshape(
              velocities, (final_length, num_classes)
          ),
          note_sequence=truncated_note_sequence,
      )
  
      if hparams.drum_data_map:
          labels_dict = labels._asdict()
          for k in ("labels", "onsets", "offsets"):
              labels_dict[k] = drum_mappings.map_pianoroll(
                  labels_dict[k],
                  mapping_name=hparams.drum_data_map,
                  reduce_mode="any",
                  min_pitch=constants.MIN_MIDI_PITCH,
              )
          for k in ("label_weights", "velocities"):
              labels_dict[k] = drum_mappings.map_pianoroll(
                  labels_dict[k],
                  mapping_name=hparams.drum_data_map,
                  reduce_mode="max",
                  min_pitch=constants.MIN_MIDI_PITCH,
              )
          if labels_dict["note_sequence"].dtype == tf.string:
              labels_dict["note_sequence"] = tf.py_func(
                  functools.partial(
                      drum_mappings.map_sequences,
                      mapping_name=hparams.drum_data_map,
                  ),
                  [labels_dict["note_sequence"]],
                  tf.string,
                  name="get_drum_sequences",
                  stateful=False,
              )
              labels_dict["note_sequence"].set_shape(())
          labels = LabelTensors(**labels_dict)
  
      return features, labels
  
imports: import collections
  import functools
  import io
  import re
  import wave
  import zlib
  import librosa
  from magenta.models.onsets_frames_transcription import audio_transform
  from magenta.models.onsets_frames_transcription import constants
  from magenta.models.onsets_frames_transcription import drum_mappings
  from magenta.models.onsets_frames_transcription import melspec_input
  from note_seq import audio_io
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 21 for calling a global function with example usage: input_tensors_to_model_input(input_tensors, hparams, is_training, num_classes) and returns: features,  labels