code: def midi_summary(controls, step, name, frame_rate, notes_key):
      """Plots segmented midi with controls."""
      batch_size = controls["f0_hz"].shape[0]
      for i in range(batch_size):
          amps = controls["harmonic"]["controls"]["amplitudes"][i]
          f0_hz = ddsp.core.hz_to_midi(controls["f0_hz"][i])
  
          fig, ax = plt.subplots(2, 1, figsize=(6.0, 4.0))
          ax[0].semilogy(amps, label="controls")
          ax[0].set_title("Amps")
          ax[1].plot(f0_hz, label="controls")
          ax[1].set_title("f0")
  
          notes_f0 = np.zeros_like(f0_hz)
          notes_amps = np.zeros_like(amps)
          markers = []
  
          note_sequence = controls[notes_key][i]
          for note in note_sequence.notes:
              start_time = int(note.start_time * frame_rate)
              end_time = int(note.end_time * frame_rate)
              notes_f0[start_time:end_time] = note.pitch
              notes_amps[start_time:end_time] = note.velocity / 1e3
              markers.append(start_time)
  
          ax[0].plot(notes_amps, "-d", label="notes", markevery=markers)
          ax[0].legend()
          ax[1].plot(notes_f0, "-d", label="notes", markevery=markers)
          ax[1].legend()
  
          fig_summary(f"midi/{name}_{i + 1}", fig, step)
  
imports: import io
  import ddsp
  from ddsp.core import tf_float32
  from ddsp.training.plotting import pianoroll_plot_setup
  import matplotlib.patches
  import matplotlib.pyplot
  from matplotlib.ticker import MaxNLocator
  import note_seq
  from note_seq import sequences_lib
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 8 for calling a global function with example usage: midi_summary(controls, step, name, frame_rate, notes_key) without return types