code: def parse_directory(
      path,
      key_func=lambda x: x[-11:],
      rgb_prefix="img_",
      flow_x_prefix="flow_x_",
      flow_y_prefix="flow_y_",
      level=1,
  ):
      """
      Parse directories holding extracted frames from standard benchmarks
      """
      print("parse frames under folder {}".format(path))
      if level == 1:
          frame_folders = glob.glob(os.path.join(path, "*"))
      elif level == 2:
          frame_folders = glob.glob(os.path.join(path, "*", "*"))
      else:
          raise ValueError("level can be only 1 or 2")
  
      def count_files(directory, prefix_list):
          lst = os.listdir(directory)
          cnt_list = [
              len(fnmatch.filter(lst, x + "*")) for x in prefix_list
          ]
          return cnt_list
  
      # check RGB
      frame_dict = {}
      for i, f in enumerate(frame_folders):
          all_cnt = count_files(
              f, (rgb_prefix, flow_x_prefix, flow_y_prefix)
          )
          k = key_func(f)
  
          x_cnt = all_cnt[1]
          y_cnt = all_cnt[2]
          if x_cnt != y_cnt:
              raise ValueError(
                  "x and y direction have different number "
                  "of flow images. video: " + f
              )
          if i % 200 == 0:
              print("{} videos parsed".format(i))
  
          frame_dict[k] = (f, all_cnt[0], x_cnt)
  
      print("frame folder analysis done")
      return frame_dict
  
imports: import argparse
  import sys
  import os
  import os.path
  import glob
  import fnmatch
  import random
  import zipfile
  from pipes import quote
  from multiprocessing import Pool, current_process
  import csv
label_desc: Use image node_id 8 for calling a global function with example usage: parse_directory(path, key_func, rgb_prefix, flow_x_prefix, flow_y_prefix, level) and returns: frame_dict, cnt_list