class_docstr: Chroma cosine similarity metric.
  
  This metric extracts a chromagram for a reference waveform and
  a generated waveform and compares each frame using the cosine similarity
  function. The output is the mean cosine similarity.
  
  Args:
      sample_rate (int): Sample rate used by the chroma extractor.
      n_chroma (int): Number of chroma used by the chroma extractor.
      radix2_exp (int): Exponent for the chroma extractor.
      argmax (bool): Whether the chroma extractor uses argmax.
      eps (float): Epsilon for cosine similarity computation.
docstr: Compute cosine similarity between chromagrams and accumulate scores over the dataset.
code: def update(
      self,
      preds: torch.Tensor,
      targets: torch.Tensor,
      sizes: torch.Tensor,
      sample_rates: torch.Tensor,
  ) -> None:
      """Compute cosine similarity between chromagrams and accumulate scores over the dataset."""
      if preds.size(0) == 0:
          return
  
      assert (
          preds.shape == targets.shape
      ), f"Preds and target shapes mismatch: preds={preds.shape}, targets={targets.shape}"
      assert preds.size(0) == sizes.size(0), (
          f"Number of items in preds ({preds.shape}) mismatch ",
          f"with sizes ({sizes.shape})",
      )
      assert preds.size(0) == sample_rates.size(0), (
          f"Number of items in preds ({preds.shape}) mismatch ",
          f"with sample_rates ({sample_rates.shape})",
      )
      assert torch.all(
          sample_rates == sample_rates[0].item()
      ), "All sample rates are not the same in the batch"
  
      device = self.weight.device
      preds, targets = preds.to(device), targets.to(device)  # type: ignore
      sample_rate = sample_rates[0].item()
      preds = convert_audio(
          preds,
          from_rate=sample_rate,
          to_rate=self.chroma_sample_rate,
          to_channels=1,
      )
      targets = convert_audio(
          targets,
          from_rate=sample_rate,
          to_rate=self.chroma_sample_rate,
          to_channels=1,
      )
      gt_chroma = self.chroma_extractor(targets)
      gen_chroma = self.chroma_extractor(preds)
      chroma_lens = (sizes / self.chroma_extractor.winhop).ceil().int()
      for i in range(len(gt_chroma)):
          t = int(chroma_lens[i].item())
          cosine_sim = torch.nn.functional.cosine_similarity(
              gt_chroma[i, :t], gen_chroma[i, :t], dim=1, eps=self.eps
          )
          self.cosine_sum += cosine_sim.sum(dim=0)  # type: ignore
          self.weight += torch.tensor(t)
  
file_path: audiocraft/audiocraft/metrics/chroma_cosinesim.py
imports: import torch
  import torchmetrics
  from ..data.audio_utils import convert_audio
  from ..modules.chroma import ChromaExtractor
label_desc: Use image node_id 2 for calling the ChromaCosineSimilarityMetric obj's underlying member method code with example usage: obj.update(preds, targets, sizes, sample_rates) without return types