class_docstr: Estimate a STFT in normal frequency domain from bark frequency domain.
  
  .. devices:: CPU CUDA
  
  It minimizes the euclidian norm between the input bark-spectrogram and the product between
  the estimated spectrogram and the filter banks using SGD.
  
  Args:
      n_stft (int): Number of bins in STFT. See ``n_fft`` in :class:`Spectrogram`.
      n_barks (int, optional): Number of bark filterbanks. (Default: ``128``)
      sample_rate (int, optional): Sample rate of audio signal. (Default: ``16000``)
      f_min (float, optional): Minimum frequency. (Default: ``0.``)
      f_max (float or None, optional): Maximum frequency. (Default: ``sample_rate // 2``)
      max_iter (int, optional): Maximum number of optimization iterations. (Default: ``100000``)
      tolerance_loss (float, optional): Value of loss to stop optimization at. (Default: ``1e-5``)
      tolerance_change (float, optional): Difference in losses to stop optimization at. (Default: ``1e-8``)
      sgdargs (dict or None, optional): Arguments for the SGD optimizer. (Default: ``None``)
      bark_scale (str, optional): Scale to use: ``traunmuller``, ``schroeder`` or ``wang``. (Default: ``traunmuller``)
  
  Example
      >>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True)
      >>> mel_spectrogram_transform = transforms.BarkSpectrogram(sample_rate, n_fft=1024)
      >>> mel_spectrogram = bark_spectrogram_transform(waveform)
      >>> inverse_barkscale_transform = transforms.InverseBarkScale(n_stft=1024 // 2 + 1)
      >>> spectrogram = inverse_barkscale_transform(mel_spectrogram)
class_docstr_tok: ["Estimate","a","STFT","in","normal","frequency","domain","from","bark","frequency","domain",".","..","devices",":",":","CPU","CUDA","It","minimizes","the","euclidian","norm","between","the","input","bark-spectrogram","and","the","product","between","the","estimated","spectrogram","and","the","filter","banks","using","SGD",".","Args",":","n_stft","(","int",")",":","Number","of","bins","in","STFT",".","See","``","n_fft","``","in",":","class",":","`","Spectrogram","`",".","n_barks","(","int",",","optional",")",":","Number","of","bark","filterbanks",".","(","Default",":","``","128","``",")","sample_rate","(","int",",","optional",")",":","Sample","rate","of","audio","signal",".","(","Default",":","``","16000","``",")","f_min","(","float",",","optional",")",":","Minimum","frequency",".","(","Default",":","``","0.","``",")","f_max","(","float","or","None",",","optional",")",":","Maximum","frequency",".","(","Default",":","``","sample_rate","\/\/","2","``",")","max_iter","(","int",",","optional",")",":","Maximum","number","of","optimization","iterations",".","(","Default",":","``","100000","``",")","tolerance_loss","(","float",",","optional",")",":","Value","of","loss","to","stop","optimization","at",".","(","Default",":","``","1e-5","``",")","tolerance_change","(","float",",","optional",")",":","Difference","in","losses","to","stop","optimization","at",".","(","Default",":","``","1e-8","``",")","sgdargs","(","dict","or","None",",","optional",")",":","Arguments","for","the","SGD","optimizer",".","(","Default",":","``","None","``",")","bark_scale","(","str",",","optional",")",":","Scale","to","use",":","``","traunmuller","``",",","``","schroeder","``","or","``","wang","``",".","(","Default",":","``","traunmuller","``",")","Example",">",">",">","waveform",",","sample_rate","=","torchaudio.load","(","``","test.wav","''",",","normalize=True",")",">",">",">","mel_spectrogram_transform","=","transforms.BarkSpectrogram","(","sample_rate",",","n_fft=1024",")",">",">",">","mel_spectrogram","=","bark_spectrogram_transform","(","waveform",")",">",">",">","inverse_barkscale_transform","=","transforms.InverseBarkScale","(","n_stft=1024","\/\/","2","+","1",")",">",">",">","spectrogram","=","inverse_barkscale_transform","(","mel_spectrogram",")"]
docstr: Args:
      barkspec (torch.Tensor): A Bark frequency spectrogram of dimension (..., ``n_barks``, time)
  
  Returns:
      torch.Tensor: Linear scale spectrogram of size (..., freq, time)
docstr_tok: ["Args",":","barkspec","(","torch.Tensor",")",":","A","Bark","frequency","spectrogram","of","dimension","(","...",",","``","n_barks","``",",","time",")","Returns",":","torch.Tensor",":","Linear","scale","spectrogram","of","size","(","...",",","freq",",","time",")"]
code: def forward(self, barkspec: torch.Tensor) -> torch.Tensor:
      r"""
      Args:
          barkspec (torch.Tensor): A Bark frequency spectrogram of dimension (..., ``n_barks``, time)
  
      Returns:
          torch.Tensor: Linear scale spectrogram of size (..., freq, time)
      """
      # pack batch
      shape = barkspec.size()
      barkspec = barkspec.view(-1, shape[-2], shape[-1])
  
      n_barks, time = shape[-2], shape[-1]
      freq, _ = self.fb.size()  # (freq, n_mels)
      barkspec = barkspec.transpose(-1, -2)
      if self.n_barks != n_barks:
          raise ValueError(
              "Expected an input with {} bark bins. Found: {}".format(
                  self.n_barks, n_barks
              )
          )
  
      specgram = torch.rand(
          barkspec.size()[0],
          time,
          freq,
          requires_grad=True,
          dtype=barkspec.dtype,
          device=barkspec.device,
      )
  
      optim = torch.optim.SGD([specgram], **self.sgdargs)
  
      loss = float("inf")
      for _ in range(self.max_iter):
          optim.zero_grad()
          diff = barkspec - specgram.matmul(self.fb)
          new_loss = diff.pow(2).sum(axis=-1).mean()
          # take sum over bark-frequency then average over other dimensions
          # so that loss threshold is applied par unit timeframe
          new_loss.backward()
          optim.step()
          specgram.data = specgram.data.clamp(min=0)
  
          new_loss = new_loss.item()
          if (
              new_loss < self.tolerance_loss
              or abs(loss - new_loss) < self.tolerance_change
          ):
              break
          loss = new_loss
  
      specgram.requires_grad_(False)
      specgram = specgram.clamp(min=0).transpose(-1, -2)
  
      # unpack batch
      specgram = specgram.view(shape[:-2] + (freq, time))
      return specgram
  
imports: from typing import Callable, Optional
  import torch
  from torchaudio.prototype.functional import barkscale_fbanks, chroma_filterbank
  from torchaudio.transforms import Spectrogram
label_desc: Use image node_id 2 for calling the InverseBarkScale obj's underlying member method code with example usage: obj.forward(barkspec) and returns: specgram