class_docstr: Compute F1 scores.
  
  Args:
      num_classes (int): Number of labels.
      key (str): The key name of the predicted and ground truth labels.
          Defaults to 'labels'.
      mode (str or list[str]): Options are:
          - 'micro': Calculate metrics globally by counting the total true
            positives, false negatives and false positives.
          - 'macro': Calculate metrics for each label, and find their
            unweighted mean.
          If mode is a list, then metrics in mode will be calculated
          separately. Defaults to 'micro'.
      cared_classes (list[int]): The indices of the labels particpated in
          the metirc computing. If both ``cared_classes`` and
          ``ignored_classes`` are empty, all classes will be taken into
          account. Defaults to []. Note: ``cared_classes`` and
          ``ignored_classes`` cannot be specified together.
      ignored_classes (list[int]): The index set of labels that are ignored
          when computing metrics. If both ``cared_classes`` and
          ``ignored_classes`` are empty, all classes will be taken into
          account. Defaults to []. Note: ``cared_classes`` and
          ``ignored_classes`` cannot be specified together.
      collect_device (str): Device name used for collecting results from
          different ranks during distributed training. Must be 'cpu' or
          'gpu'. Defaults to 'cpu'.
      prefix (str, optional): The prefix that will be added in the metric
          names to disambiguate homonymous metrics of different evaluators.
          If prefix is not provided in the argument, self.default_prefix
          will be used instead. Defaults to None.
  
  Warning:
      Only non-negative integer labels are involved in computing. All
      negative ground truth labels will be ignored.
docstr: Compute the metrics from processed results.
  
  Args:
      results (list[Dict]): The processed results of each batch.
  
  Returns:
      dict[str, float]: The f1 scores. The keys are the names of the
          metrics, and the values are corresponding results. Possible
          keys are 'micro_f1' and 'macro_f1'.
docstr_tok: ["Compute","the","metrics","from","processed","results",".","Args",":","results","(","list","[","Dict","]",")",":","The","processed","results","of","each","batch",".","Returns",":","dict","[","str",",","float","]",":","The","f1","scores",".","The","keys","are","the","names","of","the","metrics",",","and","the","values","are","corresponding","results",".","Possible","keys","are","'micro_f1","'","and","'macro_f1","'","."]
code: def compute_metrics(self, results: Sequence[Dict]) -> Dict:
      """Compute the metrics from processed results.
  
      Args:
          results (list[Dict]): The processed results of each batch.
  
      Returns:
          dict[str, float]: The f1 scores. The keys are the names of the
              metrics, and the values are corresponding results. Possible
              keys are 'micro_f1' and 'macro_f1'.
      """
  
      preds = []
      gts = []
      for result in results:
          preds.append(result["pred_labels"])
          gts.append(result["gt_labels"])
      preds = torch.cat(preds)
      gts = torch.cat(gts)
  
      assert preds.max() < self.num_classes
      assert gts.max() < self.num_classes
  
      cared_labels = preds.new_tensor(
          self.cared_labels, dtype=torch.long
      )
  
      hits = (preds == gts)[None, :]
      preds_per_label = cared_labels[:, None] == preds[None, :]
      gts_per_label = cared_labels[:, None] == gts[None, :]
  
      tp = (hits * preds_per_label).float()
      fp = (~hits * preds_per_label).float()
      fn = (~hits * gts_per_label).float()
  
      result = {}
      if "macro" in self.mode:
          result["macro_f1"] = self._compute_f1(
              tp.sum(-1), fp.sum(-1), fn.sum(-1)
          )
      if "micro" in self.mode:
          result["micro_f1"] = self._compute_f1(
              tp.sum(), fp.sum(), fn.sum()
          )
  
      return result
  
file_path: mmocr/mmocr/evaluation/metrics/f_metric.py
imports: from typing import Dict, Optional, Sequence, Union
  import torch
  from mmengine.evaluator import BaseMetric
  from mmocr.registry import METRICS
label_desc: Use image node_id 3 for calling the F1Metric obj's underlying member method code with example usage: obj.compute_metrics(results) and returns: result