docstr: time-frequency cross-entropy loss.
  
  Args:
      ref: (Batch, T) or (Batch, T, C)
      inf: (Batch, T, nclass) or (Batch, T, C, nclass)
  Returns:
      loss: (Batch,)
docstr_tok: ["time-frequency","cross-entropy","loss",".","Args",":","ref",":","(","Batch",",","T",")","or","(","Batch",",","T",",","C",")","inf",":","(","Batch",",","T",",","nclass",")","or","(","Batch",",","T",",","C",",","nclass",")","Returns",":","loss",":","(","Batch",",",")"]
code: def forward(self, ref, inf) -> torch.Tensor:
      """time-frequency cross-entropy loss.
  
      Args:
          ref: (Batch, T) or (Batch, T, C)
          inf: (Batch, T, nclass) or (Batch, T, C, nclass)
      Returns:
          loss: (Batch,)
      """
      assert (
          ref.shape[0] == inf.shape[0] and ref.shape[1] == inf.shape[1]
      ), (
          ref.shape,
          inf.shape,
      )
  
      if ref.dim() == 2:
          loss = self.cross_entropy(inf.permute(0, 2, 1), ref).mean(
              dim=1
          )
      elif ref.dim() == 3:
          loss = self.cross_entropy(inf.permute(0, 3, 1, 2), ref).mean(
              dim=[1, 2]
          )
      else:
          raise ValueError(
              "Invalid input shape: ref={}, inf={}".format(
                  ref.shape, inf.shape
              )
          )
  
      with torch.no_grad():
          pred = inf.argmax(-1)
          mask = ref != self.ignore_id
          numerator = (pred == ref).masked_fill(~mask, 0).float()
          if ref.dim() == 2:
              acc = numerator.sum(dim=1) / mask.sum(dim=1).float()
          elif ref.dim() == 3:
              acc = (
                  numerator.sum(dim=[1, 2])
                  / mask.sum(dim=[1, 2]).float()
              )
          self.stats = {"acc": acc.cpu() * 100}
  
      return loss
  
imports: import math
  from abc import ABC, abstractmethod
  from functools import reduce
  import torch
  import torch.nn.functional
  from packaging.version import parse
  from espnet2.enh.layers.complex_utils import complex_norm, is_complex, new_complex_like
  from espnet2.enh.loss.criterions.abs_loss import AbsEnhLoss
label_desc: Use image node_id 4 for calling the FrequencyDomainCrossEntropy obj's underlying member method code with example usage: obj.forward(ref, inf) and returns: loss