Folder Image Loader API — MCT Documentation: ver 1.0.0

# Folder Image Loader API

The following API can be used to load a folder of images to create a representative dataset for PTQ calibration

class model_compression_toolkit.FolderImageLoader(folder, preprocessing, batch_size, file_types=FILETYPES)

  Class for images loading, processing and retrieving.

  Initialize a FolderImageLoader object.

  Parameters

    - folder (str) – Path of folder with images to load. The path have to be exist, and have to contain at

    - image. (least one) –

    - preprocessing (List[Callable]) – List of functions to use when processing the images before retrieving them.

    - batch_size (int) – Number of images to retrieve each sample.

    - file_types (List[str]) – Files types to scan in the folder. Default list is `FILETYPES`

  Examples

  Instantiate a FolderImageLoader using a directory of images, that returns 10 images randomly each time it is sampled:

      >>> image_data_loader = FolderImageLoader('path/to/images/directory', preprocessing=[], batch_size=10)
      >>> images = image_data_loader.sample()

  To preprocess the images before retrieving them, a list of preprocessing methods can be passed:

      >>> image_data_loader = FolderImageLoader('path/to/images/directory', preprocessing=[lambda x: (x-127.5)/127.5], batch_size=10)

  For the FolderImageLoader to scan only specific files extensions, a list of extensions can be passed:

      >>> image_data_loader = FolderImageLoader('path/to/images/directory', preprocessing=[], batch_size=10, file_types=['png'])

  sample()

    Returns: A sample of batch_size images from the folder the FolderImageLoader scanned.

# Default file types to scan

model_compression_toolkit.common.data_loader.FILETYPES = ['jpeg', 'jpg', 'bmp', 'png']