parameters: (self, input, shape, dtype, max_num_images=None, exact_batches=False, preprocessor="fixed_shape_resizer")
docstring: :param input: The input directory to read images from.
          :param shape: The tensor shape of the batch to prepare, either in NCHW or NHWC format.
          :param dtype: The (numpy) datatype to cast the batched data to.
          :param max_num_images: The maximum number of images to read from the directory.
          :param exact_batches: This defines how to handle a number of images that is not an exact multiple of the batch
          size. If false, it will pad the final batch with zeros to reach the batch size. If true, it will *remove* the
          last few images in excess of a batch size multiple, to guarantee batches are exact (useful for calibration).
          :param preprocessor: Set the preprocessor to use, depending on which network is being used.
docstring_summary: :param input: The input directory to read images from.
          :param shape: The tensor shape of the batch to prepare, either in NCHW or NHWC format.
          :param dtype: The (numpy) datatype to cast the batched data to.
          :param max_num_images: The maximum number of images to read from the directory.
          :param exact_batches: This defines how to handle a number of images that is not an exact multiple of the batch
          size. If false, it will pad the final batch with zeros to reach the batch size. If true, it will *remove* the
          last few images in excess of a batch size multiple, to guarantee batches are exact (useful for calibration).
          :param preprocessor: Set the preprocessor to use, depending on which network is being used.
docstring_tokens: : param input : The input directory to read images from . : param shape : The tensor shape of the batch to prepare either in NCHW or NHWC format . : param dtype : The ( numpy ) datatype to cast the batched data to . : param max_num_images : The maximum number of images to read from the directory . : param exact_batches : This defines how to handle a number of images that is not an exact multiple of the batch size . If false it will pad the final batch with zeros to reach the batch size . If true it will * remove * the last few images in excess of a batch size multiple to guarantee batches are exact ( useful for calibration ) . : param preprocessor : Set the preprocessor to use depending on which network is being used .
function: def __init__(self, input, shape, dtype, max_num_images=None, exact_batches=False, preprocessor="fixed_shape_resizer"):
          """
          :param input: The input directory to read images from.
          :param shape: The tensor shape of the batch to prepare, either in NCHW or NHWC format.
          :param dtype: The (numpy) datatype to cast the batched data to.
          :param max_num_images: The maximum number of images to read from the directory.
          :param exact_batches: This defines how to handle a number of images that is not an exact multiple of the batch
          size. If false, it will pad the final batch with zeros to reach the batch size. If true, it will *remove* the
          last few images in excess of a batch size multiple, to guarantee batches are exact (useful for calibration).
          :param preprocessor: Set the preprocessor to use, depending on which network is being used.
          """
          # Find images in the given input path
          input = os.path.realpath(input)
          self.images = []
  
          extensions = [".jpg", ".jpeg", ".png", ".bmp"]
  
          def is_image(path):
              return os.path.isfile(path) and os.path.splitext(path)[1].lower() in extensions
  
          if os.path.isdir(input):
              self.images = [os.path.join(input, f) for f in os.listdir(input) if is_image(os.path.join(input, f))]
              self.images.sort()
          elif os.path.isfile(input):
              if is_image(input):
                  self.images.append(input)
          self.num_images = len(self.images)
          if self.num_images < 1:
              print("No valid {} images found in {}".format("/".join(extensions), input))
              sys.exit(1)
  
          # Handle Tensor Shape
          self.dtype = dtype
          self.shape = shape
          assert len(self.shape) == 4
          self.batch_size = shape[0]
          assert self.batch_size > 0
          self.format = None
          self.width = -1
          self.height = -1
          if self.shape[1] == 3:
              self.format = "NCHW"
              self.height = self.shape[2]
              self.width = self.shape[3]
          elif self.shape[3] == 3:
              self.format = "NHWC"
              self.height = self.shape[1]
              self.width = self.shape[2]
          assert all([self.format, self.width > 0, self.height > 0])
  
          # Adapt the number of images as needed
          if max_num_images and 0 < max_num_images < len(self.images):
              self.num_images = max_num_images
          if exact_batches:
              self.num_images = self.batch_size * (self.num_images // self.batch_size)
          if self.num_images < 1:
              print("Not enough images to create batches")
              sys.exit(1)
          self.images = self.images[0:self.num_images]
  
          # Subdivide the list of images into batches
          self.num_batches = 1 + int((self.num_images - 1) / self.batch_size)
          self.batches = []
          for i in range(self.num_batches):
              start = i * self.batch_size
              end = min(start + self.batch_size, self.num_images)
              self.batches.append(self.images[start:end])
  
          # Indices
          self.image_index = 0
          self.batch_index = 0
  
          self.preprocessor = preprocessor
function_tokens: def __init__ ( self , input , shape , dtype , max_num_images = None , exact_batches = False , preprocessor = "fixed_shape_resizer" ) : # Find images in the given input path input = os . path . realpath ( input ) self . images = [ ] extensions = [ ".jpg" , ".jpeg" , ".png" , ".bmp" ] def is_image ( path ) : return os . path . isfile ( path ) and os . path . splitext ( path ) [ 1 ] . lower ( ) in extensions if os . path . isdir ( input ) : self . images = [ os . path . join ( input , f ) for f in os . listdir ( input ) if is_image ( os . path . join ( input , f ) ) ] self . images . sort ( ) elif os . path . isfile ( input ) : if is_image ( input ) : self . images . append ( input ) self . num_images = len ( self . images ) if self . num_images < 1 : print ( "No valid {} images found in {}" . format ( "/" . join ( extensions ) , input ) ) sys . exit ( 1 ) # Handle Tensor Shape self . dtype = dtype self . shape = shape assert len ( self . shape ) == 4 self . batch_size = shape [ 0 ] assert self . batch_size > 0 self . format = None self . width = - 1 self . height = - 1 if self . shape [ 1 ] == 3 : self . format = "NCHW" self . height = self . shape [ 2 ] self . width = self . shape [ 3 ] elif self . shape [ 3 ] == 3 : self . format = "NHWC" self . height = self . shape [ 1 ] self . width = self . shape [ 2 ] assert all ( [ self . format , self . width > 0 , self . height > 0 ] ) # Adapt the number of images as needed if max_num_images and 0 < max_num_images < len ( self . images ) : self . num_images = max_num_images if exact_batches : self . num_images = self . batch_size * ( self . num_images // self . batch_size ) if self . num_images < 1 : print ( "Not enough images to create batches" ) sys . exit ( 1 ) self . images = self . images [ 0 : self . num_images ] # Subdivide the list of images into batches self . num_batches = 1 + int ( ( self . num_images - 1 ) / self . batch_size ) self . batches = [ ] for i in range ( self . num_batches ) : start = i * self . batch_size end = min ( start + self . batch_size , self . num_images ) self . batches . append ( self . images [ start : end ] ) # Indices self . image_index = 0 self . batch_index = 0 self . preprocessor = preprocessor