class_docstr: Inverse synthesis model (ddsp-inv).
  
  EXPERIMENTAL
  
  Builds a hierarchical model of audio:
  Audio -> Sinusoid -> Harmonic -> Sinusoid -> Audio.
  
  Unlike other models, the processor group is defined in the constructor, as
  there are many synthesizer specific regularizers and self-supervised losses.
class_docstr_tok: ["Inverse","synthesis","model","(","ddsp-inv",")",".","EXPERIMENTAL","Builds","a","hierarchical","model","of","audio",":","Audio","-",">","Sinusoid","-",">","Harmonic","-",">","Sinusoid","-",">","Audio",".","Unlike","other","models",",","the","processor","group","is","defined","in","the","constructor",",","as","there","are","many","synthesizer","specific","regularizers","and","self-supervised","losses","."]
docstr: Constructor.
docstr_tok: ["Constructor","."]
code: def __init__(
      self,
      # Encoders.
      sinusoidal_encoder=None,
      harmonic_encoder=None,
      # Losses.
      losses=None,
      sinusoidal_consistency_losses=None,
      harmonic_consistency_losses=None,
      filtered_noise_consistency_loss=None,
      twm_loss=None,
      harmonic_distribution_prior=None,
      # Processor Group.
      freq_scale_fn=None,
      reverb=True,
      n_samples=64000,
      sample_rate=16000,
      # Training.
      stop_gradient=True,
      **kwargs,
  ):
      """Constructor."""
      super().__init__(**kwargs)
      # Network objects.
      self.sinusoidal_encoder = sinusoidal_encoder
      self.harmonic_encoder = harmonic_encoder
      # Losses.
      self.audio_loss_objs = ddsp.core.make_iterable(losses)
      self.sinusoidal_consistency_losses = ddsp.core.make_iterable(
          sinusoidal_consistency_losses
      )
      self.harmonic_consistency_losses = ddsp.core.make_iterable(
          harmonic_consistency_losses
      )
      self.filtered_noise_consistency_loss = (
          filtered_noise_consistency_loss
      )
      self.twm_loss = twm_loss
      self.harmonic_distribution_prior = harmonic_distribution_prior
      # Training.
      self.stop_gradient = stop_gradient
  
      # ==============
      # ProcessorGroup
      # ==============
      # Define processor group in the constructor for more flexible routing.
      self.n_samples = n_samples
      self.sample_rate = sample_rate
  
      self.amps_scale_fn = ddsp.core.exp_sigmoid
  
      self.freq_scale_fn = freq_scale_fn or functools.partial(
          ddsp.core.frequencies_softmax, depth=64
      )
  
      self.sinusoidal_synth = ddsp.synths.Sinusoidal(
          n_samples=self.n_samples,
          sample_rate=self.sample_rate,
          amp_scale_fn=None,
          freq_scale_fn=None,
          name="sinusoidal",
      )
  
      self.filtered_noise_synth = ddsp.synths.FilteredNoise(
          n_samples=self.n_samples,
          window_size=0,
          scale_fn=None,
          name="filtered_noise",
      )
  
      dag = [
          (self.sinusoidal_synth, ["amplitudes", "frequencies"]),
          (self.filtered_noise_synth, ["noise_magnitudes"]),
          (
              ddsp.processors.Add(),
              [
                  f"{self.filtered_noise_synth.name}/signal",
                  f"{self.sinusoidal_synth.name}/signal",
              ],
          ),
      ]
  
      if reverb:
          self.reverb = ddsp.effects.FilteredNoiseReverb(
              reverb_length=int(self.sample_rate * 2),
              window_size=257,
              n_frames=500,
              n_filter_banks=16,
              trainable=True,
              name="reverb",
          )
          dag.append((self.reverb, ["add/signal"]))
  
      self.processor_group = ddsp.processors.ProcessorGroup(dag=dag)
  
file_path: ddsp/ddsp/training/models/inverse_synthesis.py
imports: import functools
  import ddsp
  from ddsp.training.models.model import Model
  import tensorflow
label_desc: Use image node_id 1 to create a new InverseSynthesis object from inherited base classes: Model with example: obj = InverseSynthesis(sinusoidal_encoder, harmonic_encoder, losses, sinusoidal_consistency_losses, harmonic_consistency_losses, filtered_noise_consistency_loss, twm_loss, harmonic_distribution_prior, freq_scale_fn, reverb, n_samples, sample_rate, stop_gradient)