code: def parse_wider_txt(data_root: str, split: str, save_root: str):
      """
      refer to: torchvision.dataset.widerface.py
      :param data_root:
      :param split:
      :param save_root:
      :return:
      """
      assert split in [
          "train",
          "val",
      ], f"split must be in ['train', 'val'], got {split}"
  
      if os.path.exists(save_root) is False:
          os.makedirs(save_root)
  
      txt_path = os.path.join(
          data_root,
          "wider_face_split",
          f"wider_face_{split}_bbx_gt.txt",
      )
      img_root = os.path.join(data_root, f"WIDER_{split}", "images")
      with open(txt_path, "r") as f:
          lines = f.readlines()
          file_name_line, num_boxes_line, box_annotation_line = (
              True,
              False,
              False,
          )
          num_boxes, box_counter, idx = 0, 0, 0
          labels = []
          xml_list = []
          progress_bar = tqdm(lines)
          for line in progress_bar:
              line = line.rstrip()
              if file_name_line:
                  img_path = line
                  file_name_line = False
                  num_boxes_line = True
              elif num_boxes_line:
                  num_boxes = int(line)
                  num_boxes_line = False
                  box_annotation_line = True
              elif box_annotation_line:
                  box_counter += 1
                  line_split = line.split(" ")
                  line_values = [x for x in line_split]
                  labels.append(line_values)
                  if box_counter >= num_boxes:
                      box_annotation_line = False
                      file_name_line = True
  
                      if num_boxes == 0:
                          print(f"in {img_path}, no object, skip.")
                      else:
                          if create_xml(
                              labels, img_root, img_path, save_root
                          ):
                              # 只记录有目标的xml文件
                              xml_list.append(
                                  img_path.split("/")[-1].split(".")[0]
                              )
  
                      box_counter = 0
                      labels.clear()
                      idx += 1
                      progress_bar.set_description(f"{idx} images")
              else:
                  raise RuntimeError(
                      "Error parsing annotation file {}".format(
                          txt_path
                      )
                  )
  
          with open(split + ".txt", "w") as w:
              w.write("\n".join(xml_list))
  
imports: import os
  from tqdm import tqdm
  import cv2
  from create_xml import create_pascal_voc_xml
label_desc: Use image node_id 2 for calling a global function with example usage: parse_wider_txt(data_root, split, save_root) without return types