For classification based on N labels, there are N subdirectories created in the parent directory. The parent directory path is mentioned for image extraction. Subdirectory names will be regarded as labels. In this recipe, we will extract images from disk using DataVec.
Extracting images from disk
How to do it...
- Use FileSplit to define the range of files to load into the neural network:
FileSplit fileSplit = new FileSplit(parentDir, NativeImageLoader.ALLOWED_FORMATS,new Random(42));
int numLabels = fileSplit.getRootDir().listFiles(File::isDirectory).length;
- Use ParentPathLabelGenerator and BalancedPathFilter to sample the labeled dataset and split it into train/test sets:
ParentPathLabelGenerator parentPathLabelGenerator...