Loading the data

Deeplearning4j provides the MNIST dataset loader out of the box. The loader is initialized as DataSetIterator. First let's import the DataSetIterator class and all of the supported datasets that are part of the impl package, for example, iris, MNIST, and others:

import org.deeplearning4j.datasets.iterator.DataSetIterator; 
import org.deeplearning4j.datasets.iterator.impl.*; 

Next, we'll define some constants, for instance, the images consist of 28 x 28 pixels and there are 10 target classes and 60,000 samples. We'll initialize a new MnistDataSetIterator class that will download the dataset and its labels. The parameters are the iteration batch size, total number of examples, and whether the datasets should be binarized or not:

int numRows = 28; 
int numColumns = 28; 
int outputNum = 10;
int numSamples = 60000;
int batchSize = 100;
int iterations = 10;
int seed = 123; DataSetIterator iter = new MnistDataSetIterator(batchSize, numSamples,true);

Having an already-implemented data importer is really convenient, but it won't work on your data. Let's take a quick look at how it is implemented and what needs to be modified to support your dataset. If you're eager to start implementing neural networks, you can safely skip the rest of this section and return to it when you need to import your own data.

To load the custom data, you'll need to implement two classes: DataSetIterator, which holds all of the information about the dataset, and BaseDataFetcher, which actually pulls the data either from a file, database, or the web. Sample implementations are available on GitHub at https://github.com/deeplearning4j/deeplearning4j/tree/master/deeplearning4j-core/src/main/java/org/deeplearning4j/datasets/iterator/impl
Another option is to use the Canova library, which was developed by the same authors, at http://deeplearning4j.org/canovadoc/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.188.121