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.
code: def __init__(
      self,
      num_classes: int,
      key: str = "labels",
      mode: Union[str, Sequence[str]] = "micro",
      cared_classes: Sequence[int] = [],
      ignored_classes: Sequence[int] = [],
      collect_device: str = "cpu",
      prefix: Optional[str] = None,
  ) -> None:
      super().__init__(collect_device, prefix)
      assert isinstance(num_classes, int)
      assert isinstance(cared_classes, (list, tuple))
      assert isinstance(ignored_classes, (list, tuple))
      assert isinstance(mode, (list, str))
      assert not (
          len(cared_classes) > 0 and len(ignored_classes) > 0
      ), "cared_classes and ignored_classes cannot be both non-empty"
  
      if isinstance(mode, str):
          mode = [mode]
      assert set(mode).issubset({"micro", "macro"})
      self.mode = mode
  
      if len(cared_classes) > 0:
          assert (
              min(cared_classes) >= 0
              and max(cared_classes) < num_classes
          ), "cared_classes must be a subset of [0, num_classes)"
          self.cared_labels = sorted(cared_classes)
      elif len(ignored_classes) > 0:
          assert (
              min(ignored_classes) >= 0
              and max(ignored_classes) < num_classes
          ), "ignored_classes must be a subset of [0, num_classes)"
          self.cared_labels = sorted(
              set(range(num_classes)) - set(ignored_classes)
          )
      else:
          self.cared_labels = list(range(num_classes))
      self.num_classes = num_classes
      self.key = key
  
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 1 to create a new F1Metric object from inherited base classes: BaseMetric with example: obj = F1Metric(num_classes, key, mode, cared_classes, ignored_classes, collect_device, prefix)