Search in sources :

Example 16 with IterationListener

use of org.deeplearning4j.optimize.api.IterationListener in project deeplearning4j by deeplearning4j.

the class TestListenerSetting method testSettingListenersUnsupervised.

@Test
public void testSettingListenersUnsupervised() {
    //Pretrain layers should get copies of the listeners, in addition to the
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new RBM.Builder().nIn(10).nOut(10).build()).layer(1, new AutoEncoder.Builder().nIn(10).nOut(10).build()).layer(2, new VariationalAutoencoder.Builder().nIn(10).nOut(10).build()).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    net.setListeners(new ScoreIterationListener(), new TestRoutingListener());
    for (Layer l : net.getLayers()) {
        Collection<IterationListener> layerListeners = l.getListeners();
        assertEquals(l.getClass().toString(), 2, layerListeners.size());
        IterationListener[] lArr = layerListeners.toArray(new IterationListener[2]);
        assertTrue(lArr[0] instanceof ScoreIterationListener);
        assertTrue(lArr[1] instanceof TestRoutingListener);
    }
    Collection<IterationListener> netListeners = net.getListeners();
    assertEquals(2, netListeners.size());
    IterationListener[] lArr = netListeners.toArray(new IterationListener[2]);
    assertTrue(lArr[0] instanceof ScoreIterationListener);
    assertTrue(lArr[1] instanceof TestRoutingListener);
    ComputationGraphConfiguration gConf = new NeuralNetConfiguration.Builder().graphBuilder().addInputs("in").addLayer("0", new RBM.Builder().nIn(10).nOut(10).build(), "in").addLayer("1", new AutoEncoder.Builder().nIn(10).nOut(10).build(), "0").addLayer("2", new VariationalAutoencoder.Builder().nIn(10).nOut(10).build(), "1").setOutputs("2").build();
    ComputationGraph cg = new ComputationGraph(gConf);
    cg.init();
    cg.setListeners(new ScoreIterationListener(), new TestRoutingListener());
    for (Layer l : cg.getLayers()) {
        Collection<IterationListener> layerListeners = l.getListeners();
        assertEquals(2, layerListeners.size());
        lArr = layerListeners.toArray(new IterationListener[2]);
        assertTrue(lArr[0] instanceof ScoreIterationListener);
        assertTrue(lArr[1] instanceof TestRoutingListener);
    }
    netListeners = cg.getListeners();
    assertEquals(2, netListeners.size());
    lArr = netListeners.toArray(new IterationListener[2]);
    assertTrue(lArr[0] instanceof ScoreIterationListener);
    assertTrue(lArr[1] instanceof TestRoutingListener);
}
Also used : VariationalAutoencoder(org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) Layer(org.deeplearning4j.nn.api.Layer) MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) RoutingIterationListener(org.deeplearning4j.api.storage.listener.RoutingIterationListener) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) IterationListener(org.deeplearning4j.optimize.api.IterationListener) ComputationGraphConfiguration(org.deeplearning4j.nn.conf.ComputationGraphConfiguration) RBM(org.deeplearning4j.nn.conf.layers.RBM) ComputationGraph(org.deeplearning4j.nn.graph.ComputationGraph) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) AutoEncoder(org.deeplearning4j.nn.conf.layers.AutoEncoder) Test(org.junit.Test)

Example 17 with IterationListener

use of org.deeplearning4j.optimize.api.IterationListener in project deeplearning4j by deeplearning4j.

the class TestParamAndGradientIterationListener method test.

@Test
public void test() {
    IrisDataSetIterator iter = new IrisDataSetIterator(30, 150);
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).learningRate(1e-5).iterations(1).list().layer(0, new DenseLayer.Builder().nIn(4).nOut(20).build()).layer(1, new DenseLayer.Builder().nIn(20).nOut(30).build()).layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation(Activation.SOFTMAX).nIn(30).nOut(3).build()).pretrain(false).backprop(true).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    IterationListener listener = ParamAndGradientIterationListener.builder().outputToFile(true).file(new File(System.getProperty("java.io.tmpdir") + "/paramAndGradTest.txt")).outputToConsole(true).outputToLogger(false).iterations(2).printHeader(true).printMean(false).printMinMax(false).printMeanAbsValue(true).delimiter("\t").build();
    net.setListeners(listener);
    for (int i = 0; i < 2; i++) {
        net.fit(iter);
    }
}
Also used : MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) DenseLayer(org.deeplearning4j.nn.conf.layers.DenseLayer) ParamAndGradientIterationListener(org.deeplearning4j.optimize.listeners.ParamAndGradientIterationListener) IterationListener(org.deeplearning4j.optimize.api.IterationListener) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) File(java.io.File) Test(org.junit.Test)

