code: def prepare_feats(
      img_dir,
      output_dir,
      split_ids,
      ids_to_skip=[],
      feature_dim=100,
      downsampling_factor=0.5,
  ):
      """Create feats.scp file from OCR images
  
      Parameters
      ----------
      output_dir : str
          The folder path for output, e.g. data/
      split_ids : list of str
          a list of ids to process, e.g. train/valid/test splits
      ids_to_skip : list of str
          A list of ids to exclude from the output,
          e.g. to ignore previously skipped ids due to empty transcript
      feature_dim : int (default=100)
          The hidden dimension for each feature matrix,
          all images are resized to this height
      downsampling_factor : float (default=0.5)
          A multiplier for the width dimension (analogous to the 'time'
          dimension in ASR) of each image, used to reduce the length for
          faster training. Empirically, a value of 0.5 is found to achieve
          the best performance for this dataset
      """
      output_ark = os.path.join(output_dir, "feats.ark")
      output_scp = os.path.join(output_dir, "feats.scp")
      writer = file_writer_helper(
          wspecifier=f"ark,scp:{output_ark},{output_scp}",
          filetype="mat",
          write_num_frames=f"ark,t:{output_dir}/num_frames.txt",
          compress=False,
      )
  
      num_processed = 0
      total_length = 0
  
      for img_id in split_ids:
          if img_id in ids_to_skip:
              continue
  
          dir, subdir, index = img_id.split("-")
          img_path = os.path.join(
              img_dir,
              dir,
              f"{dir}-{subdir}",
              f"{dir}-{subdir}-{index}.png",
          )
          with Image.open(img_path) as img:
              # resize images to common height (feature_dim)
              # and downsample width by downsampling_factor
              aspect_ratio = img.width / img.height
              n_frames = int(
                  (aspect_ratio * feature_dim) * downsampling_factor
              )
              img = img.resize((n_frames, feature_dim))
              img_arr = np.array(img, dtype=np.float32).transpose()
              assert img_arr.shape[1] == feature_dim
  
              # write to data/output_dir/feats.scp
              writer[img_id] = img_arr
  
              # update counters for logging
              num_processed += 1
              total_length += img_arr.shape[0]
  
      print(
          f"Extracted features for {num_processed} examples "
          f"to {os.path.join(output_dir, 'feats.scp')},"
          f"average length is {total_length / num_processed:.02f}"
      )
  
file_path: espnet/egs2/iam/ocr1/local/data_prep.py
imports: import argparse
  import os
  import numpy
  from PIL import Image
  from espnet.utils.cli_writers import file_writer_helper
label_desc: Use image node_id 3 for calling a global function with example usage: prepare_feats(img_dir, output_dir, split_ids, ids_to_skip, feature_dim, downsampling_factor) without return types