code: def directory_to_samples(directory, flags=None, filter_channel=False):
      """Read a directory, and list all subdirectories files as class sample"""
      samples = []
      targets = []
      label = 0
      try:  # Python 2
          classes = sorted(os.walk(directory).next()[1])
      except Exception:  # Python 3
          classes = sorted(os.walk(directory).__next__()[1])
      for c in classes:
          c_dir = os.path.join(directory, c)
          try:  # Python 2
              walk = os.walk(c_dir).next()
          except Exception:  # Python 3
              walk = os.walk(c_dir).__next__()
          for sample in walk[2]:
              if not flags or any(flag in sample for flag in flags):
                  if filter_channel:
                      if (
                          get_img_channel(os.path.join(c_dir, sample))
                          != 3
                      ):
                          continue
                  samples.append(os.path.join(c_dir, sample))
                  targets.append(label)
          label += 1
      return samples, targets
  
imports: from __future__ import division, print_function, absolute_import
  import os
  import random
  import numpy
  from PIL import Image
  import pickle
  import csv
  import warnings
  import tensorflow.compat.v1
  from io import BytesIO
label_desc: Use image node_id 24 for calling a global function with example usage: directory_to_samples(directory, flags, filter_channel) and returns: samples,  targets