Search in sources :

Example 1 with HistogramIterationListener

use of org.deeplearning4j.ui.weights.HistogramIterationListener in project deeplearning4j by deeplearning4j.

the class TestRenders method renderHistogram.

@Test
public void renderHistogram() throws Exception {
    MnistDataFetcher fetcher = new MnistDataFetcher(true);
    NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder().momentum(0.9f).optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).iterations(100).learningRate(1e-1f).layer(new org.deeplearning4j.nn.conf.layers.AutoEncoder.Builder().nIn(784).nOut(600).corruptionLevel(0.6).weightInit(WeightInit.XAVIER).lossFunction(LossFunctions.LossFunction.RMSE_XENT).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, null, 0, params, true);
    da.setListeners(new ScoreIterationListener(1), new HistogramIterationListener(5));
    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) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) HistogramIterationListener(org.deeplearning4j.ui.weights.HistogramIterationListener) AutoEncoder(org.deeplearning4j.nn.layers.feedforward.autoencoder.AutoEncoder) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) Test(org.junit.Test)

Example 2 with HistogramIterationListener

use of org.deeplearning4j.ui.weights.HistogramIterationListener in project deeplearning4j by deeplearning4j.

the class TestRenders method testHistogramComputationGraphUnderscoresInName.

@Test
public void testHistogramComputationGraphUnderscoresInName() throws Exception {
    ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).graphBuilder().addInputs("input").setInputTypes(InputType.convolutional(1, 28, 28)).addLayer("cnn_1", new ConvolutionLayer.Builder(2, 2).stride(2, 2).nIn(1).nOut(3).build(), "input").addLayer("cnn_2", new ConvolutionLayer.Builder(4, 4).stride(2, 2).padding(1, 1).nIn(1).nOut(3).build(), "input").addLayer("max_1", new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX).kernelSize(2, 2).build(), "cnn_1", "cnn_2").addLayer("output", new OutputLayer.Builder().nIn(7 * 7 * 6).nOut(10).build(), "max_1").setOutputs("output").pretrain(false).backprop(true).build();
    ComputationGraph graph = new ComputationGraph(conf);
    graph.init();
    graph.setListeners(new HistogramIterationListener(1), new ScoreIterationListener(1));
    DataSetIterator mnist = new MnistDataSetIterator(32, 640, false, true, false, 12345);
    graph.fit(mnist);
}
Also used : MnistDataSetIterator(org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator) ComputationGraphConfiguration(org.deeplearning4j.nn.conf.ComputationGraphConfiguration) HistogramIterationListener(org.deeplearning4j.ui.weights.HistogramIterationListener) ComputationGraph(org.deeplearning4j.nn.graph.ComputationGraph) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) MnistDataSetIterator(org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator) Test(org.junit.Test)

Example 3 with HistogramIterationListener

use of org.deeplearning4j.ui.weights.HistogramIterationListener in project deeplearning4j by deeplearning4j.

the class TestRenders method renderHistogram2.

@Test
public void renderHistogram2() throws Exception {
    MnistDataFetcher fetcher = new MnistDataFetcher(true);
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().momentum(0.9f).optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).iterations(1000).learningRate(1e-1f).list().layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(784).nOut(100).weightInit(WeightInit.XAVIER).build()).layer(1, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder().lossFunction(LossFunctions.LossFunction.MCXENT).nIn(100).nOut(10).build()).pretrain(false).backprop(true).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    net.setListeners(Arrays.<IterationListener>asList(new ScoreIterationListener(1), new HistogramIterationListener(1, true)));
    fetcher.fetch(100);
    DataSet d2 = fetcher.next();
    net.fit(d2);
}
Also used : DataSet(org.nd4j.linalg.dataset.DataSet) HistogramIterationListener(org.deeplearning4j.ui.weights.HistogramIterationListener) MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) MnistDataFetcher(org.deeplearning4j.datasets.fetchers.MnistDataFetcher) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) Test(org.junit.Test)

Example 4 with HistogramIterationListener

use of org.deeplearning4j.ui.weights.HistogramIterationListener in project deeplearning4j by deeplearning4j.

the class ManualTests method testHistograms.

