Class ImageDataset
java.lang.Object
smile.vision.ImageDataset
- All Implemented Interfaces:
AutoCloseable, Iterable<SampleBatch>, 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 Summary
ConstructorsConstructorDescriptionImageDataset(String root, int batch, Transform transform, ToIntFunction<String> targetTransform) Constructor.ImageDataset(ArrayList<Path> images, int batch, Transform transform, ToIntFunction<String> targetTransform) Constructor. -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
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
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:
closein interfaceAutoCloseable
-
size
-
iterator
- Specified by:
iteratorin interfaceIterable<SampleBatch>
-