Class ImageDataset

  • All Implemented Interfaces:
    ai.djl.training.dataset.Dataset
    Direct Known Subclasses:
    ImageClassificationDataset, ObjectDetectionDataset

    public abstract class ImageDataset
    extends ai.djl.training.dataset.RandomAccessDataset
    A helper to create a Dataset where the data contains a single image.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ai.djl.modality.cv.Image.Flag flag  
      • Fields inherited from class ai.djl.training.dataset.RandomAccessDataset

        dataBatchifier, device, labelBatchifier, limit, pipeline, prefetchNumber, sampler, targetPipeline
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageDataset​(ImageDataset.BaseBuilder<?> builder)
      Creates a new instance of RandomAccessDataset with the given necessary configurations.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract ai.djl.modality.cv.Image getImage​(long index)
      Returns the image at the given index in the dataset.
      int getImageChannels()
      Returns the number of channels in the images in the dataset.
      abstract java.util.Optional<java.lang.Integer> getImageHeight()
      Returns the height of the images in the dataset.
      abstract java.util.Optional<java.lang.Integer> getImageWidth()
      Returns the width of the images in the dataset.
      protected ai.djl.ndarray.NDArray getRecordImage​(ai.djl.ndarray.NDManager manager, long index)  
      • Methods inherited from class ai.djl.training.dataset.RandomAccessDataset

        availableSize, get, getData, getData, getData, getData, newSubDataset, newSubDataset, randomSplit, size, subDataset, subDataset, subDataset, subDataset, toArray
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface ai.djl.training.dataset.Dataset

        matchingTranslatorOptions, prepare, prepare
    • Field Detail

      • flag

        protected ai.djl.modality.cv.Image.Flag flag
    • Constructor Detail

      • ImageDataset

        public ImageDataset​(ImageDataset.BaseBuilder<?> builder)
        Creates a new instance of RandomAccessDataset with the given necessary configurations.
        Parameters:
        builder - a builder with the necessary configurations
    • Method Detail

      • getRecordImage

        protected ai.djl.ndarray.NDArray getRecordImage​(ai.djl.ndarray.NDManager manager,
                                                        long index)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getImage

        protected abstract ai.djl.modality.cv.Image getImage​(long index)
                                                      throws java.io.IOException
        Returns the image at the given index in the dataset.
        Parameters:
        index - the index (if the dataset is a list of data items)
        Returns:
        the image
        Throws:
        java.io.IOException - if the image could not be loaded
      • getImageChannels

        public int getImageChannels()
        Returns the number of channels in the images in the dataset.

        For example, RGB would be 3 channels while grayscale only uses 1 channel.

        Returns:
        the number of channels in the images in the dataset
      • getImageWidth

        public abstract java.util.Optional<java.lang.Integer> getImageWidth()
        Returns the width of the images in the dataset.
        Returns:
        the width of the images in the dataset
      • getImageHeight

        public abstract java.util.Optional<java.lang.Integer> getImageHeight()
        Returns the height of the images in the dataset.
        Returns:
        the height of the images in the dataset