Class AbstractImageFolder
- java.lang.Object
-
- ai.djl.training.dataset.RandomAccessDataset
-
- ai.djl.basicdataset.cv.ImageDataset
-
- ai.djl.basicdataset.cv.classification.ImageClassificationDataset
-
- ai.djl.basicdataset.cv.classification.AbstractImageFolder
-
- 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
ImageFolderinstead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractImageFolder.ImageFolderBuilder<T extends AbstractImageFolder.ImageFolderBuilder<T>>Used to build anAbstractImageFolder.-
Nested classes/interfaces inherited from class ai.djl.basicdataset.cv.ImageDataset
ImageDataset.BaseBuilder<T extends ImageDataset.BaseBuilder<T>>
-
-
Field Summary
Fields Modifier and Type Field Description protected ai.djl.util.PairList<java.lang.String,java.lang.Integer>itemsprotected ai.djl.repository.MRLmrlprotected booleanpreparedprotected java.util.List<java.lang.String>synset-
Fields inherited from class ai.djl.basicdataset.cv.ImageDataset
flag
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractImageFolder(AbstractImageFolder.ImageFolderBuilder<?> builder)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected longavailableSize()java.util.List<java.lang.String>getClasses()Returns the classes that the images in the dataset are classified into.protected longgetClassNumber(long index)Returns the class of the data item at the given index.protected ai.djl.modality.cv.ImagegetImage(long index)Returns the image at the given index in the dataset.java.util.Optional<java.lang.Integer>getImageHeight()Returns the height of the images in the dataset.protected abstract java.nio.file.PathgetImagePath(java.lang.String key)java.util.Optional<java.lang.Integer>getImageWidth()Returns the width of the images in the dataset.java.util.List<java.lang.String>getSynset()Returns the synsets of the ImageFolder dataset.protected voidlistImages(java.nio.file.Path root, java.util.List<java.lang.String> classes)-
Methods inherited from class ai.djl.basicdataset.cv.classification.ImageClassificationDataset
get, matchingTranslatorOptions
-
Methods inherited from class ai.djl.basicdataset.cv.ImageDataset
getImageChannels, getRecordImage
-
Methods inherited from class ai.djl.training.dataset.RandomAccessDataset
getData, getData, getData, getData, newSubDataset, newSubDataset, randomSplit, size, subDataset, subDataset, subDataset, subDataset, toArray
-
-
-
-
Constructor Detail
-
AbstractImageFolder
protected AbstractImageFolder(AbstractImageFolder.ImageFolderBuilder<?> builder)
-
-
Method Detail
-
getImage
protected ai.djl.modality.cv.Image getImage(long index) throws java.io.IOExceptionReturns the image at the given index in the dataset.- Specified by:
getImagein classImageDataset- 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
-
getClassNumber
protected long getClassNumber(long index)
Returns the class of the data item at the given index.- Specified by:
getClassNumberin classImageClassificationDataset- 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:
availableSizein classai.djl.training.dataset.RandomAccessDataset
-
getSynset
public java.util.List<java.lang.String> getSynset() throws java.io.IOException, ai.djl.translate.TranslateExceptionReturns the synsets of the ImageFolder dataset.- Returns:
- a list that contains synsets
- Throws:
java.io.IOException- for various exceptions depending on the datasetai.djl.translate.TranslateException- if there is an error while processing input
-
listImages
protected void listImages(java.nio.file.Path root, java.util.List<java.lang.String> classes)
-
getImagePath
protected abstract java.nio.file.Path getImagePath(java.lang.String key)
-
getImageWidth
public java.util.Optional<java.lang.Integer> getImageWidth()
Returns the width of the images in the dataset.- Specified by:
getImageWidthin classImageDataset- Returns:
- the width of the images in the dataset
-
getImageHeight
public java.util.Optional<java.lang.Integer> getImageHeight()
Returns the height of the images in the dataset.- Specified by:
getImageHeightin classImageDataset- Returns:
- the height of the images in the dataset
-
getClasses
public java.util.List<java.lang.String> getClasses()
Returns the classes that the images in the dataset are classified into.- Specified by:
getClassesin classImageClassificationDataset- Returns:
- the classes that the images in the dataset are classified into
-
-