Class AbstractImageFolder

java.lang.Object
ai.djl.training.dataset.RandomAccessDataset
All Implemented Interfaces:
ai.djl.training.dataset.Dataset
Direct Known Subclasses:
FruitsFreshAndRotten, ImageFolder, ImageNet

public abstract class AbstractImageFolder extends ImageClassificationDataset
A dataset for loading image files stored in a folder structure.

Usually, you want to use ImageFolder instead.

  • Field Details

    • synset

      protected List<String> synset
    • items

      protected ai.djl.util.PairList<String,Integer> items
    • mrl

      protected ai.djl.repository.MRL mrl
    • prepared

      protected boolean prepared
  • Constructor Details

  • Method Details

    • getImage

      protected ai.djl.modality.cv.Image getImage(long index) throws IOException
      Returns the image at the given index in the dataset.
      Specified by:
      getImage in class ImageDataset
      Parameters:
      index - the index (if the dataset is a list of data items)
      Returns:
      the image
      Throws:
      IOException - if the image could not be loaded
    • getClassNumber

      protected long getClassNumber(long index)
      Returns the class of the data item at the given index.
      Specified by:
      getClassNumber in class ImageClassificationDataset
      Parameters:
      index - the index (if the dataset is a list of data items)
      Returns:
      the class number or the index into the list of classes of the desired class name
    • availableSize

      protected long availableSize()
      Specified by:
      availableSize in class ai.djl.training.dataset.RandomAccessDataset
    • getSynset

      public List<String> getSynset() throws IOException, ai.djl.translate.TranslateException
      Returns the synsets of the ImageFolder dataset.
      Returns:
      a list that contains synsets
      Throws:
      IOException - for various exceptions depending on the dataset
      ai.djl.translate.TranslateException - if there is an error while processing input
    • listImages

      protected void listImages(Path root, List<String> classes)
    • getImagePath

      protected abstract Path getImagePath(String key)
    • isImage

      protected boolean isImage(File file)
    • getImageWidth

      public Optional<Integer> getImageWidth()
      Returns the width of the images in the dataset.
      Specified by:
      getImageWidth in class ImageDataset
      Returns:
      the width of the images in the dataset
    • getImageHeight

      public Optional<Integer> getImageHeight()
      Returns the height of the images in the dataset.
      Specified by:
      getImageHeight in class ImageDataset
      Returns:
      the height of the images in the dataset
    • getClasses

      public List<String> getClasses()
      Returns the classes that the images in the dataset are classified into.
      Specified by:
      getClasses in class ImageClassificationDataset
      Returns:
      the classes that the images in the dataset are classified into