code: def main(args):
      path_imgrec = os.path.join(args.root_dir, "train.rec")
      path_imgidx = os.path.join(args.root_dir, "train.idx")
      imgrec = mx.recordio.MXIndexedRecordIO(
          path_imgidx, path_imgrec, "r"
      )
      s = imgrec.read_idx(0)
      header, _ = mx.recordio.unpack(s)
      if header.flag > 0:
          header0 = (int(header.label[0]), int(header.label[1]))
          imgidx = np.array(range(1, int(header.label[0])))
      else:
          imgidx = np.array(list(imgrec.keys))
  
      classes = set()
      os.makedirs(
          os.path.join(args.output_dir, "images"), exist_ok=True
      )
      fp = open(os.path.join(args.output_dir, "label.txt"), "w")
      for idx in tqdm.tqdm(imgidx):
          s = imgrec.read_idx(idx)
          header, img = mx.recordio.unpack(s)
          label = header.label
          if not isinstance(label, numbers.Number):
              label = label[0]
          img = mx.image.imdecode(img).asnumpy()[..., ::-1]
          label = int(label)
          classes.add(label)
  
          filename = "images/%08d.jpg" % idx
          fp.write("%s\t%d\n" % (filename, label))
          cv2.imwrite(
              os.path.join(args.output_dir, filename),
              img,
              [int(cv2.IMWRITE_JPEG_QUALITY), 100],
          )
      fp.close()
      shutil.copy(
          os.path.join(args.root_dir, "agedb_30.bin"),
          os.path.join(args.output_dir, "agedb_30.bin"),
      )
      shutil.copy(
          os.path.join(args.root_dir, "cfp_fp.bin"),
          os.path.join(args.output_dir, "cfp_fp.bin"),
      )
      shutil.copy(
          os.path.join(args.root_dir, "lfw.bin"),
          os.path.join(args.output_dir, "lfw.bin"),
      )
      print("num_image: ", len(imgidx), "num_classes: ", len(classes))
      with open(os.path.join(args.output_dir, "README.md"), "w") as f:
          f.write("num_image: {}\n".format(len(imgidx)))
          f.write("num_classes: {}\n".format(len(classes)))
  
file_path: insightface/recognition/arcface_paddle/tools/mx_recordio_2_images.py
imports: import os
  import argparse
  import numpy
  import numbers
  import mxnet
  import cv2
  import tqdm
  import shutil
label_desc: Use image node_id 1 for calling a global function with example usage: main(args) without return types