code: def collect_files(img_dir, gt_dir, ratio):
      """Collect all images and their corresponding groundtruth files.
      Args:
          img_dir (str): The image directory
          gt_dir (str): The groundtruth directory
          ratio (float): Split ratio for val set
  
      Returns:
          files (list): The list of tuples (img_file, groundtruth_file)
      """
      assert isinstance(img_dir, str)
      assert img_dir
      assert isinstance(gt_dir, str)
      assert gt_dir
      assert isinstance(ratio, float)
      assert (
          ratio < 1.0
      ), "val_ratio should be a float between 0.0 to 1.0"
  
      ann_list, imgs_list = [], []
      for ann_file in os.listdir(gt_dir):
          ann_list.append(osp.join(gt_dir, ann_file))
          imgs_list.append(
              osp.join(img_dir, ann_file.replace("txt", "jpg"))
          )
  
      all_files = list(zip(imgs_list, ann_list))
      assert len(all_files), f"No images found in {img_dir}"
      print(f"Loaded {len(all_files)} images from {img_dir}")
  
      trn_files, val_files = [], []
      if ratio > 0:
          for i, file in enumerate(all_files):
              if i % math.floor(1 / ratio):
                  trn_files.append(file)
              else:
                  val_files.append(file)
      else:
          trn_files, val_files = all_files, []
  
      print(f"training #{len(trn_files)}, val #{len(val_files)}")
  
      return trn_files, val_files
  
file_path: mmocr/tools/dataset_converters/textrecog/rctw_converter.py
imports: import argparse
  import math
  import os
  import os.path
  import mmcv
  import mmengine
  from mmocr.utils import crop_img, dump_ocr_data
label_desc: Use image node_id 1 for calling a global function with example usage: collect_files(img_dir, gt_dir, ratio) and returns: trn_files,  val_files