Example usage for org.deeplearning4j.base MnistFetcher MnistFetcher

List of usage examples for org.deeplearning4j.base MnistFetcher MnistFetcher

Introduction

In this page you can find the example usage for org.deeplearning4j.base MnistFetcher MnistFetcher.

Prototype

MnistFetcher

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();
    }//from  w w  w  .  j av a  2 s .co 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
}