code: def get_imagenet_tfdata(
      datadir, name, batch_size, mapper=None, parallel=None
  ):
      """
      Args:
          mapper: a symbolic function that takes a tf.string (the raw bytes read from file) and produces a BGR image.
              Defaults to `fbresnet_mapper(isTrain)`.
  
      Returns:
          A `tf.data.Dataset`. If training, the dataset is infinite.
          The dataset contains BGR images and labels.
      """
  
      def get_imglist(dir, name):
          """
          Returns:
              [(full filename, label)]
          """
          dir = os.path.join(dir, name)
          meta = dataset.ILSVRCMeta()
          imglist = meta.get_image_list(
              name, dataset.ILSVRCMeta.guess_dir_structure(dir)
          )
  
          def _filter(fname):
              # png
              return "n02105855_2933.JPEG" in fname
  
          ret = []
          for fname, label in imglist:
              if _filter(fname):
                  logger.info(
                      "Image {} was filtered out.".format(fname)
                  )
                  continue
              fname = os.path.join(dir, fname)
              ret.append((fname, label))
          return ret
  
      assert name in ["train", "val", "test"]
      assert datadir is not None
      isTrain = name == "train"
      if mapper is None:
          mapper = fbresnet_mapper(isTrain)
      if parallel is None:
          parallel = min(
              40, multiprocessing.cpu_count() // 2
          )  # assuming hyperthreading
      imglist = get_imglist(datadir, name)
  
      N = len(imglist)
      filenames = tf.constant([k[0] for k in imglist], name="filenames")
      labels = tf.constant(
          [k[1] for k in imglist], dtype=tf.int32, name="labels"
      )
  
      ds = tf.data.Dataset.from_tensor_slices((filenames, labels))
  
      if isTrain:
          ds = ds.shuffle(N, reshuffle_each_iteration=True).repeat()
  
      ds = ds.apply(
          tf.data.experimental.map_and_batch(
              lambda fname, label: (mapper(tf.read_file(fname)), label),
              batch_size=batch_size,
              num_parallel_batches=parallel,
          )
      )
      ds = ds.prefetch(100)
      return ds
  
imports: import multiprocessing
  import numpy
  import os
  from abc import abstractmethod
  import cv2
  import tqdm
  from tensorpack import tfv1
  from tensorpack import ModelDesc
  from tensorpack.dataflow import AugmentImageComponent, BatchData, MultiThreadMapData, MultiProcessRunnerZMQ, dataset, imgaug
  from tensorpack.input_source import QueueInput, StagingInput
  from tensorpack.models import regularize_cost, l2_regularizer
  from tensorpack.predict import FeedfreePredictor, PredictConfig
  from tensorpack.tfutils.summary import add_moving_summary
  from tensorpack.tfutils.optimizer import AccumGradOptimizer
  from tensorpack.utils import logger
  from tensorpack.utils.stats import RatioCounter
label_desc: Use image node_id 3 for calling a global function with example usage: get_imagenet_tfdata(datadir, name, batch_size, mapper, parallel) and returns: ds, ret, unknown