Search in sources :

Example 6 with MnistDataFetcher

use of org.deeplearning4j.datasets.fetchers.MnistDataFetcher in project deeplearning4j by deeplearning4j.

the class AutoEncoderTest method testAutoEncoder.

@Test
public void testAutoEncoder() throws Exception {
    MnistDataFetcher fetcher = new MnistDataFetcher(true);
    NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder().momentum(0.9f).optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).iterations(1).learningRate(1e-1f).layer(new org.deeplearning4j.nn.conf.layers.AutoEncoder.Builder().nIn(784).nOut(600).corruptionLevel(0.6).lossFunction(LossFunctions.LossFunction.RECONSTRUCTION_CROSSENTROPY).build()).build();
    fetcher.fetch(100);
    DataSet d2 = fetcher.next();
    INDArray input = d2.getFeatureMatrix();
    int numParams = conf.getLayer().initializer().numParams(conf);
    INDArray params = Nd4j.create(1, numParams);
    AutoEncoder da = (AutoEncoder) conf.getLayer().instantiate(conf, Arrays.<IterationListener>asList(new ScoreIterationListener(1)), 0, params, true);
    assertEquals(da.params(), da.params());
    assertEquals(471784, da.params().length());
    da.setParams(da.params());
    da.fit(input);
}
Also used : MnistDataFetcher(org.deeplearning4j.datasets.fetchers.MnistDataFetcher) INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataSet(org.nd4j.linalg.dataset.DataSet) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) IterationListener(org.deeplearning4j.optimize.api.IterationListener) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) Test(org.junit.Test)

Aggregations

MnistDataFetcher (org.deeplearning4j.datasets.fetchers.MnistDataFetcher)6 Test (org.junit.Test)5 DataSet (org.nd4j.linalg.dataset.DataSet)5 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)4 INDArray (org.nd4j.linalg.api.ndarray.INDArray)4 ScoreIterationListener (org.deeplearning4j.optimize.listeners.ScoreIterationListener)3 HistogramIterationListener (org.deeplearning4j.ui.weights.HistogramIterationListener)2 IOException (java.io.IOException)1 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)1 NormalDistribution (org.deeplearning4j.nn.conf.distribution.NormalDistribution)1 DefaultGradient (org.deeplearning4j.nn.gradient.DefaultGradient)1 Gradient (org.deeplearning4j.nn.gradient.Gradient)1 AutoEncoder (org.deeplearning4j.nn.layers.feedforward.autoencoder.AutoEncoder)1 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)1 IterationListener (org.deeplearning4j.optimize.api.IterationListener)1 Distribution (org.nd4j.linalg.api.rng.distribution.Distribution)1