class_docstr: A wrapper around a pretrained CREPE model, for pitch prediction.
  
  Enables predicting pitch and confidence entirely in TF for running in batch
  on accelerators. For [full,large,small,tiny] crepe models, reads h5 models
  from installed pip package. Other saved models
class_docstr_tok: ["A","wrapper","around","a","pretrained","CREPE","model",",","for","pitch","prediction",".","Enables","predicting","pitch","and","confidence","entirely","in","TF","for","running","in","batch","on","accelerators",".","For","[","full",",","large",",","small",",","tiny","]","crepe","models",",","reads","h5","models","from","installed","pip","package",".","Other","saved","models"]
docstr: Convert network outputs (activations) to f0 predictions.
docstr_tok: ["Convert","network","outputs","(","activations",")","to","f0","predictions","."]
code: def activations_to_f0_and_confidence(cls, activations, centers=None):
      """Convert network outputs (activations) to f0 predictions."""
      cent_mapping = tf.cast(
          tf.linspace(0, 7180, 360) + 1997.3794084376191, tf.float32
      )
  
      # The confidence of voicing activity and the argmax bin.
      confidence = tf.reduce_max(activations, axis=-1, keepdims=True)
      if centers is None:
          centers = tf.math.argmax(activations, axis=-1)
      centers = tf.cast(centers, tf.int32)
  
      # Slice the local neighborhood around the argmax bin.
      start = centers - 4
      idx_list = tf.range(0, 10)
      idx_list = start[:, None] + idx_list[None, :]
  
      # Bound to [0, 359].
      idx_list = tf.where(idx_list > 0, idx_list, 0)
      idx_list = tf.where(idx_list < 359, idx_list, 359)
  
      # Gather and weight activations.
      weights = tf.gather(activations, idx_list, batch_dims=1)
      cents = tf.gather(cent_mapping, idx_list, batch_dims=0)
      f0_cent = tf.reduce_sum(weights * cents, axis=-1) / tf.reduce_sum(
          weights, axis=-1
      )
      f0_hz = 10 * 2 ** (f0_cent / 1200.0)
  
      return f0_hz, confidence
  
imports: import crepe
  from ddsp import core
  from ddsp.core import safe_log
  from ddsp.core import tf_float32
  import gin
  import librosa
  import numpy
  import tensorflow.compat.v2
  import tensorflow_probability
label_desc: Use image node_id 2 for calling the PretrainedCREPE obj's underlying member method code with example usage: obj.activations_to_f0_and_confidence(cls, activations, centers) and returns: f0_hz,  confidence