code: def extract_polyphonic_sequences(
      quantized_sequence,
      start_step=0,
      min_steps_discard=None,
      max_steps_discard=None,
  ):
      """Extracts a polyphonic track from the given quantized NoteSequence.
  
      Currently, this extracts only one polyphonic sequence from a given track.
  
      Args:
        quantized_sequence: A quantized NoteSequence.
        start_step: Start extracting a sequence at this time step. Assumed
            to be the beginning of a bar.
        min_steps_discard: Minimum length of tracks in steps. Shorter tracks are
            discarded.
        max_steps_discard: Maximum length of tracks in steps. Longer tracks are
            discarded.
  
      Returns:
        poly_seqs: A python list of PolyphonicSequence instances.
        stats: A dictionary mapping string names to `statistics.Statistic` objects.
      """
      sequences_lib.assert_is_relative_quantized_sequence(
          quantized_sequence
      )
  
      stats = dict(
          (stat_name, statistics.Counter(stat_name))
          for stat_name in [
              "polyphonic_tracks_discarded_too_short",
              "polyphonic_tracks_discarded_too_long",
              "polyphonic_tracks_discarded_more_than_1_program",
          ]
      )
  
      steps_per_bar = sequences_lib.steps_per_bar_in_quantized_sequence(
          quantized_sequence
      )
  
      # Create a histogram measuring lengths (in bars not steps).
      stats["polyphonic_track_lengths_in_bars"] = statistics.Histogram(
          "polyphonic_track_lengths_in_bars",
          [0, 1, 10, 20, 30, 40, 50, 100, 200, 500, 1000],
      )
  
      # Allow only 1 program.
      programs = set()
      for note in quantized_sequence.notes:
          programs.add(note.program)
      if len(programs) > 1:
          stats[
              "polyphonic_tracks_discarded_more_than_1_program"
          ].increment()
          return [], stats.values()
  
      # Translate the quantized sequence into a PolyphonicSequence.
      poly_seq = PolyphonicSequence(
          quantized_sequence, start_step=start_step
      )
  
      poly_seqs = []
      num_steps = poly_seq.num_steps
  
      if (
          min_steps_discard is not None
          and num_steps < min_steps_discard
      ):
          stats["polyphonic_tracks_discarded_too_short"].increment()
      elif (
          max_steps_discard is not None
          and num_steps > max_steps_discard
      ):
          stats["polyphonic_tracks_discarded_too_long"].increment()
      else:
          poly_seqs.append(poly_seq)
          stats["polyphonic_track_lengths_in_bars"].increment(
              num_steps // steps_per_bar
          )
  
      return poly_seqs, stats.values()
  
imports: from __future__ import division
  import collections
  import copy
  from magenta.pipelines import statistics
  from note_seq import constants
  from note_seq import events_lib
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  from six.moves import range
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: extract_polyphonic_sequences(quantized_sequence, start_step, min_steps_discard, max_steps_discard) and returns: poly_seqs,  stats, list,  stats