code: def splitTrainVal(
      root,
      absTrainRootPath,
      absValRootPath,
      absTestRootPath,
      trainTxt,
      valTxt,
      testTxt,
      flag,
  ):
      # 按照指定的比例划分训练集、验证集、测试集
      dataAbsPath = os.path.abspath(root)
  
      if flag == "det":
          labelFilePath = os.path.join(
              dataAbsPath, args.detLabelFileName
          )
      elif flag == "rec":
          labelFilePath = os.path.join(
              dataAbsPath, args.recLabelFileName
          )
  
      labelFileRead = open(labelFilePath, "r", encoding="UTF-8")
      labelFileContent = labelFileRead.readlines()
      random.shuffle(labelFileContent)
      labelRecordLen = len(labelFileContent)
  
      for index, labelRecordInfo in enumerate(labelFileContent):
          imageRelativePath = labelRecordInfo.split("\t")[0]
          imageLabel = labelRecordInfo.split("\t")[1]
          imageName = os.path.basename(imageRelativePath)
  
          if flag == "det":
              imagePath = os.path.join(dataAbsPath, imageName)
          elif flag == "rec":
              imagePath = os.path.join(
                  dataAbsPath,
                  "{}\\{}".format(args.recImageDirName, imageName),
              )
  
          # 按预设的比例划分训练集、验证集、测试集
          trainValTestRatio = args.trainValTestRatio.split(":")
          trainRatio = eval(trainValTestRatio[0]) / 10
          valRatio = trainRatio + eval(trainValTestRatio[1]) / 10
          curRatio = index / labelRecordLen
  
          if curRatio < trainRatio:
              imageCopyPath = os.path.join(absTrainRootPath, imageName)
              shutil.copy(imagePath, imageCopyPath)
              trainTxt.write("{}\t{}".format(imageCopyPath, imageLabel))
          elif curRatio >= trainRatio and curRatio < valRatio:
              imageCopyPath = os.path.join(absValRootPath, imageName)
              shutil.copy(imagePath, imageCopyPath)
              valTxt.write("{}\t{}".format(imageCopyPath, imageLabel))
          else:
              imageCopyPath = os.path.join(absTestRootPath, imageName)
              shutil.copy(imagePath, imageCopyPath)
              testTxt.write("{}\t{}".format(imageCopyPath, imageLabel))
  
file_path: PaddleOCR/PPOCRLabel/gen_ocr_train_val_test.py
imports: import os
  import shutil
  import random
  import argparse
label_desc: Use image node_id 2 for calling a global function with example usage: splitTrainVal(root, absTrainRootPath, absValRootPath, absTestRootPath, trainTxt, valTxt, testTxt, flag) without return types