Example usage for org.deeplearning4j.datasets.mnist MnistManager MnistManager

List of usage examples for org.deeplearning4j.datasets.mnist MnistManager MnistManager

Introduction

In this page you can find the example usage for org.deeplearning4j.datasets.mnist MnistManager MnistManager.

Prototype

public MnistManager(String imagesFile, String labelsFile, int numExamples) throws IOException 

Source Link

Usage

From source file:com.jiantsing.test.MyMnistDataFetcher.java

License:Apache License

public MyMnistDataFetcher(boolean binarize, boolean train, boolean shuffle, long rngSeed) throws IOException {
    //        System.out.println("111");
    if (!mnistExists()) {
        //           System.out.println("2222");
        new MnistFetcher().downloadAndUntar();
    }// w ww .j  ava  2  s .  c  o  m
    String images;
    String labels;
    if (train) {
        images = MNIST_ROOT + MnistFetcher.trainingFilesFilename_unzipped;
        labels = MNIST_ROOT + MnistFetcher.trainingFileLabelsFilename_unzipped;
        totalExamples = NUM_EXAMPLES;
    } else {
        images = MNIST_ROOT + MnistFetcher.testFilesFilename_unzipped;
        labels = MNIST_ROOT + MnistFetcher.testFileLabelsFilename_unzipped;
        totalExamples = NUM_EXAMPLES_TEST;
    }

    try {
        man = new MnistManager(images, labels, train);
    } catch (Exception e) {
        FileUtils.deleteDirectory(new File(MNIST_ROOT));
        new MnistFetcher().downloadAndUntar();
        man = new MnistManager(images, labels, train);
    }

    numOutcomes = 10;
    this.binarize = binarize;
    cursor = 0;
    inputColumns = man.getImages().getEntryLength();
    this.train = train;
    this.shuffle = shuffle;

    if (train) {
        order = new int[NUM_EXAMPLES];
    } else {
        order = new int[NUM_EXAMPLES_TEST];
    }
    for (int i = 0; i < order.length; i++)
        order[i] = i;
    rng = new Random(rngSeed);
    reset(); //Shuffle order
}