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);
}
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);
}
}
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);
}
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);
}
}
}
}
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);
}
}
}
}
Aggregations