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: Process one batch of data_samples. The processed results should be
  stored in ``self.results``, which will be used to compute the metrics
  when all batches have been processed.
  
  Args:
      data_batch (Sequence[Dict]): A batch of gts.
      data_samples (Sequence[Dict]): A batch of outputs from the model.
docstr_tok: ["Process","one","batch","of","data_samples",".","The","processed","results","should","be","stored","in","``","self.results","``",",","which","will","be","used","to","compute","the","metrics","when","all","batches","have","been","processed",".","Args",":","data_batch","(","Sequence","[","Dict","]",")",":","A","batch","of","gts",".","data_samples","(","Sequence","[","Dict","]",")",":","A","batch","of","outputs","from","the","model","."]
code: def process(
      self, data_batch: Sequence[Dict], data_samples: Sequence[Dict]
  ) -> None:
      """Process one batch of data_samples. The processed results should be
      stored in ``self.results``, which will be used to compute the metrics
      when all batches have been processed.
  
      Args:
          data_batch (Sequence[Dict]): A batch of gts.
          data_samples (Sequence[Dict]): A batch of outputs from the model.
      """
      for data_sample in data_samples:
          pred_labels = (
              data_sample.get("pred_instances").get(self.key).cpu()
          )
          gt_labels = (
              data_sample.get("gt_instances").get(self.key).cpu()
          )
  
          result = dict(
              pred_labels=pred_labels.flatten(),
              gt_labels=gt_labels.flatten(),
          )
          self.results.append(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 2 for calling the F1Metric obj's underlying member method code with example usage: obj.process(data_batch, data_samples) without return types