@Test
public void testHistograms() throws Exception {
    final int numRows = 28;
    final int numColumns = 28;
    int outputNum = 10;
    int numSamples = 60000;
    int batchSize = 100;
    int iterations = 10;
    int seed = 123;
    int listenerFreq = batchSize / 5;
    log.info("Load data....");
    DataSetIterator iter = new MnistDataSetIterator(batchSize, numSamples, true);
    log.info("Build model....");
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(seed).gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue).gradientNormalizationThreshold(1.0).iterations(iterations).momentum(0.5).momentumAfter(Collections.singletonMap(3, 0.9)).optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).list().layer(0, new RBM.Builder().nIn(numRows * numColumns).nOut(500).weightInit(WeightInit.XAVIER).lossFunction(LossFunctions.LossFunction.KL_DIVERGENCE).visibleUnit(RBM.VisibleUnit.BINARY).hiddenUnit(RBM.HiddenUnit.BINARY).build()).layer(1, new RBM.Builder().nIn(500).nOut(250).weightInit(WeightInit.XAVIER).lossFunction(LossFunctions.LossFunction.KL_DIVERGENCE).visibleUnit(RBM.VisibleUnit.BINARY).hiddenUnit(RBM.HiddenUnit.BINARY).build()).layer(2, new RBM.Builder().nIn(250).nOut(200).weightInit(WeightInit.XAVIER).lossFunction(LossFunctions.LossFunction.KL_DIVERGENCE).visibleUnit(RBM.VisibleUnit.BINARY).hiddenUnit(RBM.HiddenUnit.BINARY).build()).layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD).activation(Activation.SOFTMAX).nIn(200).nOut(outputNum).build()).pretrain(true).backprop(false).build();
    //        UiServer server = UiServer.getInstance();
    //        UiConnectionInfo connectionInfo = server.getConnectionInfo();
    //        connectionInfo.setSessionId("my session here");
    MultiLayerNetwork model = new MultiLayerNetwork(conf);
    model.init();
    model.setListeners(Arrays.asList(new ScoreIterationListener(listenerFreq), new HistogramIterationListener(listenerFreq), new FlowIterationListener(listenerFreq)));
    log.info("Train model....");
    // achieves end to end pre-training
    model.fit(iter);
    log.info("Evaluate model....");
    Evaluation eval = new Evaluation(outputNum);
    DataSetIterator testIter = new MnistDataSetIterator(100, 10000);
    while (testIter.hasNext()) {
        DataSet testMnist = testIter.next();
        INDArray predict2 = model.output(testMnist.getFeatureMatrix());
        eval.eval(testMnist.getLabels(), predict2);
    }
    log.info(eval.stats());
    log.info("****************Example finished********************");
    fail("Not implemented");
}
Also used : Evaluation(org.deeplearning4j.eval.Evaluation) MnistDataSetIterator(org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator) DataSet(org.nd4j.linalg.dataset.DataSet) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) HistogramIterationListener(org.deeplearning4j.ui.weights.HistogramIterationListener) MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) FlowIterationListener(org.deeplearning4j.ui.flow.FlowIterationListener) INDArray(org.nd4j.linalg.api.ndarray.INDArray) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) LFWDataSetIterator(org.deeplearning4j.datasets.iterator.impl.LFWDataSetIterator) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) MnistDataSetIterator(org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator) Test(org.junit.Test)

Example 5 with HistogramIterationListener

use of org.deeplearning4j.ui.weights.HistogramIterationListener in project deeplearning4j by deeplearning4j.

the class TestRenders method testHistogramComputationGraph.

@Test
public void testHistogramComputationGraph() throws Exception {
    ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).graphBuilder().addInputs("input").addLayer("cnn1", new ConvolutionLayer.Builder(2, 2).stride(2, 2).nIn(1).nOut(3).build(), "input").addLayer("cnn2", new ConvolutionLayer.Builder(4, 4).stride(2, 2).padding(1, 1).nIn(1).nOut(3).build(), "input").addLayer("max1", new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX).kernelSize(2, 2).build(), "cnn1", "cnn2").addLayer("output", new OutputLayer.Builder().nIn(7 * 7 * 6).nOut(10).build(), "max1").setOutputs("output").inputPreProcessor("cnn1", new FeedForwardToCnnPreProcessor(28, 28, 1)).inputPreProcessor("cnn2", new FeedForwardToCnnPreProcessor(28, 28, 1)).inputPreProcessor("output", new CnnToFeedForwardPreProcessor(7, 7, 6)).pretrain(false).backprop(true).build();
    ComputationGraph graph = new ComputationGraph(conf);
    graph.init();
    graph.setListeners(new HistogramIterationListener(1), new ScoreIterationListener(1));
    DataSetIterator mnist = new MnistDataSetIterator(32, 640, false, true, false, 12345);
    graph.fit(mnist);
}
Also used : OutputLayer(org.deeplearning4j.nn.conf.layers.OutputLayer) CnnToFeedForwardPreProcessor(org.deeplearning4j.nn.conf.preprocessor.CnnToFeedForwardPreProcessor) SubsamplingLayer(org.deeplearning4j.nn.conf.layers.SubsamplingLayer) MnistDataSetIterator(org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator) HistogramIterationListener(org.deeplearning4j.ui.weights.HistogramIterationListener) ConvolutionLayer(org.deeplearning4j.nn.conf.layers.ConvolutionLayer) ComputationGraphConfiguration(org.deeplearning4j.nn.conf.ComputationGraphConfiguration) FeedForwardToCnnPreProcessor(org.deeplearning4j.nn.conf.preprocessor.FeedForwardToCnnPreProcessor) ComputationGraph(org.deeplearning4j.nn.graph.ComputationGraph) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) MnistDataSetIterator(org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator) Test(org.junit.Test)

Aggregations

ScoreIterationListener (org.deeplearning4j.optimize.listeners.ScoreIterationListener)6 HistogramIterationListener (org.deeplearning4j.ui.weights.HistogramIterationListener)6 Test (org.junit.Test)6 DataSet (org.nd4j.linalg.dataset.DataSet)4 MnistDataSetIterator (org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator)3 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)3 INDArray (org.nd4j.linalg.api.ndarray.INDArray)3 DataSetIterator (org.nd4j.linalg.dataset.api.iterator.DataSetIterator)3 MnistDataFetcher (org.deeplearning4j.datasets.fetchers.MnistDataFetcher)2 ComputationGraphConfiguration (org.deeplearning4j.nn.conf.ComputationGraphConfiguration)2 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)2 ComputationGraph (org.deeplearning4j.nn.graph.ComputationGraph)2 AutoEncoder (org.deeplearning4j.nn.layers.feedforward.autoencoder.AutoEncoder)2 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IrisDataSetIterator (org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator)1 LFWDataSetIterator (org.deeplearning4j.datasets.iterator.impl.LFWDataSetIterator)1 Evaluation (org.deeplearning4j.eval.Evaluation)1 ConvolutionLayer (org.deeplearning4j.nn.conf.layers.ConvolutionLayer)1 OutputLayer (org.deeplearning4j.nn.conf.layers.OutputLayer)1