Example 18 with IterationListener

use of org.deeplearning4j.optimize.api.IterationListener in project deeplearning4j by deeplearning4j.

the class ComputationGraph method setListeners.

/**
     * Set the IterationListeners for the ComputationGraph (and all layers in the network)
     */
public void setListeners(IterationListener... listeners) {
    List<IterationListener> list = new ArrayList<>();
    //This results in an IterationListener[1] with a single null value -> results in a NPE later
    if (listeners != null && listeners.length > 0) {
        for (IterationListener i : listeners) {
            if (i != null)
                list.add(i);
        }
    }
    setListeners(list);
}
Also used : IterationListener(org.deeplearning4j.optimize.api.IterationListener)

Example 19 with IterationListener

use of org.deeplearning4j.optimize.api.IterationListener in project deeplearning4j by deeplearning4j.

the class ComputationGraph method setListeners.

/**
     * Set the IterationListeners for the ComputationGraph (and all layers in the network)
     */
public void setListeners(Collection<IterationListener> listeners) {
    this.listeners = listeners;
    if (layers == null)
        init();
    for (Layer l : layers) {
        l.setListeners(listeners);
    }
    if (solver != null) {
        solver.setListeners(listeners);
    }
    this.trainingListeners.clear();
    if (listeners != null) {
        for (IterationListener il : listeners) {
            if (il instanceof TrainingListener) {
                this.trainingListeners.add((TrainingListener) il);
            }
        }
    }
}
Also used : IterationListener(org.deeplearning4j.optimize.api.IterationListener) TrainingListener(org.deeplearning4j.optimize.api.TrainingListener) Layer(org.deeplearning4j.nn.api.Layer) FrozenLayer(org.deeplearning4j.nn.layers.FrozenLayer) RecurrentLayer(org.deeplearning4j.nn.api.layers.RecurrentLayer) FeedForwardLayer(org.deeplearning4j.nn.conf.layers.FeedForwardLayer) IOutputLayer(org.deeplearning4j.nn.api.layers.IOutputLayer)

Example 20 with IterationListener

use of org.deeplearning4j.optimize.api.IterationListener in project deeplearning4j by deeplearning4j.

the class MultiLayerNetwork method setListeners.

@Override
public void setListeners(Collection<IterationListener> listeners) {
    this.listeners = listeners;
    if (layers == null) {
        init();
    }
    for (Layer layer : layers) {
        layer.setListeners(listeners);
    }
    if (solver != null) {
        solver.setListeners(listeners);
    }
    this.trainingListeners.clear();
    if (listeners != null) {
        for (IterationListener il : listeners) {
            if (il instanceof TrainingListener) {
                this.trainingListeners.add((TrainingListener) il);
            }
        }
    }
}
Also used : IterationListener(org.deeplearning4j.optimize.api.IterationListener) TrainingListener(org.deeplearning4j.optimize.api.TrainingListener) FeedForwardLayer(org.deeplearning4j.nn.conf.layers.FeedForwardLayer) FrozenLayer(org.deeplearning4j.nn.layers.FrozenLayer) IOutputLayer(org.deeplearning4j.nn.api.layers.IOutputLayer) RecurrentLayer(org.deeplearning4j.nn.api.layers.RecurrentLayer)

Aggregations

IterationListener (org.deeplearning4j.optimize.api.IterationListener)24 ScoreIterationListener (org.deeplearning4j.optimize.listeners.ScoreIterationListener)15 Test (org.junit.Test)15 DataSet (org.nd4j.linalg.dataset.DataSet)12 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)11 INDArray (org.nd4j.linalg.api.ndarray.INDArray)9 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)7 IrisDataSetIterator (org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator)6 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)5 DataSetIterator (org.nd4j.linalg.dataset.api.iterator.DataSetIterator)5 RoutingIterationListener (org.deeplearning4j.api.storage.listener.RoutingIterationListener)4 Evaluation (org.deeplearning4j.eval.Evaluation)4 OptimizationAlgorithm (org.deeplearning4j.nn.api.OptimizationAlgorithm)4 Layer (org.deeplearning4j.nn.api.Layer)3 RnnOutputLayer (org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer)3 SplitTestAndTrain (org.nd4j.linalg.dataset.SplitTestAndTrain)3 Serializable (java.io.Serializable)2 StatsStorageRouterProvider (org.deeplearning4j.api.storage.StatsStorageRouterProvider)2 IOutputLayer (org.deeplearning4j.nn.api.layers.IOutputLayer)2 RecurrentLayer (org.deeplearning4j.nn.api.layers.RecurrentLayer)2