Class ImageDataset

java.lang.Object
smile.vision.ImageDataset
All Implemented Interfaces:
AutoCloseable, Iterable<SampleBatch>, Dataset

public class ImageDataset extends Object implements Dataset
Each of these directories should contain one subdirectory for each class in the dataset. The subdirectories are named after the corresponding class and contain all the images for that class. Ensure that each image file is named uniquely and stored in a common format such as JPEG or PNG.
  • Constructor Details

    • ImageDataset

      public ImageDataset(String root, int batch, Transform transform, ToIntFunction<String> targetTransform) throws IOException
      Constructor.
      Parameters:
      root - the root directory of image dataset.
      batch - the mini-batch size.
      transform - the transformation from image to tensor.
      targetTransform - the transform from image label to class index.
      Throws:
      IOException - if the root directory doesn't exist or doesn't have images.
    • ImageDataset

      public ImageDataset(ArrayList<Path> images, int batch, Transform transform, ToIntFunction<String> targetTransform)
      Constructor.
      Parameters:
      images - the list of image files. The folder name of an image file will be used as the class label.
      batch - the mini-batch size.
      transform - the transformation from image to tensor.
      targetTransform - the transform from image label to class index.
  • Method Details

    • sample

      public ImageDataset sample(int size)
      Returns a random sample of the dataset with the given size. The sample shares the same image files and transforms with the original dataset. The sample is useful for quick testing or debugging on a smaller subset of the data.
      Parameters:
      size - the sample size.
      Returns:
      a random sample of the dataset with the given size.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • size

      public long size()
      Description copied from interface: Dataset
      Returns the size of dataset.
      Specified by:
      size in interface Dataset
      Returns:
      the size of dataset.
    • iterator

      public Iterator<SampleBatch> iterator()
      Specified by:
      iterator in interface Iterable<SampleBatch>