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
ImageFolder
instead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractImageFolder.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>
items
protected ai.djl.repository.MRL
mrl
protected boolean
prepared
protected java.util.List<java.lang.String>
synset
-
Fields inherited from class ai.djl.basicdataset.cv.ImageDataset
flag
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractImageFolder(AbstractImageFolder.ImageFolderBuilder<?> builder)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected long
availableSize()
java.util.List<java.lang.String>
getClasses()
Returns the classes that the images in the dataset are classified into.protected long
getClassNumber(long index)
Returns the class of the data item at the given index.protected ai.djl.modality.cv.Image
getImage(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.Path
getImagePath(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 void
listImages(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.IOException
Returns the image at the given index in the dataset.- Specified by:
getImage
in 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:
getClassNumber
in 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:
availableSize
in classai.djl.training.dataset.RandomAccessDataset
-
getSynset
public java.util.List<java.lang.String> getSynset() throws java.io.IOException, ai.djl.translate.TranslateException
Returns 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:
getImageWidth
in 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:
getImageHeight
in 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:
getClasses
in classImageClassificationDataset
- Returns:
- the classes that the images in the dataset are classified into
-
-