docstr: Dump the detection results to a txt file.
  
  Args:
      results (list[list | tuple]): Testing results of the
          dataset.
      outfile_prefix (str): The filename prefix of the json files.
          If the prefix is "somepath/xxx",
          the txt files will be named "somepath/xxx.txt".
  
  Returns:
      list[str]: Result txt files which contains corresponding                 instance segmentation images.
docstr_tok: ["Dump","the","detection","results","to","a","txt","file",".","Args",":","results","(","list","[","list","|","tuple","]",")",":","Testing","results","of","the","dataset",".","outfile_prefix","(","str",")",":","The","filename","prefix","of","the","json","files",".","If","the","prefix","is","``","somepath\/xxx","''",",","the","txt","files","will","be","named","``","somepath\/xxx.txt","''",".","Returns",":","list","[","str","]",":","Result","txt","files","which","contains","corresponding","instance","segmentation","images","."]
code: def results2txt(self, results, outfile_prefix):
      """Dump the detection results to a txt file.
  
          Args:
              results (list[list | tuple]): Testing results of the
                  dataset.
              outfile_prefix (str): The filename prefix of the json files.
                  If the prefix is "somepath/xxx",
                  the txt files will be named "somepath/xxx.txt".
  
          Returns:
              list[str]: Result txt files which contains corresponding \
                  instance segmentation images.
          """
      try:
          import cityscapesscripts.helpers.labels as CSLabels
      except ImportError:
          raise ImportError(
              'Please run "pip install citscapesscripts" to '
              "install cityscapesscripts first."
          )
      result_files = []
      os.makedirs(outfile_prefix, exist_ok=True)
      prog_bar = mmcv.ProgressBar(len(self))
      for idx in range(len(self)):
          result = results[idx]
          filename = self.data_infos[idx]["filename"]
          basename = osp.splitext(osp.basename(filename))[0]
          pred_txt = osp.join(outfile_prefix, basename + "_pred.txt")
  
          bbox_result, segm_result = result
          bboxes = np.vstack(bbox_result)
          # segm results
          if isinstance(segm_result, tuple):
              # Some detectors use different scores for bbox and mask,
              # like Mask Scoring R-CNN. Score of segm will be used instead
              # of bbox score.
              segms = mmcv.concat_list(segm_result[0])
              mask_score = segm_result[1]
          else:
              # use bbox score for mask score
              segms = mmcv.concat_list(segm_result)
              mask_score = [bbox[-1] for bbox in bboxes]
          labels = [
              np.full(bbox.shape[0], i, dtype=np.int32)
              for i, bbox in enumerate(bbox_result)
          ]
          labels = np.concatenate(labels)
  
          assert len(bboxes) == len(segms) == len(labels)
          num_instances = len(bboxes)
          prog_bar.update()
          with open(pred_txt, "w") as fout:
              for i in range(num_instances):
                  pred_class = labels[i]
                  classes = self.CLASSES[pred_class]
                  class_id = CSLabels.name2label[classes].id
                  score = mask_score[i]
                  mask = maskUtils.decode(segms[i]).astype(np.uint8)
                  png_filename = osp.join(
                      outfile_prefix, basename + f"_{i}_{classes}.png"
                  )
                  mmcv.imwrite(mask, png_filename)
                  fout.write(
                      f"{osp.basename(png_filename)} {class_id} "
                      f"{score}\n"
                  )
          result_files.append(pred_txt)
  
      return result_files
  
file_path: insightface/detection/scrfd/mmdet/datasets/cityscapes.py
imports: import glob
  import os
  import os.path
  import tempfile
  from collections import OrderedDict
  import mmcv
  import numpy
  import pycocotools.mask
  from mmcv.utils import print_log
  from .builder import DATASETS
  from .coco import CocoDataset
label_desc: Use image node_id 3 for calling the CityscapesDataset obj's underlying member method code with example usage: obj.results2txt(results, outfile_prefix) and returns: result_files