docstr: Test F0CrepeMetrics.
  
  F0CrepeMetrics makes an expensive call to compute_f0 (which in turn calls
  CREPE) for every generated example during update_state. To avoid this, we
  mock out compute_f0 and replace the return values (via side_effect) with
  precomputed f0_hz and confidence values.
  
  Args:
    mock_compute_f0: The mock object for compute_f0, automatically injected
      by mock.patch.
docstr_tok: ["Test","F0CrepeMetrics",".","F0CrepeMetrics","makes","an","expensive","call","to","compute_f0","(","which","in","turn","calls","CREPE",")","for","every","generated","example","during","update_state",".","To","avoid","this",",","we","mock","out","compute_f0","and","replace","the","return","values","(","via","side_effect",")","with","precomputed","f0_hz","and","confidence","values",".","Args",":","mock_compute_f0",":","The","mock","object","for","compute_f0",",","automatically","injected","by","mock.patch","."]
code: def test_f0_crepe_metrics_has_expected_values(self, mock_compute_f0):
      """Test F0CrepeMetrics.
  
      F0CrepeMetrics makes an expensive call to compute_f0 (which in turn calls
      CREPE) for every generated example during update_state. To avoid this, we
      mock out compute_f0 and replace the return values (via side_effect) with
      precomputed f0_hz and confidence values.
  
      Args:
        mock_compute_f0: The mock object for compute_f0, automatically injected
          by mock.patch.
      """
      f0_crepe_metrics = ddsp_metrics.F0CrepeMetrics(
          self.sample_rate, self.frame_rate
      )
      # Batch 1: correct f0
      crepe_f0 = self.batch_of_sin_feats["f0_hz"]
      crepe_conf = np.ones_like(crepe_f0)
      mock_compute_f0.side_effect = zip(crepe_f0, crepe_conf)
      f0_crepe_metrics.update_state(
          self.batch_of_sin_feats, self.batch_of_sin
      )
      self.assertAllClose(
          f0_crepe_metrics.metrics["f0_dist"].result(), 0
      )
      self.assertAllClose(
          f0_crepe_metrics.metrics["outlier_ratio"].result(), 0
      )
  
      # Batch 2: incorrect f0
      crepe_f0 = self.batch_of_sin_feats["f0_hz"] * 2
      crepe_conf = np.ones_like(crepe_f0)
      mock_compute_f0.side_effect = zip(crepe_f0, crepe_conf)
      f0_crepe_metrics.update_state(
          self.batch_of_sin_feats, self.batch_of_sin
      )
  
      self.assertGreater(
          f0_crepe_metrics.metrics["f0_dist"].result(), 0
      )
      self.assertAllClose(
          f0_crepe_metrics.metrics["outlier_ratio"].result(), 0
      )
  
      # Batch 3: low crepe confidence
      crepe_f0 = np.zeros_like(self.batch_of_sin_feats["f0_hz"])
      crepe_conf = np.ones_like(crepe_f0)
      mock_compute_f0.side_effect = zip(crepe_f0, crepe_conf)
      f0_crepe_metrics.update_state(
          self.batch_of_sin_feats, self.batch_of_noise
      )
      self.assertGreater(
          f0_crepe_metrics.metrics["f0_dist"].result(), 0
      )
      self.assertGreater(
          f0_crepe_metrics.metrics["outlier_ratio"].result(), 0
      )
  
      f0_crepe_metrics.flush(step=1)
  
imports: from unittest import mock
  from absl.testing import parameterized
  import ddsp
  from ddsp.test_util import gen_np_batched_sinusoids
  from ddsp.test_util import gen_np_sinusoid
  import ddsp.training.metrics
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 5 for calling the MetricsObjectsTest obj's underlying member method code with example usage: obj.test_f0_crepe_metrics_has_expected_values(mock_compute_f0) without return types