### Question:
ImageFolder extends AbstractImageFolder { private ImageFolder(ImageFolderBuilder<?> builder) { super(builder); } private  ImageFolder(ImageFolderBuilder<?> builder); static Builder builder(); @Override void prepare(Progress progress);  }### Answer:
@Test public void testImageFolder() throws IOException, TranslateException { Repository repository = Repository.newInstance("test", "src/test/resources/imagefolder"); TrainingConfig config = new DefaultTrainingConfig(Loss.softmaxCrossEntropyLoss()); try (Model model = Model.newInstance("model")) { model.setBlock(Blocks.identityBlock()); ImageFolder dataset = ImageFolder.builder() .setRepository(repository) .optPipeline( new Pipeline().add(new Resize(100, 100)).add(new ToTensor())) .setSampling(1, false) .build(); List<String> synsets = Arrays.asList("cat", "dog", "misc"); Assert.assertEquals(synsets, dataset.getSynset()); try (Trainer trainer = model.newTrainer(config)) { NDManager manager = trainer.getManager(); NDArray cat = ImageFactory.getInstance() .fromFile( Paths.get("src/test/resources/imagefolder/cat/kitten.jpg")) .toNDArray(manager); NDArray dog = ImageFactory.getInstance() .fromFile( Paths.get( "src/test/resources/imagefolder/dog/dog_bike_car.jpg")) .toNDArray(manager); NDArray pikachu = ImageFactory.getInstance() .fromFile( Paths.get( "src/test/resources/imagefolder/misc/pikachu.png")) .toNDArray(manager); Iterator<Batch> ds = trainer.iterateDataset(dataset).iterator(); Batch catBatch = ds.next(); Assertions.assertAlmostEquals( catBatch.getData().singletonOrThrow(), NDImageUtils.toTensor(NDImageUtils.resize(cat, 100, 100)).expandDims(0)); Assert.assertEquals( catBatch.getLabels().singletonOrThrow(), manager.create(new int[] {0})); catBatch.close(); Batch dogBatch = ds.next(); Assertions.assertAlmostEquals( dogBatch.getData().singletonOrThrow(), NDImageUtils.toTensor(NDImageUtils.resize(dog, 100, 100)).expandDims(0)); Assert.assertEquals( dogBatch.getLabels().singletonOrThrow(), manager.create(new int[] {1})); dogBatch.close(); Batch pikachuBatch = ds.next(); Assertions.assertAlmostEquals( pikachuBatch.getData().singletonOrThrow(), NDImageUtils.toTensor(NDImageUtils.resize(pikachu, 100, 100)) .expandDims(0)); Assert.assertEquals( pikachuBatch.getLabels().singletonOrThrow(), manager.create(new int[] {2})); pikachuBatch.close(); } } }