code: def f0_dist_conf_thresh(
      f0_hz,
      f0_hz_gen,
      f0_confidence,
      f0_confidence_thresh=MIN_F0_CONFIDENCE,
  ):
      """Compute L1 between gen audio and ground truth audio.
  
      Calculating F0 distance is more complicated than calculating loudness
      distance because of inherent inaccuracies in pitch tracking.
  
      We take the following steps:
      - Define a `keep_mask` that only select f0 values above when f0_confidence in
      the original audio exceeds a minimum threshold.
      Experimentation by jessengel@ and hanoih@ found this to be optimal way to
      filter out bad f0 pitch tracking.
      - Compute `delta_f0` between generated audio and ground truth audio.
      - Only select values in `delta_f0` based on this `keep_mask`
      - Compute mean on this selection
      - At the start of training, audio samples will sound bad and thus have no
      pitch content. If the `f0_confidence` is all below the threshold, we keep a
      count of it. A better performing model will have a smaller count of
      "untrackable pitch" samples.
  
      Args:
        f0_hz: Ground truth audio f0 in hertz [MB,:].
        f0_hz_gen: Generated audio f0 in hertz [MB,:].
        f0_confidence: Ground truth audio f0 confidence [MB,:]
        f0_confidence_thresh: Confidence threshold above which f0 metrics will be
          computed
  
      Returns:
        delta_f0_mean: Float or None if entire generated sample had
          f0_confidence below threshold. In units of MIDI (logarithmic frequency).
      """
      if len(f0_hz.shape) > 2:
          f0_hz = f0_hz[:, :, 0]
      if len(f0_hz_gen.shape) > 2:
          f0_hz_gen = f0_hz_gen[:, :, 0]
      if len(f0_confidence.shape) > 2:
          f0_confidence = f0_confidence[:, :, 0]
  
      if np.max(f0_confidence) < f0_confidence_thresh:
          # Generated audio is not good enough for reliable pitch tracking.
          return None
      else:
          keep_mask = f0_confidence >= f0_confidence_thresh
  
          # Report mean error in midi space for easier interpretation.
          f0_midi = librosa.core.hz_to_midi(f0_hz)
          f0_midi_gen = librosa.core.hz_to_midi(f0_hz_gen)
          # Set -infs introduced by hz_to_midi to 0.
          f0_midi[f0_midi == -np.inf] = 0
          f0_midi_gen[f0_midi_gen == -np.inf] = 0
  
          delta_f0_midi = l1_distance(f0_midi, f0_midi_gen)
          delta_f0_midi_filt = delta_f0_midi[keep_mask]
          return np.mean(delta_f0_midi_filt)
  
imports: import dataclasses
  from absl import logging
  import ddsp
  import librosa
  import mir_eval
  import note_seq
  from note_seq import sequences_lib
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 5 for calling a global function with example usage: f0_dist_conf_thresh(f0_hz, f0_hz_gen, f0_confidence, f0_confidence_thresh) and returns: None, np