Refactoring and separation of IModel / Layer
parent
42fb4bd48e
commit
d592e02852
|
@ -205,7 +205,7 @@ public class TupleStreamDataSetIteratorTest extends SolrCloudTestCase {
|
||||||
public void modelFitTest() throws Exception {
|
public void modelFitTest() throws Exception {
|
||||||
|
|
||||||
final MultiLayerNetwork model = new MultiLayerNetwork(
|
final MultiLayerNetwork model = new MultiLayerNetwork(
|
||||||
new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.builder()
|
||||||
.list(
|
.list(
|
||||||
new OutputLayer.Builder(LossFunction.MSE)
|
new OutputLayer.Builder(LossFunction.MSE)
|
||||||
.nIn(3)
|
.nIn(3)
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||||
import org.apache.solr.cloud.SolrCloudTestCase;
|
import org.apache.solr.cloud.SolrCloudTestCase;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import org.deeplearning4j.nn.api.Model;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
@ -153,7 +153,7 @@ public class ModelTupleStreamIntegrationTest extends SolrCloudTestCase {
|
||||||
final int numInputs = 3;
|
final int numInputs = 3;
|
||||||
final int numOutputs = 2;
|
final int numOutputs = 2;
|
||||||
|
|
||||||
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list(
|
.list(
|
||||||
new OutputLayer.Builder()
|
new OutputLayer.Builder()
|
||||||
.nIn(numInputs)
|
.nIn(numInputs)
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.solr.core.SolrResourceLoader;
|
||||||
import org.apache.solr.handler.SolrDefaultStreamFactory;
|
import org.apache.solr.handler.SolrDefaultStreamFactory;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import org.deeplearning4j.nn.api.Model;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
|
@ -242,7 +242,7 @@ public class ModelTupleStreamTest {
|
||||||
|
|
||||||
protected Model buildMultiLayerNetworkModel(int numInputs, int numOutputs) throws Exception {
|
protected Model buildMultiLayerNetworkModel(int numInputs, int numOutputs) throws Exception {
|
||||||
|
|
||||||
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list(
|
.list(
|
||||||
new OutputLayer.Builder()
|
new OutputLayer.Builder()
|
||||||
.nIn(numInputs)
|
.nIn(numInputs)
|
||||||
|
@ -274,7 +274,7 @@ public class ModelTupleStreamTest {
|
||||||
|
|
||||||
protected Model buildComputationGraphModel(int numInputs, int numOutputs) throws Exception {
|
protected Model buildComputationGraphModel(int numInputs, int numOutputs) throws Exception {
|
||||||
|
|
||||||
final ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
final ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("inputLayer")
|
.addInputs("inputLayer")
|
||||||
.addLayer("outputLayer",
|
.addLayer("outputLayer",
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.apache.solr.ltr.norm.Normalizer;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import org.deeplearning4j.nn.api.Model;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
|
@ -192,7 +192,7 @@ public class ScoringModelTest {
|
||||||
|
|
||||||
protected Model buildMultiLayerNetworkModel(int numFeatures) throws Exception {
|
protected Model buildMultiLayerNetworkModel(int numFeatures) throws Exception {
|
||||||
|
|
||||||
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list(
|
.list(
|
||||||
new OutputLayer.Builder().nIn(numFeatures).nOut(1).lossFunction(LossFunctions.LossFunction.MSE).activation(Activation.IDENTITY).build()
|
new OutputLayer.Builder().nIn(numFeatures).nOut(1).lossFunction(LossFunctions.LossFunction.MSE).activation(Activation.IDENTITY).build()
|
||||||
)
|
)
|
||||||
|
@ -217,7 +217,7 @@ public class ScoringModelTest {
|
||||||
|
|
||||||
protected Model buildComputationGraphModel(int numFeatures) throws Exception {
|
protected Model buildComputationGraphModel(int numFeatures) throws Exception {
|
||||||
|
|
||||||
final ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
final ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("inputLayer")
|
.addInputs("inputLayer")
|
||||||
.addLayer("outputLayer",
|
.addLayer("outputLayer",
|
||||||
|
|
|
@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.graph.MergeVertex;
|
import org.deeplearning4j.nn.conf.graph.MergeVertex;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.*;
|
||||||
|
@ -70,7 +70,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
|
||||||
private static final MultiLayerNetwork model;
|
private static final MultiLayerNetwork model;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
val conf = new NeuralNetConfiguration.Builder()
|
val conf = NeuralNetConfiguration.builder()
|
||||||
.seed(119)
|
.seed(119)
|
||||||
.updater(new Adam(0.119f))
|
.updater(new Adam(0.119f))
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
@ -541,7 +541,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMlnMnist() throws Exception {
|
public void testMlnMnist() throws Exception {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
.list()
|
||||||
.layer(new DenseLayer.Builder().nIn(784).nOut(10).build())
|
.layer(new DenseLayer.Builder().nIn(784).nOut(10).build())
|
||||||
.layer(new LossLayer.Builder().activation(Activation.SOFTMAX).build())
|
.layer(new LossLayer.Builder().activation(Activation.SOFTMAX).build())
|
||||||
|
@ -597,7 +597,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCompGraph() throws Exception {
|
public void testCompGraph() throws Exception {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("input1", "input2")
|
.addInputs("input1", "input2")
|
||||||
.addLayer("L1", new DenseLayer.Builder().nIn(3).nOut(4).build(), "input1")
|
.addLayer("L1", new DenseLayer.Builder().nIn(3).nOut(4).build(), "input1")
|
||||||
|
@ -652,7 +652,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCompGraph_1() throws Exception {
|
public void testCompGraph_1() throws Exception {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.updater(new Sgd(0.01))
|
.updater(new Sgd(0.01))
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("input")
|
.addInputs("input")
|
||||||
|
|
|
@ -425,7 +425,7 @@ public class SharedTrainingWrapper {
|
||||||
.setTrainingWorkspaceMode(trainingConfiguration.getWorkspaceMode());
|
.setTrainingWorkspaceMode(trainingConfiguration.getWorkspaceMode());
|
||||||
((ComputationGraph) originalModel).setGradientsAccumulator(accumulator);
|
((ComputationGraph) originalModel).setGradientsAccumulator(accumulator);
|
||||||
} else if (model instanceof MultiLayerNetwork) {
|
} else if (model instanceof MultiLayerNetwork) {
|
||||||
((MultiLayerNetwork) originalModel).getLayerWiseConfigurations()
|
((MultiLayerNetwork) originalModel).getConfiguration()
|
||||||
.setTrainingWorkspaceMode(trainingConfiguration.getWorkspaceMode());
|
.setTrainingWorkspaceMode(trainingConfiguration.getWorkspaceMode());
|
||||||
((MultiLayerNetwork) originalModel).setGradientsAccumulator(accumulator);
|
((MultiLayerNetwork) originalModel).setGradientsAccumulator(accumulator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,7 @@ public class SharedTrainingMaster extends BaseTrainingMaster<SharedTrainingResul
|
||||||
/*
|
/*
|
||||||
Here we're going create our worker, which will be passed into corresponding FlatMapFunction
|
Here we're going create our worker, which will be passed into corresponding FlatMapFunction
|
||||||
*/
|
*/
|
||||||
NetBroadcastTuple tuple = new NetBroadcastTuple(network.getNetwork().getLayerWiseConfigurations(),
|
NetBroadcastTuple tuple = new NetBroadcastTuple(network.getNetwork().getConfiguration(),
|
||||||
network.getNetwork().params(), network.getNetwork().getUpdater().getStateViewArray());
|
network.getNetwork().params(), network.getNetwork().getUpdater().getStateViewArray());
|
||||||
|
|
||||||
voidConfiguration.setUnicastControllerPort(voidConfiguration.getPortSupplier().getPort());
|
voidConfiguration.setUnicastControllerPort(voidConfiguration.getPortSupplier().getPort());
|
||||||
|
|
|
@ -24,7 +24,7 @@ import lombok.Getter;
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.core.storage.StatsStorageRouter;
|
import org.deeplearning4j.core.storage.StatsStorageRouter;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.optimize.api.TrainingListener;
|
import org.deeplearning4j.optimize.api.TrainingListener;
|
||||||
|
@ -91,7 +91,7 @@ public class SharedTrainingWorker extends BaseTrainingWorker<SharedTrainingResul
|
||||||
|
|
||||||
NetBroadcastTuple tuple = broadcastModel.getValue();
|
NetBroadcastTuple tuple = broadcastModel.getValue();
|
||||||
if (tuple.getConfiguration() != null) {
|
if (tuple.getConfiguration() != null) {
|
||||||
MultiLayerConfiguration conf = tuple.getConfiguration();
|
NeuralNetConfiguration conf = tuple.getConfiguration();
|
||||||
MultiLayerNetwork network = new MultiLayerNetwork(conf);
|
MultiLayerNetwork network = new MultiLayerNetwork(conf);
|
||||||
network.init();
|
network.init();
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.spark.SparkConf;
|
||||||
import org.apache.spark.api.java.JavaRDD;
|
import org.apache.spark.api.java.JavaRDD;
|
||||||
import org.apache.spark.api.java.JavaSparkContext;
|
import org.apache.spark.api.java.JavaSparkContext;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.spark.impl.multilayer.SparkDl4jMultiLayer;
|
import org.deeplearning4j.spark.impl.multilayer.SparkDl4jMultiLayer;
|
||||||
import org.deeplearning4j.spark.impl.paramavg.ParameterAveragingTrainingMaster;
|
import org.deeplearning4j.spark.impl.paramavg.ParameterAveragingTrainingMaster;
|
||||||
|
@ -126,8 +126,8 @@ public abstract class BaseSparkTest extends BaseDL4JTest implements Serializable
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MultiLayerConfiguration getBasicConf() {
|
protected NeuralNetConfiguration getBasicConf() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
|
||||||
.updater(new Nesterovs(0.1, 0.9)).list()
|
.updater(new Nesterovs(0.1, 0.9)).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.eval.Evaluation;
|
import org.deeplearning4j.eval.Evaluation;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import org.deeplearning4j.nn.api.Model;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -132,7 +132,7 @@ public class GradientSharingTrainingTest extends BaseSparkTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new AMSGrad(0.1))
|
.updater(new AMSGrad(0.1))
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
|
@ -266,16 +266,16 @@ public class GradientSharingTrainingTest extends BaseSparkTest {
|
||||||
System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
|
System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
|
||||||
log.info("Starting: {}", i);
|
log.info("Starting: {}", i);
|
||||||
|
|
||||||
MultiLayerConfiguration conf;
|
NeuralNetConfiguration conf;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
conf = new NeuralNetConfiguration.Builder()
|
conf = NeuralNetConfiguration.builder()
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.list()
|
.list()
|
||||||
.layer(new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX).lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.layer(new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX).lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
conf = new NeuralNetConfiguration.Builder()
|
conf = NeuralNetConfiguration.builder()
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.list()
|
.list()
|
||||||
|
@ -353,7 +353,7 @@ public class GradientSharingTrainingTest extends BaseSparkTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new AMSGrad(0.001))
|
.updater(new AMSGrad(0.001))
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.spark.api.worker;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -31,13 +31,13 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@Data
|
@Data
|
||||||
public class NetBroadcastTuple implements Serializable {
|
public class NetBroadcastTuple implements Serializable {
|
||||||
|
|
||||||
private final MultiLayerConfiguration configuration;
|
private final NeuralNetConfiguration configuration;
|
||||||
private final ComputationGraphConfiguration graphConfiguration;
|
private final ComputationGraphConfiguration graphConfiguration;
|
||||||
private final INDArray parameters;
|
private final INDArray parameters;
|
||||||
private final INDArray updaterState;
|
private final INDArray updaterState;
|
||||||
private final AtomicInteger counter;
|
private final AtomicInteger counter;
|
||||||
|
|
||||||
public NetBroadcastTuple(MultiLayerConfiguration configuration, INDArray parameters, INDArray updaterState) {
|
public NetBroadcastTuple(NeuralNetConfiguration configuration, INDArray parameters, INDArray updaterState) {
|
||||||
this(configuration, null, parameters, updaterState);
|
this(configuration, null, parameters, updaterState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@ public class NetBroadcastTuple implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetBroadcastTuple(MultiLayerConfiguration configuration, ComputationGraphConfiguration graphConfiguration,
|
public NetBroadcastTuple(NeuralNetConfiguration configuration, ComputationGraphConfiguration graphConfiguration,
|
||||||
INDArray parameters, INDArray updaterState) {
|
INDArray parameters, INDArray updaterState) {
|
||||||
this(configuration, graphConfiguration, parameters, updaterState, new AtomicInteger(0));
|
this(configuration, graphConfiguration, parameters, updaterState, new AtomicInteger(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetBroadcastTuple(MultiLayerConfiguration configuration, ComputationGraphConfiguration graphConfiguration,
|
public NetBroadcastTuple(NeuralNetConfiguration configuration, ComputationGraphConfiguration graphConfiguration,
|
||||||
INDArray parameters, INDArray updaterState, AtomicInteger counter) {
|
INDArray parameters, INDArray updaterState, AtomicInteger counter) {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.graphConfiguration = graphConfiguration;
|
this.graphConfiguration = graphConfiguration;
|
||||||
|
|
|
@ -31,7 +31,7 @@ public abstract class BaseVaeReconstructionProbWithKeyFunction<K> extends BaseVa
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param useLogProbability If true: use log probability. False: use raw probability.
|
* @param useLogProbability If true: use log probability. False: use raw probability.
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}
|
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public abstract class BaseVaeScoreWithKeyFunction<K> implements PairFlatMapFunct
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
*/
|
*/
|
||||||
public BaseVaeScoreWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig, int batchSize) {
|
public BaseVaeScoreWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig, int batchSize) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.deeplearning4j.datasets.iterator.IteratorDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.IteratorMultiDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.IteratorMultiDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import org.deeplearning4j.nn.api.Model;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.nd4j.common.base.Preconditions;
|
import org.nd4j.common.base.Preconditions;
|
||||||
|
@ -131,7 +131,7 @@ public class EvaluationRunner {
|
||||||
cg.init(deviceLocalParams.get(), false);
|
cg.init(deviceLocalParams.get(), false);
|
||||||
m = cg;
|
m = cg;
|
||||||
} else {
|
} else {
|
||||||
MultiLayerConfiguration conf = MultiLayerConfiguration.fromJson(json.getValue());
|
NeuralNetConfiguration conf = NeuralNetConfiguration.fromJson(json.getValue());
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init(deviceLocalParams.get(), false);
|
net.init(deviceLocalParams.get(), false);
|
||||||
m = net;
|
m = net;
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class CGVaeReconstructionErrorWithKeyFunction<K> extends BaseVaeScoreWith
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
*/
|
*/
|
||||||
public CGVaeReconstructionErrorWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig,
|
public CGVaeReconstructionErrorWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig,
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class CGVaeReconstructionProbWithKeyFunction<K> extends BaseVaeReconstruc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param useLogProbability If true: use log probability. False: use raw probability.
|
* @param useLogProbability If true: use log probability. False: use raw probability.
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}
|
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.datavec.spark.util.BroadcastHadoopConfigHolder;
|
||||||
import org.deeplearning4j.core.loader.DataSetLoader;
|
import org.deeplearning4j.core.loader.DataSetLoader;
|
||||||
import org.deeplearning4j.core.loader.MultiDataSetLoader;
|
import org.deeplearning4j.core.loader.MultiDataSetLoader;
|
||||||
import org.deeplearning4j.core.loader.impl.SerializedDataSetLoader;
|
import org.deeplearning4j.core.loader.impl.SerializedDataSetLoader;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.FeedForwardLayer;
|
import org.deeplearning4j.nn.conf.layers.FeedForwardLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.spark.api.TrainingMaster;
|
import org.deeplearning4j.spark.api.TrainingMaster;
|
||||||
|
@ -80,7 +80,7 @@ public class SparkDl4jMultiLayer extends SparkListenable {
|
||||||
public static final int DEFAULT_ROC_THRESHOLD_STEPS = 32;
|
public static final int DEFAULT_ROC_THRESHOLD_STEPS = 32;
|
||||||
public static final int DEFAULT_EVAL_WORKERS = 4;
|
public static final int DEFAULT_EVAL_WORKERS = 4;
|
||||||
private transient JavaSparkContext sc;
|
private transient JavaSparkContext sc;
|
||||||
private MultiLayerConfiguration conf;
|
private NeuralNetConfiguration conf;
|
||||||
private MultiLayerNetwork network;
|
private MultiLayerNetwork network;
|
||||||
private double lastScore;
|
private double lastScore;
|
||||||
private int defaultEvaluationWorkers = DEFAULT_EVAL_WORKERS;
|
private int defaultEvaluationWorkers = DEFAULT_EVAL_WORKERS;
|
||||||
|
@ -104,7 +104,7 @@ public class SparkDl4jMultiLayer extends SparkListenable {
|
||||||
* @param sparkContext the spark context to use
|
* @param sparkContext the spark context to use
|
||||||
* @param conf the configuration of the network
|
* @param conf the configuration of the network
|
||||||
*/
|
*/
|
||||||
public SparkDl4jMultiLayer(SparkContext sparkContext, MultiLayerConfiguration conf,
|
public SparkDl4jMultiLayer(SparkContext sparkContext, NeuralNetConfiguration conf,
|
||||||
TrainingMaster<?, ?> trainingMaster) {
|
TrainingMaster<?, ?> trainingMaster) {
|
||||||
this(new JavaSparkContext(sparkContext), initNetwork(conf), trainingMaster);
|
this(new JavaSparkContext(sparkContext), initNetwork(conf), trainingMaster);
|
||||||
}
|
}
|
||||||
|
@ -115,14 +115,14 @@ public class SparkDl4jMultiLayer extends SparkListenable {
|
||||||
* @param sc the spark context to use
|
* @param sc the spark context to use
|
||||||
* @param conf the configuration of the network
|
* @param conf the configuration of the network
|
||||||
*/
|
*/
|
||||||
public SparkDl4jMultiLayer(JavaSparkContext sc, MultiLayerConfiguration conf, TrainingMaster<?, ?> trainingMaster) {
|
public SparkDl4jMultiLayer(JavaSparkContext sc, NeuralNetConfiguration conf, TrainingMaster<?, ?> trainingMaster) {
|
||||||
this(sc.sc(), conf, trainingMaster);
|
this(sc.sc(), conf, trainingMaster);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SparkDl4jMultiLayer(JavaSparkContext javaSparkContext, MultiLayerNetwork network,
|
public SparkDl4jMultiLayer(JavaSparkContext javaSparkContext, MultiLayerNetwork network,
|
||||||
TrainingMaster<?, ?> trainingMaster) {
|
TrainingMaster<?, ?> trainingMaster) {
|
||||||
sc = javaSparkContext;
|
sc = javaSparkContext;
|
||||||
this.conf = network.getLayerWiseConfigurations().clone();
|
this.conf = network.getConfiguration().clone();
|
||||||
this.network = network;
|
this.network = network;
|
||||||
if (!network.isInitCalled())
|
if (!network.isInitCalled())
|
||||||
network.init();
|
network.init();
|
||||||
|
@ -132,7 +132,7 @@ public class SparkDl4jMultiLayer extends SparkListenable {
|
||||||
SparkUtils.checkKryoConfiguration(javaSparkContext, log);
|
SparkUtils.checkKryoConfiguration(javaSparkContext, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MultiLayerNetwork initNetwork(MultiLayerConfiguration conf) {
|
private static MultiLayerNetwork initNetwork(NeuralNetConfiguration conf) {
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
return net;
|
return net;
|
||||||
|
@ -315,8 +315,8 @@ public class SparkDl4jMultiLayer extends SparkListenable {
|
||||||
* @return the multi layer network that was fitDataSet
|
* @return the multi layer network that was fitDataSet
|
||||||
*/
|
*/
|
||||||
public MultiLayerNetwork fitLabeledPoint(JavaRDD<LabeledPoint> rdd) {
|
public MultiLayerNetwork fitLabeledPoint(JavaRDD<LabeledPoint> rdd) {
|
||||||
int nLayers = network.getLayerWiseConfigurations().getConfs().size();
|
int nLayers = network.getConfiguration().getConfs().size();
|
||||||
FeedForwardLayer ffl = (FeedForwardLayer) network.getLayerWiseConfigurations().getConf(nLayers - 1).getLayer();
|
FeedForwardLayer ffl = (FeedForwardLayer) network.getConfiguration().getConf(nLayers - 1).getLayer();
|
||||||
JavaRDD<DataSet> ds = MLLibUtil.fromLabeledPoint(sc, rdd, ffl.getNOut());
|
JavaRDD<DataSet> ds = MLLibUtil.fromLabeledPoint(sc, rdd, ffl.getNOut());
|
||||||
return fit(ds);
|
return fit(ds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
|
||||||
|
|
||||||
import org.apache.spark.api.java.function.PairFlatMapFunction;
|
import org.apache.spark.api.java.function.PairFlatMapFunction;
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.dataset.api.DataSetUtil;
|
import org.nd4j.linalg.dataset.api.DataSetUtil;
|
||||||
|
@ -49,7 +49,7 @@ public class FeedForwardWithKeyFunction<K>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param batchSize Batch size to use for forward pass (use > 1 for efficiency)
|
* @param batchSize Batch size to use for forward pass (use > 1 for efficiency)
|
||||||
*/
|
*/
|
||||||
public FeedForwardWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig, int batchSize) {
|
public FeedForwardWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig, int batchSize) {
|
||||||
|
@ -65,7 +65,7 @@ public class FeedForwardWithKeyFunction<K>
|
||||||
return Collections.emptyIterator();
|
return Collections.emptyIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(jsonConfig.getValue()));
|
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(jsonConfig.getValue()));
|
||||||
network.init();
|
network.init();
|
||||||
INDArray val = params.value().unsafeDuplication();
|
INDArray val = params.value().unsafeDuplication();
|
||||||
if (val.length() != network.numParams(false))
|
if (val.length() != network.numParams(false))
|
||||||
|
|
|
@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
|
||||||
import org.apache.spark.api.java.function.DoubleFlatMapFunction;
|
import org.apache.spark.api.java.function.DoubleFlatMapFunction;
|
||||||
import org.apache.spark.api.java.function.FlatMapFunction;
|
import org.apache.spark.api.java.function.FlatMapFunction;
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.dataset.DataSet;
|
import org.nd4j.linalg.dataset.DataSet;
|
||||||
|
@ -60,7 +60,7 @@ public class ScoreExamplesFunction implements DoubleFlatMapFunction<Iterator<Dat
|
||||||
return Collections.emptyIterator();
|
return Collections.emptyIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(jsonConfig.getValue()));
|
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(jsonConfig.getValue()));
|
||||||
network.init();
|
network.init();
|
||||||
INDArray val = params.value().unsafeDuplication();
|
INDArray val = params.value().unsafeDuplication();
|
||||||
if (val.length() != network.numParams(false))
|
if (val.length() != network.numParams(false))
|
||||||
|
|
|
@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.spark.api.java.function.PairFlatMapFunction;
|
import org.apache.spark.api.java.function.PairFlatMapFunction;
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.dataset.DataSet;
|
import org.nd4j.linalg.dataset.DataSet;
|
||||||
|
@ -45,7 +45,7 @@ public class ScoreExamplesWithKeyFunction<K> implements PairFlatMapFunction<Iter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param addRegularizationTerms if true: add regularization terms (L1, L2) to the score
|
* @param addRegularizationTerms if true: add regularization terms (L1, L2) to the score
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +63,7 @@ public class ScoreExamplesWithKeyFunction<K> implements PairFlatMapFunction<Iter
|
||||||
return Collections.emptyIterator();
|
return Collections.emptyIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(jsonConfig.getValue()));
|
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(jsonConfig.getValue()));
|
||||||
network.init();
|
network.init();
|
||||||
INDArray val = params.value().unsafeDuplication();
|
INDArray val = params.value().unsafeDuplication();
|
||||||
if (val.length() != network.numParams(false))
|
if (val.length() != network.numParams(false))
|
||||||
|
|
|
@ -26,7 +26,7 @@ import lombok.val;
|
||||||
import org.apache.spark.api.java.function.FlatMapFunction;
|
import org.apache.spark.api.java.function.FlatMapFunction;
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.datasets.iterator.IteratorDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.IteratorDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.dataset.DataSet;
|
import org.nd4j.linalg.dataset.DataSet;
|
||||||
|
@ -55,7 +55,7 @@ public class ScoreFlatMapFunction implements FlatMapFunction<Iterator<DataSet>,
|
||||||
|
|
||||||
DataSetIterator iter = new IteratorDataSetIterator(dataSetIterator, minibatchSize); //Does batching where appropriate
|
DataSetIterator iter = new IteratorDataSetIterator(dataSetIterator, minibatchSize); //Does batching where appropriate
|
||||||
|
|
||||||
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(json));
|
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(json));
|
||||||
network.init();
|
network.init();
|
||||||
INDArray val = params.value().unsafeDuplication(); //.value() object will be shared by all executors on each machine -> OK, as params are not modified by score function
|
INDArray val = params.value().unsafeDuplication(); //.value() object will be shared by all executors on each machine -> OK, as params are not modified by score function
|
||||||
if (val.length() != network.numParams(false))
|
if (val.length() != network.numParams(false))
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
|
||||||
|
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.nn.api.Layer;
|
import org.deeplearning4j.nn.api.Layer;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.layers.variational.VariationalAutoencoder;
|
import org.deeplearning4j.nn.layers.variational.VariationalAutoencoder;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.spark.impl.common.score.BaseVaeScoreWithKeyFunction;
|
import org.deeplearning4j.spark.impl.common.score.BaseVaeScoreWithKeyFunction;
|
||||||
|
@ -36,7 +36,7 @@ public class VaeReconstructionErrorWithKeyFunction<K> extends BaseVaeScoreWithKe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
*/
|
*/
|
||||||
public VaeReconstructionErrorWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig,
|
public VaeReconstructionErrorWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig,
|
||||||
|
@ -47,7 +47,7 @@ public class VaeReconstructionErrorWithKeyFunction<K> extends BaseVaeScoreWithKe
|
||||||
@Override
|
@Override
|
||||||
public VariationalAutoencoder getVaeLayer() {
|
public VariationalAutoencoder getVaeLayer() {
|
||||||
MultiLayerNetwork network =
|
MultiLayerNetwork network =
|
||||||
new MultiLayerNetwork(MultiLayerConfiguration.fromJson((String) jsonConfig.getValue()));
|
new MultiLayerNetwork(NeuralNetConfiguration.fromJson((String) jsonConfig.getValue()));
|
||||||
network.init();
|
network.init();
|
||||||
INDArray val = ((INDArray) params.value()).unsafeDuplication();
|
INDArray val = ((INDArray) params.value()).unsafeDuplication();
|
||||||
if (val.length() != network.numParams(false))
|
if (val.length() != network.numParams(false))
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
|
||||||
|
|
||||||
import org.apache.spark.broadcast.Broadcast;
|
import org.apache.spark.broadcast.Broadcast;
|
||||||
import org.deeplearning4j.nn.api.Layer;
|
import org.deeplearning4j.nn.api.Layer;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.layers.variational.VariationalAutoencoder;
|
import org.deeplearning4j.nn.layers.variational.VariationalAutoencoder;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.spark.impl.common.score.BaseVaeReconstructionProbWithKeyFunction;
|
import org.deeplearning4j.spark.impl.common.score.BaseVaeReconstructionProbWithKeyFunction;
|
||||||
|
@ -34,7 +34,7 @@ public class VaeReconstructionProbWithKeyFunction<K> extends BaseVaeReconstructi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param params MultiLayerNetwork parameters
|
* @param params MultiLayerNetwork parameters
|
||||||
* @param jsonConfig MultiLayerConfiguration, as json
|
* @param jsonConfig NeuralNetConfiguration, as json
|
||||||
* @param useLogProbability If true: use log probability. False: use raw probability.
|
* @param useLogProbability If true: use log probability. False: use raw probability.
|
||||||
* @param batchSize Batch size to use when scoring
|
* @param batchSize Batch size to use when scoring
|
||||||
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}
|
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}
|
||||||
|
@ -47,7 +47,7 @@ public class VaeReconstructionProbWithKeyFunction<K> extends BaseVaeReconstructi
|
||||||
@Override
|
@Override
|
||||||
public VariationalAutoencoder getVaeLayer() {
|
public VariationalAutoencoder getVaeLayer() {
|
||||||
MultiLayerNetwork network =
|
MultiLayerNetwork network =
|
||||||
new MultiLayerNetwork(MultiLayerConfiguration.fromJson((String) jsonConfig.getValue()));
|
new MultiLayerNetwork(NeuralNetConfiguration.fromJson((String) jsonConfig.getValue()));
|
||||||
network.init();
|
network.init();
|
||||||
INDArray val = ((INDArray) params.value()).unsafeDuplication();
|
INDArray val = ((INDArray) params.value()).unsafeDuplication();
|
||||||
if (val.length() != network.numParams(false))
|
if (val.length() != network.numParams(false))
|
||||||
|
|
|
@ -41,7 +41,7 @@ import org.deeplearning4j.core.storage.StatsStorageRouter;
|
||||||
import org.deeplearning4j.core.storage.StatsStorageRouterProvider;
|
import org.deeplearning4j.core.storage.StatsStorageRouterProvider;
|
||||||
import org.deeplearning4j.core.storage.StorageMetaData;
|
import org.deeplearning4j.core.storage.StorageMetaData;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.optimize.api.TrainingListener;
|
import org.deeplearning4j.optimize.api.TrainingListener;
|
||||||
|
@ -274,7 +274,7 @@ public class ParameterAveragingTrainingMaster
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParameterAveragingTrainingWorker getWorkerInstance(SparkDl4jMultiLayer network) {
|
public ParameterAveragingTrainingWorker getWorkerInstance(SparkDl4jMultiLayer network) {
|
||||||
NetBroadcastTuple tuple = new NetBroadcastTuple(network.getNetwork().getLayerWiseConfigurations(),
|
NetBroadcastTuple tuple = new NetBroadcastTuple(network.getNetwork().getConfiguration(),
|
||||||
network.getNetwork().params(), network.getNetwork().getUpdater().getStateViewArray());
|
network.getNetwork().params(), network.getNetwork().getUpdater().getStateViewArray());
|
||||||
|
|
||||||
if (collectTrainingStats)
|
if (collectTrainingStats)
|
||||||
|
@ -726,7 +726,7 @@ public class ParameterAveragingTrainingMaster
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
//Params may be null for edge case (empty RDD)
|
//Params may be null for edge case (empty RDD)
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
MultiLayerConfiguration conf = network.getNetwork().getLayerWiseConfigurations();
|
NeuralNetConfiguration conf = network.getNetwork().getConfiguration();
|
||||||
int numUpdates = averagingFrequency;
|
int numUpdates = averagingFrequency;
|
||||||
conf.setIterationCount(conf.getIterationCount() + numUpdates);
|
conf.setIterationCount(conf.getIterationCount() + numUpdates);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.spark.api.java.JavaRDD;
|
||||||
import org.apache.spark.api.java.JavaSparkContext;
|
import org.apache.spark.api.java.JavaSparkContext;
|
||||||
import org.datavec.spark.util.SerializableHadoopConfig;
|
import org.datavec.spark.util.SerializableHadoopConfig;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.spark.impl.multilayer.SparkDl4jMultiLayer;
|
import org.deeplearning4j.spark.impl.multilayer.SparkDl4jMultiLayer;
|
||||||
import org.deeplearning4j.spark.impl.paramavg.ParameterAveragingTrainingMaster;
|
import org.deeplearning4j.spark.impl.paramavg.ParameterAveragingTrainingMaster;
|
||||||
|
@ -129,8 +129,8 @@ public abstract class BaseSparkTest extends BaseDL4JTest implements Serializable
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MultiLayerConfiguration getBasicConf() {
|
protected NeuralNetConfiguration getBasicConf() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
|
||||||
.updater(new Nesterovs(0.1, 0.9)).list()
|
.updater(new Nesterovs(0.1, 0.9)).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.deeplearning4j.earlystopping.termination.MaxTimeIterationTerminationC
|
||||||
import org.deeplearning4j.earlystopping.termination.ScoreImprovementEpochTerminationCondition;
|
import org.deeplearning4j.earlystopping.termination.ScoreImprovementEpochTerminationCondition;
|
||||||
import org.deeplearning4j.earlystopping.trainer.IEarlyStoppingTrainer;
|
import org.deeplearning4j.earlystopping.trainer.IEarlyStoppingTrainer;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
@ -68,7 +68,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd()).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd()).weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -123,7 +123,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(10.0)) //Intentionally huge LR
|
.updater(new Sgd(10.0)) //Intentionally huge LR
|
||||||
.weightInit(WeightInit.XAVIER).list()
|
.weightInit(WeightInit.XAVIER).list()
|
||||||
|
@ -163,7 +163,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -209,7 +209,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -246,7 +246,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd()).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd()).weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd()).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.updater(new Sgd()).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -124,7 +124,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(2.0)) //Intentionally huge LR
|
.updater(new Sgd(2.0)) //Intentionally huge LR
|
||||||
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
|
@ -165,7 +165,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).graphBuilder()
|
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -213,7 +213,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).graphBuilder()
|
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -253,7 +253,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd()).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.updater(new Sgd()).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.spark;
|
||||||
|
|
||||||
import org.apache.spark.serializer.SerializerInstance;
|
import org.apache.spark.serializer.SerializerInstance;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
|
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
|
||||||
import org.deeplearning4j.nn.conf.graph.*;
|
import org.deeplearning4j.nn.conf.graph.*;
|
||||||
|
@ -68,14 +68,14 @@ public class TestKryo extends BaseSparkKryoTest {
|
||||||
Map<Integer, Double> m = new HashMap<>();
|
Map<Integer, Double> m = new HashMap<>();
|
||||||
m.put(0, 0.5);
|
m.put(0, 0.5);
|
||||||
m.put(10, 0.1);
|
m.put(10, 0.1);
|
||||||
MultiLayerConfiguration mlc = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration mlc = NeuralNetConfiguration.builder()
|
||||||
.updater(new Nadam(new MapSchedule(ScheduleType.ITERATION,m))).list().layer(0, new OutputLayer.Builder().nIn(10).nOut(10).build())
|
.updater(new Nadam(new MapSchedule(ScheduleType.ITERATION,m))).list().layer(0, new OutputLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
testSerialization(mlc, si);
|
testSerialization(mlc, si);
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration cgc = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration cgc = NeuralNetConfiguration.builder()
|
||||||
.dist(new UniformDistribution(-1, 1))
|
.dist(new UniformDistribution(-1, 1))
|
||||||
.updater(new Adam(new MapSchedule(ScheduleType.ITERATION,m)))
|
.updater(new Adam(new MapSchedule(ScheduleType.ITERATION,m)))
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.Updater;
|
import org.deeplearning4j.nn.conf.Updater;
|
||||||
import org.deeplearning4j.spark.BaseSparkTest;
|
import org.deeplearning4j.spark.BaseSparkTest;
|
||||||
|
@ -84,7 +84,7 @@ public class TestPreProcessedData extends BaseSparkTest {
|
||||||
iter.next().save(f2);
|
iter.next().save(f2);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(Updater.RMSPROP)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(Updater.RMSPROP)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -134,7 +134,7 @@ public class TestPreProcessedData extends BaseSparkTest {
|
||||||
iter.next().save(f2);
|
iter.next().save(f2);
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(Updater.RMSPROP)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(Updater.RMSPROP)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.graphBuilder().addInputs("in")
|
.graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
|
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -188,7 +188,7 @@ public class TestPreProcessedData extends BaseSparkTest {
|
||||||
mds.save(f2);
|
mds.save(f2);
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(Updater.RMSPROP)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(Updater.RMSPROP)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.graphBuilder().addInputs("in")
|
.graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
|
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
|
||||||
|
|
|
@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl;
|
||||||
import org.apache.spark.SparkConf;
|
import org.apache.spark.SparkConf;
|
||||||
import org.apache.spark.api.java.JavaSparkContext;
|
import org.apache.spark.api.java.JavaSparkContext;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.spark.api.TrainingMaster;
|
import org.deeplearning4j.spark.api.TrainingMaster;
|
||||||
|
@ -40,7 +40,7 @@ public class TestKryoWarning {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new OutputLayer.Builder().nIn(10).nOut(10).build())
|
.layer(0, new OutputLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class TestKryoWarning {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().graphBuilder().addInputs("in")
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new OutputLayer.Builder().nIn(10).nOut(10).build(), "in").setOutputs("0")
|
.addLayer("0", new OutputLayer.Builder().nIn(10).nOut(10).build(), "in").setOutputs("0")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.customlayer;
|
||||||
|
|
||||||
import com.sun.jna.Platform;
|
import com.sun.jna.Platform;
|
||||||
import org.apache.spark.api.java.JavaRDD;
|
import org.apache.spark.api.java.JavaRDD;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -51,8 +51,8 @@ public class TestCustomLayer extends BaseSparkTest {
|
||||||
}
|
}
|
||||||
//Basic test - checks whether exceptions etc are thrown with custom layers + spark
|
//Basic test - checks whether exceptions etc are thrown with custom layers + spark
|
||||||
//Custom layers are tested more extensively in dl4j core
|
//Custom layers are tested more extensively in dl4j core
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().updater(new Sgd(0.1)).list()
|
NeuralNetConfiguration.builder().updater(new Sgd(0.1)).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.layer(1, new CustomLayer(3.14159)).layer(2,
|
.layer(1, new CustomLayer(3.14159)).layer(2,
|
||||||
new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
|
||||||
|
|
||||||
public static ComputationGraph getBasicNetIris2Class() {
|
public static ComputationGraph getBasicNetIris2Class() {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER)
|
||||||
.graphBuilder().addInputs("in")
|
.graphBuilder().addInputs("in")
|
||||||
.addLayer("l0", new DenseLayer.Builder().nIn(4).nOut(10).build(), "in")
|
.addLayer("l0", new DenseLayer.Builder().nIn(4).nOut(10).build(), "in")
|
||||||
.addLayer("l1", new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.addLayer("l1", new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
|
@ -104,7 +104,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
list.add(iter.next());
|
list.add(iter.next());
|
||||||
|
|
||||||
ComputationGraphConfiguration config = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration config = NeuralNetConfiguration.builder()
|
||||||
.updater(new Sgd(0.1))
|
.updater(new Sgd(0.1))
|
||||||
.graphBuilder().addInputs("in")
|
.graphBuilder().addInputs("in")
|
||||||
.addLayer("dense", new DenseLayer.Builder().nIn(4).nOut(2).build(), "in").addLayer("out",
|
.addLayer("dense", new DenseLayer.Builder().nIn(4).nOut(2).build(), "in").addLayer("out",
|
||||||
|
@ -138,7 +138,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDistributedScoring() {
|
public void testDistributedScoring() {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().l1(0.1).l2(0.1)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().l1(0.1).l2(0.1)
|
||||||
.seed(123).updater(new Nesterovs(0.1, 0.9)).graphBuilder()
|
.seed(123).updater(new Nesterovs(0.1, 0.9)).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
||||||
|
@ -217,7 +217,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
|
||||||
//@Ignore("AB 2019/05/23 - Failing on CI only - passing locally. Possible precision or threading issue")
|
//@Ignore("AB 2019/05/23 - Failing on CI only - passing locally. Possible precision or threading issue")
|
||||||
public void testSeedRepeatability() throws Exception {
|
public void testSeedRepeatability() throws Exception {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).updater(Updater.RMSPROP)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345).updater(Updater.RMSPROP)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(4)
|
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(4)
|
||||||
|
@ -414,7 +414,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
|
||||||
JavaRDD<org.nd4j.linalg.dataset.api.MultiDataSet> rdd = sc.parallelize(l);
|
JavaRDD<org.nd4j.linalg.dataset.api.MultiDataSet> rdd = sc.parallelize(l);
|
||||||
|
|
||||||
// simple model
|
// simple model
|
||||||
val modelConf = new NeuralNetConfiguration.Builder()
|
val modelConf = NeuralNetConfiguration.builder()
|
||||||
.updater(new Adam(0.01))
|
.updater(new Adam(0.01))
|
||||||
.weightInit(WeightInit.XAVIER_UNIFORM)
|
.weightInit(WeightInit.XAVIER_UNIFORM)
|
||||||
.biasInit(0)
|
.biasInit(0)
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class TestFrozenLayers extends BaseSparkTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSparkFrozenLayers() {
|
public void testSparkFrozenLayers() {
|
||||||
|
|
||||||
NeuralNetConfiguration.Builder overallConf = new NeuralNetConfiguration.Builder().updater(new Sgd(0.1))
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder overallConf = NeuralNetConfiguration.builder().updater(new Sgd(0.1))
|
||||||
.activation(Activation.TANH);
|
.activation(Activation.TANH);
|
||||||
|
|
||||||
FineTuneConfiguration finetune = new FineTuneConfiguration.Builder().updater(new Sgd(0.1)).build();
|
FineTuneConfiguration finetune = new FineTuneConfiguration.Builder().updater(new Sgd(0.1)).build();
|
||||||
|
@ -74,7 +74,7 @@ public class TestFrozenLayers extends BaseSparkTest {
|
||||||
MultiLayerNetwork withFrozen = new TransferLearning.Builder(origModel).fineTuneConfiguration(finetune)
|
MultiLayerNetwork withFrozen = new TransferLearning.Builder(origModel).fineTuneConfiguration(finetune)
|
||||||
.setFeatureExtractor(1).build();
|
.setFeatureExtractor(1).build();
|
||||||
|
|
||||||
Map<String, INDArray> m = withFrozen.paramTable();
|
Map<String, INDArray> m = withFrozen.getParamTable();
|
||||||
Map<String, INDArray> pCopy = new HashMap<>();
|
Map<String, INDArray> pCopy = new HashMap<>();
|
||||||
for (Map.Entry<String, INDArray> entry : m.entrySet()) {
|
for (Map.Entry<String, INDArray> entry : m.entrySet()) {
|
||||||
pCopy.put(entry.getKey(), entry.getValue().dup());
|
pCopy.put(entry.getKey(), entry.getValue().dup());
|
||||||
|
@ -110,7 +110,7 @@ public class TestFrozenLayers extends BaseSparkTest {
|
||||||
|
|
||||||
MultiLayerNetwork fitted = sNet.getNetwork();
|
MultiLayerNetwork fitted = sNet.getNetwork();
|
||||||
|
|
||||||
Map<String, INDArray> fittedParams = fitted.paramTable();
|
Map<String, INDArray> fittedParams = fitted.getParamTable();
|
||||||
|
|
||||||
for (Map.Entry<String, INDArray> entry : fittedParams.entrySet()) {
|
for (Map.Entry<String, INDArray> entry : fittedParams.entrySet()) {
|
||||||
INDArray orig = pCopy.get(entry.getKey());
|
INDArray orig = pCopy.get(entry.getKey());
|
||||||
|
@ -136,7 +136,7 @@ public class TestFrozenLayers extends BaseSparkTest {
|
||||||
int nIn = 6;
|
int nIn = 6;
|
||||||
int nOut = 3;
|
int nOut = 3;
|
||||||
|
|
||||||
ComputationGraph origModel = new ComputationGraph(new NeuralNetConfiguration.Builder().updater(new Sgd(0.1))
|
ComputationGraph origModel = new ComputationGraph(NeuralNetConfiguration.builder().updater(new Sgd(0.1))
|
||||||
.activation(Activation.TANH).graphBuilder().addInputs("in")
|
.activation(Activation.TANH).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new DenseLayer.Builder().nIn(6).nOut(5).build(), "in")
|
.addLayer("0", new DenseLayer.Builder().nIn(6).nOut(5).build(), "in")
|
||||||
.addLayer("1", new DenseLayer.Builder().nIn(5).nOut(4).build(), "0")
|
.addLayer("1", new DenseLayer.Builder().nIn(5).nOut(4).build(), "0")
|
||||||
|
@ -151,7 +151,7 @@ public class TestFrozenLayers extends BaseSparkTest {
|
||||||
ComputationGraph withFrozen = new TransferLearning.GraphBuilder(origModel).fineTuneConfiguration(finetune)
|
ComputationGraph withFrozen = new TransferLearning.GraphBuilder(origModel).fineTuneConfiguration(finetune)
|
||||||
.setFeatureExtractor("1").build();
|
.setFeatureExtractor("1").build();
|
||||||
|
|
||||||
Map<String, INDArray> m = withFrozen.paramTable();
|
Map<String, INDArray> m = withFrozen.getParamTable();
|
||||||
Map<String, INDArray> pCopy = new HashMap<>();
|
Map<String, INDArray> pCopy = new HashMap<>();
|
||||||
for (Map.Entry<String, INDArray> entry : m.entrySet()) {
|
for (Map.Entry<String, INDArray> entry : m.entrySet()) {
|
||||||
pCopy.put(entry.getKey(), entry.getValue().dup());
|
pCopy.put(entry.getKey(), entry.getValue().dup());
|
||||||
|
@ -187,7 +187,7 @@ public class TestFrozenLayers extends BaseSparkTest {
|
||||||
|
|
||||||
ComputationGraph fitted = sNet.getNetwork();
|
ComputationGraph fitted = sNet.getNetwork();
|
||||||
|
|
||||||
Map<String, INDArray> fittedParams = fitted.paramTable();
|
Map<String, INDArray> fittedParams = fitted.getParamTable();
|
||||||
|
|
||||||
for (Map.Entry<String, INDArray> entry : fittedParams.entrySet()) {
|
for (Map.Entry<String, INDArray> entry : fittedParams.entrySet()) {
|
||||||
INDArray orig = pCopy.get(entry.getKey());
|
INDArray orig = pCopy.get(entry.getKey());
|
||||||
|
|
|
@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl.multilayer;
|
||||||
import org.apache.spark.api.java.JavaPairRDD;
|
import org.apache.spark.api.java.JavaPairRDD;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.*;
|
||||||
import org.deeplearning4j.nn.conf.layers.variational.GaussianReconstructionDistribution;
|
import org.deeplearning4j.nn.conf.layers.variational.GaussianReconstructionDistribution;
|
||||||
|
@ -57,7 +57,7 @@ public class TestMiscFunctions extends BaseSparkTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFeedForwardWithKey() {
|
public void testFeedForwardWithKey() {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(3).build())
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(3).build())
|
||||||
.layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT).nIn(3).nOut(3)
|
.layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT).nIn(3).nOut(3)
|
||||||
.activation(Activation.SOFTMAX).build())
|
.activation(Activation.SOFTMAX).build())
|
||||||
|
@ -107,7 +107,7 @@ public class TestMiscFunctions extends BaseSparkTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFeedForwardWithKeyInputMask() {
|
public void testFeedForwardWithKeyInputMask() {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER)
|
||||||
.list()
|
.list()
|
||||||
.layer( new LSTM.Builder().nIn(4).nOut(3).build())
|
.layer( new LSTM.Builder().nIn(4).nOut(3).build())
|
||||||
.layer(new GlobalPoolingLayer(PoolingType.AVG))
|
.layer(new GlobalPoolingLayer(PoolingType.AVG))
|
||||||
|
@ -162,7 +162,7 @@ public class TestMiscFunctions extends BaseSparkTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFeedForwardWithKeyGraph() {
|
public void testFeedForwardWithKeyGraph() {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER)
|
||||||
.graphBuilder().addInputs("in1", "in2")
|
.graphBuilder().addInputs("in1", "in2")
|
||||||
.addLayer("0", new DenseLayer.Builder().nIn(4).nOut(3).build(), "in1")
|
.addLayer("0", new DenseLayer.Builder().nIn(4).nOut(3).build(), "in1")
|
||||||
.addLayer("1", new DenseLayer.Builder().nIn(4).nOut(3).build(), "in2").addLayer("2",
|
.addLayer("1", new DenseLayer.Builder().nIn(4).nOut(3).build(), "in2").addLayer("2",
|
||||||
|
@ -220,7 +220,7 @@ public class TestMiscFunctions extends BaseSparkTest {
|
||||||
|
|
||||||
int nIn = 10;
|
int nIn = 10;
|
||||||
|
|
||||||
MultiLayerConfiguration mlc = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration mlc = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder.Builder()
|
.layer(0, new org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder.Builder()
|
||||||
.reconstructionDistribution(
|
.reconstructionDistribution(
|
||||||
new GaussianReconstructionDistribution(Activation.IDENTITY))
|
new GaussianReconstructionDistribution(Activation.IDENTITY))
|
||||||
|
@ -259,7 +259,7 @@ public class TestMiscFunctions extends BaseSparkTest {
|
||||||
|
|
||||||
int nIn = 10;
|
int nIn = 10;
|
||||||
|
|
||||||
MultiLayerConfiguration mlc = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration mlc = NeuralNetConfiguration.builder()
|
||||||
.list().layer(0,
|
.list().layer(0,
|
||||||
new org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder.Builder()
|
new org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder.Builder()
|
||||||
.reconstructionDistribution(new LossFunctionWrapper(
|
.reconstructionDistribution(new LossFunctionWrapper(
|
||||||
|
|
|
@ -25,7 +25,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.spark.api.java.JavaRDD;
|
import org.apache.spark.api.java.JavaRDD;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -102,7 +102,7 @@ public class TestSparkDl4jMultiLayer extends BaseSparkTest {
|
||||||
|
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
//Create network configuration and conduct network training
|
//Create network configuration and conduct network training
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.spark.api.java.JavaRDD;
|
||||||
import org.apache.spark.api.java.JavaSparkContext;
|
import org.apache.spark.api.java.JavaSparkContext;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
||||||
|
@ -63,9 +63,9 @@ public class TestCompareParameterAveragingSparkVsSingleMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static MultiLayerConfiguration getConf(int seed, IUpdater updater) {
|
private static NeuralNetConfiguration getConf(int seed, IUpdater updater) {
|
||||||
Nd4j.getRandom().setSeed(seed);
|
Nd4j.getRandom().setSeed(seed);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).list()
|
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build()).layer(1, new OutputLayer.Builder()
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build()).layer(1, new OutputLayer.Builder()
|
||||||
|
@ -74,9 +74,9 @@ public class TestCompareParameterAveragingSparkVsSingleMachine {
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MultiLayerConfiguration getConfCNN(int seed, IUpdater updater) {
|
private static NeuralNetConfiguration getConfCNN(int seed, IUpdater updater) {
|
||||||
Nd4j.getRandom().setSeed(seed);
|
Nd4j.getRandom().setSeed(seed);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).list()
|
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().nOut(3).kernelSize(2, 2).stride(1, 1).padding(0, 0)
|
.layer(0, new ConvolutionLayer.Builder().nOut(3).kernelSize(2, 2).stride(1, 1).padding(0, 0)
|
||||||
|
@ -85,13 +85,13 @@ public class TestCompareParameterAveragingSparkVsSingleMachine {
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
.layer(1, new OutputLayer.Builder().lossFunction(LossFunctions.LossFunction.MSE).nOut(10)
|
.layer(1, new OutputLayer.Builder().lossFunction(LossFunctions.LossFunction.MSE).nOut(10)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutional(10, 10, 3)).build();
|
.inputType(InputType.convolutional(10, 10, 3)).build();
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComputationGraphConfiguration getGraphConf(int seed, IUpdater updater) {
|
private static ComputationGraphConfiguration getGraphConf(int seed, IUpdater updater) {
|
||||||
Nd4j.getRandom().setSeed(seed);
|
Nd4j.getRandom().setSeed(seed);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).graphBuilder()
|
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -105,7 +105,7 @@ public class TestCompareParameterAveragingSparkVsSingleMachine {
|
||||||
|
|
||||||
private static ComputationGraphConfiguration getGraphConfCNN(int seed, IUpdater updater) {
|
private static ComputationGraphConfiguration getGraphConfCNN(int seed, IUpdater updater) {
|
||||||
Nd4j.getRandom().setSeed(seed);
|
Nd4j.getRandom().setSeed(seed);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).graphBuilder()
|
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.Layer;
|
import org.deeplearning4j.nn.api.Layer;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.BaseLayer;
|
import org.deeplearning4j.nn.conf.layers.BaseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.BatchNormalization;
|
import org.deeplearning4j.nn.conf.layers.BatchNormalization;
|
||||||
|
@ -127,7 +127,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
.toJavaRDD().map(new TestFn());
|
.toJavaRDD().map(new TestFn());
|
||||||
|
|
||||||
DataSet d = new IrisDataSetIterator(150, 150).next();
|
DataSet d = new IrisDataSetIterator(150, 150).next();
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.RELU).build())
|
.activation(Activation.RELU).build())
|
||||||
|
@ -162,8 +162,8 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
.getAbsolutePath())
|
.getAbsolutePath())
|
||||||
.toJavaRDD().map(new TestFn());
|
.toJavaRDD().map(new TestFn());
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration.builder().seed(123)
|
||||||
.updater(new Adam(1e-6))
|
.updater(new Adam(1e-6))
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.list()
|
.list()
|
||||||
|
@ -275,7 +275,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -300,7 +300,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDistributedScoring() {
|
public void testDistributedScoring() {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().l1(0.1).l2(0.1)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().l1(0.1).l2(0.1)
|
||||||
.seed(123).updater(new Nesterovs(0.1, 0.9)).list()
|
.seed(123).updater(new Nesterovs(0.1, 0.9)).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -389,7 +389,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
list.add(iter.next());
|
list.add(iter.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -453,7 +453,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -523,7 +523,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -611,7 +611,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.graphBuilder().addInputs("in")
|
.graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
||||||
|
@ -684,7 +684,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345).updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.weightInit(WeightInit.XAVIER).list()
|
.weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(4)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(4)
|
||||||
|
@ -769,7 +769,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
list.add(iter.next());
|
list.add(iter.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
|
@ -791,13 +791,13 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
|
|
||||||
JavaRDD<DataSet> rdd = sc.parallelize(list);
|
JavaRDD<DataSet> rdd = sc.parallelize(list);
|
||||||
|
|
||||||
assertEquals(0, sparkNet.getNetwork().getLayerWiseConfigurations().getIterationCount());
|
assertEquals(0, sparkNet.getNetwork().getConfiguration().getIterationCount());
|
||||||
sparkNet.fit(rdd);
|
sparkNet.fit(rdd);
|
||||||
assertEquals(minibatchesPerWorkerPerEpoch,
|
assertEquals(minibatchesPerWorkerPerEpoch,
|
||||||
sparkNet.getNetwork().getLayerWiseConfigurations().getIterationCount());
|
sparkNet.getNetwork().getConfiguration().getIterationCount());
|
||||||
sparkNet.fit(rdd);
|
sparkNet.fit(rdd);
|
||||||
assertEquals(2 * minibatchesPerWorkerPerEpoch,
|
assertEquals(2 * minibatchesPerWorkerPerEpoch,
|
||||||
sparkNet.getNetwork().getLayerWiseConfigurations().getIterationCount());
|
sparkNet.getNetwork().getConfiguration().getIterationCount());
|
||||||
|
|
||||||
sparkNet.getTrainingMaster().deleteTempFiles(sc);
|
sparkNet.getTrainingMaster().deleteTempFiles(sc);
|
||||||
}
|
}
|
||||||
|
@ -819,7 +819,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
list.add(iter.next());
|
list.add(iter.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.graphBuilder().addInputs("in")
|
.graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
|
||||||
|
@ -860,7 +860,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
int nIn = 8;
|
int nIn = 8;
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).updater(new RmsProp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345).updater(new RmsProp())
|
||||||
.weightInit(WeightInit.XAVIER).list()
|
.weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new VariationalAutoencoder.Builder().nIn(8).nOut(10).encoderLayerSizes(12)
|
.layer(0, new VariationalAutoencoder.Builder().nIn(8).nOut(10).encoderLayerSizes(12)
|
||||||
.decoderLayerSizes(13).reconstructionDistribution(
|
.decoderLayerSizes(13).reconstructionDistribution(
|
||||||
|
@ -896,7 +896,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
int nIn = 8;
|
int nIn = 8;
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).updater(new RmsProp())
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345).updater(new RmsProp())
|
||||||
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new VariationalAutoencoder.Builder().nIn(8).nOut(10).encoderLayerSizes(12)
|
.addLayer("0", new VariationalAutoencoder.Builder().nIn(8).nOut(10).encoderLayerSizes(12)
|
||||||
.decoderLayerSizes(13).reconstructionDistribution(
|
.decoderLayerSizes(13).reconstructionDistribution(
|
||||||
|
@ -936,8 +936,8 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
int nOut = 2;
|
int nOut = 2;
|
||||||
int layerSize = 10;
|
int layerSize = 10;
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
|
NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(layerSize).build())
|
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(layerSize).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(layerSize).nOut(nOut)
|
.layer(1, new OutputLayer.Builder().nIn(layerSize).nOut(nOut)
|
||||||
.activation(Activation.SOFTMAX).lossFunction(
|
.activation(Activation.SOFTMAX).lossFunction(
|
||||||
|
@ -991,8 +991,8 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
int nOut = 3;
|
int nOut = 3;
|
||||||
int layerSize = 10;
|
int layerSize = 10;
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
|
NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(layerSize).build())
|
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(layerSize).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(layerSize).nOut(nOut)
|
.layer(1, new OutputLayer.Builder().nIn(layerSize).nOut(nOut)
|
||||||
.activation(Activation.SOFTMAX).lossFunction(
|
.activation(Activation.SOFTMAX).lossFunction(
|
||||||
|
@ -1045,12 +1045,12 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
//Spark tests don't run on windows
|
//Spark tests don't run on windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
.list()
|
||||||
.layer(new OutputLayer.Builder().nIn(4).nOut(3).build())
|
.layer(new OutputLayer.Builder().nIn(4).nOut(3).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ComputationGraphConfiguration conf2 = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf2 = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.addLayer("out", new OutputLayer.Builder().nIn(4).nOut(3).build(), "in")
|
.addLayer("out", new OutputLayer.Builder().nIn(4).nOut(3).build(), "in")
|
||||||
|
@ -1081,11 +1081,11 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
|
||||||
|
|
||||||
|
|
||||||
for(int i=0; i<3; i++ ){
|
for(int i=0; i<3; i++ ){
|
||||||
assertEquals(i, sn1.getNetwork().getLayerWiseConfigurations().getEpochCount());
|
assertEquals(i, sn1.getNetwork().getConfiguration().getEpochCount());
|
||||||
assertEquals(i, sn2.getNetwork().getConfiguration().getEpochCount());
|
assertEquals(i, sn2.getNetwork().getConfiguration().getEpochCount());
|
||||||
sn1.fit(rdd);
|
sn1.fit(rdd);
|
||||||
sn2.fit(rdd);
|
sn2.fit(rdd);
|
||||||
assertEquals(i+1, sn1.getNetwork().getLayerWiseConfigurations().getEpochCount());
|
assertEquals(i+1, sn1.getNetwork().getConfiguration().getEpochCount());
|
||||||
assertEquals(i+1, sn2.getNetwork().getConfiguration().getEpochCount());
|
assertEquals(i+1, sn2.getNetwork().getConfiguration().getEpochCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.spark.SparkConf;
|
||||||
import org.apache.spark.api.java.JavaRDD;
|
import org.apache.spark.api.java.JavaRDD;
|
||||||
import org.apache.spark.api.java.JavaSparkContext;
|
import org.apache.spark.api.java.JavaSparkContext;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -67,7 +67,7 @@ public class TestTrainingStatsCollection extends BaseSparkTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build())
|
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build())
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.deeplearning4j.core.storage.Persistable;
|
||||||
import org.deeplearning4j.core.storage.StatsStorage;
|
import org.deeplearning4j.core.storage.StatsStorage;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
@ -60,7 +60,7 @@ public class TestListeners extends BaseSparkTest {
|
||||||
JavaSparkContext sc = getContext();
|
JavaSparkContext sc = getContext();
|
||||||
int nExecutors = numExecutors();
|
int nExecutors = numExecutors();
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.RELU).build())
|
.activation(Activation.RELU).build())
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package org.deeplearning4j.rl4j.network;
|
package org.deeplearning4j.rl4j.network;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.gradient.Gradient;
|
import org.deeplearning4j.nn.gradient.Gradient;
|
||||||
import org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer;
|
import org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
@ -41,7 +41,7 @@ public class MultiLayerNetworkHandler implements INetworkHandler {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final boolean recurrent;
|
private final boolean recurrent;
|
||||||
private final MultiLayerConfiguration configuration;
|
private final NeuralNetConfiguration configuration;
|
||||||
private final String labelName;
|
private final String labelName;
|
||||||
private final String gradientName;
|
private final String gradientName;
|
||||||
private final int inputFeatureIdx;
|
private final int inputFeatureIdx;
|
||||||
|
@ -59,7 +59,7 @@ public class MultiLayerNetworkHandler implements INetworkHandler {
|
||||||
int inputFeatureIdx) {
|
int inputFeatureIdx) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
recurrent = model.getOutputLayer() instanceof RnnOutputLayer;
|
recurrent = model.getOutputLayer() instanceof RnnOutputLayer;
|
||||||
configuration = model.getLayerWiseConfigurations();
|
configuration = model.getConfiguration();
|
||||||
this.labelName = labelName;
|
this.labelName = labelName;
|
||||||
this.gradientName = gradientName;
|
this.gradientName = gradientName;
|
||||||
this.inputFeatureIdx = inputFeatureIdx;
|
this.inputFeatureIdx = inputFeatureIdx;
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class ActorCriticFactoryCompGraphStdConv implements ActorCriticFactoryCom
|
||||||
int w = (((shapeInputs[2] - 8) / 4 + 1) - 4) / 2 + 1;
|
int w = (((shapeInputs[2] - 8) / 4 + 1) - 4) / 2 + 1;
|
||||||
|
|
||||||
ComputationGraphConfiguration.GraphBuilder confB =
|
ComputationGraphConfiguration.GraphBuilder confB =
|
||||||
new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class ActorCriticFactoryCompGraphStdDense implements ActorCriticFactoryCo
|
||||||
nIn *= i;
|
nIn *= i;
|
||||||
}
|
}
|
||||||
ComputationGraphConfiguration.GraphBuilder confB =
|
ComputationGraphConfiguration.GraphBuilder confB =
|
||||||
new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
|
|
@ -24,7 +24,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
|
@ -56,7 +56,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
|
||||||
for (int i : numInputs) {
|
for (int i : numInputs) {
|
||||||
nIn *= i;
|
nIn *= i;
|
||||||
}
|
}
|
||||||
NeuralNetConfiguration.ListBuilder confB = new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
NeuralNetConfiguration.ListBuilder confB = NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
@ -81,7 +81,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
|
||||||
}
|
}
|
||||||
|
|
||||||
confB.setInputType(conf.isUseLSTM() ? InputType.recurrent(nIn) : InputType.feedForward(nIn));
|
confB.setInputType(conf.isUseLSTM() ? InputType.recurrent(nIn) : InputType.feedForward(nIn));
|
||||||
MultiLayerConfiguration mlnconf2 = confB.build();
|
NeuralNetConfiguration mlnconf2 = confB.build();
|
||||||
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf2);
|
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf2);
|
||||||
model.init();
|
model.init();
|
||||||
if (conf.getListeners() != null) {
|
if (conf.getListeners() != null) {
|
||||||
|
@ -90,7 +90,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
|
||||||
model.setListeners(new ScoreIterationListener(Constants.NEURAL_NET_ITERATION_LISTENER));
|
model.setListeners(new ScoreIterationListener(Constants.NEURAL_NET_ITERATION_LISTENER));
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder confB2 = new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
NeuralNetConfiguration.ListBuilder confB2 = NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
@ -116,7 +116,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
|
||||||
}
|
}
|
||||||
|
|
||||||
confB2.setInputType(conf.isUseLSTM() ? InputType.recurrent(nIn) : InputType.feedForward(nIn));
|
confB2.setInputType(conf.isUseLSTM() ? InputType.recurrent(nIn) : InputType.feedForward(nIn));
|
||||||
MultiLayerConfiguration mlnconf = confB2.build();
|
NeuralNetConfiguration mlnconf = confB2.build();
|
||||||
MultiLayerNetwork model2 = new MultiLayerNetwork(mlnconf);
|
MultiLayerNetwork model2 = new MultiLayerNetwork(mlnconf);
|
||||||
model2.init();
|
model2.init();
|
||||||
if (conf.getListeners() != null) {
|
if (conf.getListeners() != null) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ package org.deeplearning4j.rl4j.network.ac;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.deeplearning4j.nn.api.NeuralNetwork;
|
import org.deeplearning4j.nn.api.NeuralNetwork;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.gradient.Gradient;
|
import org.deeplearning4j.nn.gradient.Gradient;
|
||||||
import org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer;
|
import org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
@ -131,7 +131,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
|
||||||
@Override
|
@Override
|
||||||
public void applyGradients(Gradients gradients) {
|
public void applyGradients(Gradients gradients) {
|
||||||
int batchSize = (int)gradients.getBatchSize();
|
int batchSize = (int)gradients.getBatchSize();
|
||||||
MultiLayerConfiguration valueConf = valueNet.getLayerWiseConfigurations();
|
NeuralNetConfiguration valueConf = valueNet.getConfiguration();
|
||||||
int valueIterationCount = valueConf.getIterationCount();
|
int valueIterationCount = valueConf.getIterationCount();
|
||||||
int valueEpochCount = valueConf.getEpochCount();
|
int valueEpochCount = valueConf.getEpochCount();
|
||||||
Gradient valueGradient = gradients.getGradient(CommonGradientNames.ActorCritic.Value);
|
Gradient valueGradient = gradients.getGradient(CommonGradientNames.ActorCritic.Value);
|
||||||
|
@ -145,7 +145,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
|
||||||
}
|
}
|
||||||
valueConf.setIterationCount(valueIterationCount + 1);
|
valueConf.setIterationCount(valueIterationCount + 1);
|
||||||
|
|
||||||
MultiLayerConfiguration policyConf = policyNet.getLayerWiseConfigurations();
|
NeuralNetConfiguration policyConf = policyNet.getConfiguration();
|
||||||
int policyIterationCount = policyConf.getIterationCount();
|
int policyIterationCount = policyConf.getIterationCount();
|
||||||
int policyEpochCount = policyConf.getEpochCount();
|
int policyEpochCount = policyConf.getEpochCount();
|
||||||
Gradient policyGradient = gradients.getGradient(CommonGradientNames.ActorCritic.Policy);
|
Gradient policyGradient = gradients.getGradient(CommonGradientNames.ActorCritic.Policy);
|
||||||
|
@ -191,7 +191,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void applyGradient(Gradient[] gradient, int batchSize) {
|
public void applyGradient(Gradient[] gradient, int batchSize) {
|
||||||
MultiLayerConfiguration valueConf = valueNet.getLayerWiseConfigurations();
|
NeuralNetConfiguration valueConf = valueNet.getConfiguration();
|
||||||
int valueIterationCount = valueConf.getIterationCount();
|
int valueIterationCount = valueConf.getIterationCount();
|
||||||
int valueEpochCount = valueConf.getEpochCount();
|
int valueEpochCount = valueConf.getEpochCount();
|
||||||
valueNet.getUpdater().update(valueNet, gradient[0], valueIterationCount, valueEpochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());
|
valueNet.getUpdater().update(valueNet, gradient[0], valueIterationCount, valueEpochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());
|
||||||
|
@ -204,7 +204,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
|
||||||
}
|
}
|
||||||
valueConf.setIterationCount(valueIterationCount + 1);
|
valueConf.setIterationCount(valueIterationCount + 1);
|
||||||
|
|
||||||
MultiLayerConfiguration policyConf = policyNet.getLayerWiseConfigurations();
|
NeuralNetConfiguration policyConf = policyNet.getConfiguration();
|
||||||
int policyIterationCount = policyConf.getIterationCount();
|
int policyIterationCount = policyConf.getIterationCount();
|
||||||
int policyEpochCount = policyConf.getEpochCount();
|
int policyEpochCount = policyConf.getEpochCount();
|
||||||
policyNet.getUpdater().update(policyNet, gradient[1], policyIterationCount, policyEpochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());
|
policyNet.getUpdater().update(policyNet, gradient[1], policyIterationCount, policyEpochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.rl4j.network.dqn;
|
||||||
|
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.deeplearning4j.nn.api.NeuralNetwork;
|
import org.deeplearning4j.nn.api.NeuralNetwork;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.gradient.Gradient;
|
import org.deeplearning4j.nn.gradient.Gradient;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.nn.workspace.LayerWorkspaceMgr;
|
import org.deeplearning4j.nn.workspace.LayerWorkspaceMgr;
|
||||||
|
@ -157,7 +157,7 @@ public class DQN implements IDQN<DQN> {
|
||||||
public void applyGradients(Gradients gradients) {
|
public void applyGradients(Gradients gradients) {
|
||||||
Gradient qValues = gradients.getGradient(CommonGradientNames.QValues);
|
Gradient qValues = gradients.getGradient(CommonGradientNames.QValues);
|
||||||
|
|
||||||
MultiLayerConfiguration mlnConf = mln.getLayerWiseConfigurations();
|
NeuralNetConfiguration mlnConf = mln.getConfiguration();
|
||||||
int iterationCount = mlnConf.getIterationCount();
|
int iterationCount = mlnConf.getIterationCount();
|
||||||
int epochCount = mlnConf.getEpochCount();
|
int epochCount = mlnConf.getEpochCount();
|
||||||
mln.getUpdater().update(mln, qValues, iterationCount, epochCount, (int)gradients.getBatchSize(), LayerWorkspaceMgr.noWorkspaces());
|
mln.getUpdater().update(mln, qValues, iterationCount, epochCount, (int)gradients.getBatchSize(), LayerWorkspaceMgr.noWorkspaces());
|
||||||
|
@ -172,7 +172,7 @@ public class DQN implements IDQN<DQN> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyGradient(Gradient[] gradient, int batchSize) {
|
public void applyGradient(Gradient[] gradient, int batchSize) {
|
||||||
MultiLayerConfiguration mlnConf = mln.getLayerWiseConfigurations();
|
NeuralNetConfiguration mlnConf = mln.getConfiguration();
|
||||||
int iterationCount = mlnConf.getIterationCount();
|
int iterationCount = mlnConf.getIterationCount();
|
||||||
int epochCount = mlnConf.getEpochCount();
|
int epochCount = mlnConf.getEpochCount();
|
||||||
mln.getUpdater().update(mln, gradient[0], iterationCount, epochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());
|
mln.getUpdater().update(mln, gradient[0], iterationCount, epochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());
|
||||||
|
|
|
@ -24,7 +24,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
||||||
|
@ -55,7 +55,7 @@ public class DQNFactoryStdConv implements DQNFactory {
|
||||||
throw new AssertionError("Impossible to apply convolutional layer on a shape == 1");
|
throw new AssertionError("Impossible to apply convolutional layer on a shape == 1");
|
||||||
|
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder confB = new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
NeuralNetConfiguration.ListBuilder confB = NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.l2(conf.getL2())
|
.l2(conf.getL2())
|
||||||
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
||||||
|
@ -71,8 +71,8 @@ public class DQNFactoryStdConv implements DQNFactory {
|
||||||
confB.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MSE).activation(Activation.IDENTITY).nOut(numOutputs)
|
confB.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MSE).activation(Activation.IDENTITY).nOut(numOutputs)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
confB.setInputType(InputType.convolutional(shapeInputs[1], shapeInputs[2], shapeInputs[0]));
|
confB.inputType(InputType.convolutional(shapeInputs[1], shapeInputs[2], shapeInputs[0]));
|
||||||
MultiLayerConfiguration mlnconf = confB.build();
|
NeuralNetConfiguration mlnconf = confB.build();
|
||||||
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf);
|
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf);
|
||||||
model.init();
|
model.init();
|
||||||
if (conf.getListeners() != null) {
|
if (conf.getListeners() != null) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -54,7 +54,7 @@ public class DQNFactoryStdDense implements DQNFactory {
|
||||||
nIn *= i;
|
nIn *= i;
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder confB = new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
NeuralNetConfiguration.ListBuilder confB = NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
@ -82,7 +82,7 @@ public class DQNFactoryStdDense implements DQNFactory {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration mlnconf = confB.build();
|
NeuralNetConfiguration mlnconf = confB.build();
|
||||||
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf);
|
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf);
|
||||||
model.init();
|
model.init();
|
||||||
if (conf.getListeners() != null) {
|
if (conf.getListeners() != null) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class NStepRnn {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComputationGraphConfiguration.GraphBuilder buildBaseNetworkConfiguration(int lstmLayerSize, int dl1Size, int dl2Size) {
|
private static ComputationGraphConfiguration.GraphBuilder buildBaseNetworkConfiguration(int lstmLayerSize, int dl1Size, int dl2Size) {
|
||||||
return new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
return NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Adam())
|
.updater(new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class RobotLakeExample {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComputationGraphConfiguration.GraphBuilder buildBaseNetworkConfiguration() {
|
private static ComputationGraphConfiguration.GraphBuilder buildBaseNetworkConfiguration() {
|
||||||
return new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
return NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Adam())
|
.updater(new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
|
|
@ -174,7 +174,7 @@ public class TMazeExample {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComputationGraphConfiguration.GraphBuilder buildBaseNetworkConfiguration() {
|
private static ComputationGraphConfiguration.GraphBuilder buildBaseNetworkConfiguration() {
|
||||||
return new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
|
return NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Adam())
|
.updater(new Adam())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
package org.deeplearning4j.rl4j.network;
|
package org.deeplearning4j.rl4j.network;
|
||||||
|
|
||||||
import org.deeplearning4j.nn.api.Updater;
|
import org.deeplearning4j.nn.api.Updater;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.gradient.Gradient;
|
import org.deeplearning4j.nn.gradient.Gradient;
|
||||||
import org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer;
|
import org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
@ -52,7 +52,7 @@ public class MultiLayerNetworkHandlerTest {
|
||||||
|
|
||||||
private MultiLayerNetwork modelMock;
|
private MultiLayerNetwork modelMock;
|
||||||
private TrainingListener trainingListenerMock;
|
private TrainingListener trainingListenerMock;
|
||||||
private MultiLayerConfiguration configurationMock;
|
private NeuralNetConfiguration configurationMock;
|
||||||
|
|
||||||
private MultiLayerNetworkHandler sut;
|
private MultiLayerNetworkHandler sut;
|
||||||
|
|
||||||
|
@ -60,10 +60,10 @@ public class MultiLayerNetworkHandlerTest {
|
||||||
modelMock = mock(MultiLayerNetwork.class);
|
modelMock = mock(MultiLayerNetwork.class);
|
||||||
trainingListenerMock = mock(TrainingListener.class);
|
trainingListenerMock = mock(TrainingListener.class);
|
||||||
|
|
||||||
configurationMock = mock(MultiLayerConfiguration.class);
|
configurationMock = mock(NeuralNetConfiguration.class);
|
||||||
when(configurationMock.getIterationCount()).thenReturn(123);
|
when(configurationMock.getIterationCount()).thenReturn(123);
|
||||||
when(configurationMock.getEpochCount()).thenReturn(234);
|
when(configurationMock.getEpochCount()).thenReturn(234);
|
||||||
when(modelMock.getLayerWiseConfigurations()).thenReturn(configurationMock);
|
when(modelMock.getConfiguration()).thenReturn(configurationMock);
|
||||||
|
|
||||||
if(setupRecurrent) {
|
if(setupRecurrent) {
|
||||||
when(modelMock.getOutputLayer()).thenReturn(new RnnOutputLayer(null, null));
|
when(modelMock.getOutputLayer()).thenReturn(new RnnOutputLayer(null, null));
|
||||||
|
|
|
@ -166,9 +166,9 @@ public class PolicyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testACPolicy() throws Exception {
|
public void testACPolicy() throws Exception {
|
||||||
ComputationGraph cg = new ComputationGraph(new NeuralNetConfiguration.Builder().seed(444).graphBuilder().addInputs("input")
|
ComputationGraph cg = new ComputationGraph(NeuralNetConfiguration.builder().seed(444).graphBuilder().addInputs("input")
|
||||||
.addLayer("output", new OutputLayer.Builder().nOut(1).lossFunction(LossFunctions.LossFunction.XENT).activation(Activation.SIGMOID).build(), "input").setOutputs("output").build());
|
.addLayer("output", new OutputLayer.Builder().nOut(1).lossFunction(LossFunctions.LossFunction.XENT).activation(Activation.SIGMOID).build(), "input").setOutputs("output").build());
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(new NeuralNetConfiguration.Builder().seed(555).list()
|
MultiLayerNetwork mln = new MultiLayerNetwork(NeuralNetConfiguration.builder().seed(555).list()
|
||||||
.layer(0, new OutputLayer.Builder().nOut(1).lossFunction(LossFunctions.LossFunction.XENT).activation(Activation.SIGMOID).build()).build());
|
.layer(0, new OutputLayer.Builder().nOut(1).lossFunction(LossFunctions.LossFunction.XENT).activation(Activation.SIGMOID).build()).build());
|
||||||
|
|
||||||
ACPolicy policy = new ACPolicy(new DummyAC(mln), true, Nd4j.getRandom());
|
ACPolicy policy = new ACPolicy(new DummyAC(mln), true, Nd4j.getRandom());
|
||||||
|
|
|
@ -48,12 +48,12 @@ Deeplearning4J offers a very high level API for defining even complex neural net
|
||||||
you how LeNet, a convolutional neural network, is defined in DL4J.
|
you how LeNet, a convolutional neural network, is defined in DL4J.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(seed)
|
.seed(seed)
|
||||||
.l2(0.0005)
|
.l2(0.0005)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Adam(1e-3))
|
.updater(new Adam(1e-3))
|
||||||
.list()
|
|
||||||
.layer(new ConvolutionLayer.Builder(5, 5)
|
.layer(new ConvolutionLayer.Builder(5, 5)
|
||||||
.stride(1,1)
|
.stride(1,1)
|
||||||
.nOut(20)
|
.nOut(20)
|
||||||
|
@ -78,7 +78,7 @@ MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
||||||
.nOut(outputNum)
|
.nOut(outputNum)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutionalFlat(28,28,1))
|
.inputType(InputType.convolutionalFlat(28,28,1))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -21,15 +21,21 @@
|
||||||
|
|
||||||
package net.brutex.gan;
|
package net.brutex.gan;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import javax.ws.rs.client.ClientBuilder;
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.WindowConstants;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.datavec.api.Writable;
|
|
||||||
import org.datavec.api.records.reader.RecordReader;
|
|
||||||
import org.datavec.api.split.FileSplit;
|
import org.datavec.api.split.FileSplit;
|
||||||
import org.datavec.image.loader.NativeImageLoader;
|
import org.datavec.image.loader.NativeImageLoader;
|
||||||
import org.datavec.image.recordreader.ImageRecordReader;
|
import org.datavec.image.recordreader.ImageRecordReader;
|
||||||
|
@ -37,41 +43,33 @@ import org.datavec.image.transform.ColorConversionTransform;
|
||||||
import org.datavec.image.transform.ImageTransform;
|
import org.datavec.image.transform.ImageTransform;
|
||||||
import org.datavec.image.transform.PipelineImageTransform;
|
import org.datavec.image.transform.PipelineImageTransform;
|
||||||
import org.datavec.image.transform.ResizeImageTransform;
|
import org.datavec.image.transform.ResizeImageTransform;
|
||||||
import org.datavec.image.transform.ScaleImageTransform;
|
|
||||||
import org.datavec.image.transform.ShowImageTransform;
|
import org.datavec.image.transform.ShowImageTransform;
|
||||||
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
|
||||||
import org.deeplearning4j.nn.conf.GradientNormalization;
|
import org.deeplearning4j.nn.conf.GradientNormalization;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.ActivationLayer;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.DropoutLayer;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.LayerConfiguration;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.misc.FrozenLayerWithBackprop;
|
import org.deeplearning4j.nn.conf.layers.misc.FrozenLayerWithBackprop;
|
||||||
|
import org.deeplearning4j.nn.conf.weightnoise.WeightNoise;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.nn.weights.WeightInit;
|
import org.deeplearning4j.nn.weights.WeightInit;
|
||||||
|
import org.deeplearning4j.nn.weights.WeightInitXavier;
|
||||||
import org.deeplearning4j.optimize.listeners.PerformanceListener;
|
import org.deeplearning4j.optimize.listeners.PerformanceListener;
|
||||||
import org.deeplearning4j.optimize.listeners.ScoreToChartListener;
|
import org.deeplearning4j.optimize.listeners.ScoreToChartListener;
|
||||||
import org.glassfish.jersey.client.JerseyClient;
|
|
||||||
import org.glassfish.jersey.client.JerseyClientBuilder;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.linalg.activations.Activation;
|
import org.nd4j.linalg.activations.Activation;
|
||||||
import org.nd4j.linalg.activations.impl.ActivationLReLU;
|
import org.nd4j.linalg.activations.impl.ActivationLReLU;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.dataset.DataSet;
|
import org.nd4j.linalg.dataset.DataSet;
|
||||||
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
||||||
import org.nd4j.linalg.dataset.api.preprocessor.ImagePreProcessingScaler;
|
|
||||||
import org.nd4j.linalg.dataset.api.preprocessor.NormalizerMinMaxScaler;
|
|
||||||
import org.nd4j.linalg.factory.Nd4j;
|
import org.nd4j.linalg.factory.Nd4j;
|
||||||
import org.nd4j.linalg.learning.config.Adam;
|
import org.nd4j.linalg.learning.config.Adam;
|
||||||
import org.nd4j.linalg.learning.config.IUpdater;
|
import org.nd4j.linalg.learning.config.IUpdater;
|
||||||
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import org.nd4j.linalg.lossfunctions.LossFunctions.LossFunction;
|
import org.nd4j.linalg.lossfunctions.LossFunctions.LossFunction;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -95,8 +93,8 @@ public class App {
|
||||||
private static JPanel panel;
|
private static JPanel panel;
|
||||||
private static JPanel panel2;
|
private static JPanel panel2;
|
||||||
|
|
||||||
private static Layer[] genLayers() {
|
private static LayerConfiguration[] genLayers() {
|
||||||
return new Layer[] {
|
return new LayerConfiguration[] {
|
||||||
new DenseLayer.Builder().nIn(INPUT).nOut(X_DIM*Y_DIM*CHANNELS).weightInit(WeightInit.NORMAL).build(),
|
new DenseLayer.Builder().nIn(INPUT).nOut(X_DIM*Y_DIM*CHANNELS).weightInit(WeightInit.NORMAL).build(),
|
||||||
new ActivationLayer.Builder(new ActivationLReLU(0.2)).build(),
|
new ActivationLayer.Builder(new ActivationLReLU(0.2)).build(),
|
||||||
new DenseLayer.Builder().nIn(X_DIM*Y_DIM*CHANNELS).nOut(X_DIM*Y_DIM).build(),
|
new DenseLayer.Builder().nIn(X_DIM*Y_DIM*CHANNELS).nOut(X_DIM*Y_DIM).build(),
|
||||||
|
@ -106,30 +104,33 @@ public class App {
|
||||||
new DenseLayer.Builder().nIn(X_DIM*Y_DIM).nOut(X_DIM*Y_DIM*CHANNELS).activation(Activation.TANH)
|
new DenseLayer.Builder().nIn(X_DIM*Y_DIM).nOut(X_DIM*Y_DIM*CHANNELS).activation(Activation.TANH)
|
||||||
.build()
|
.build()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a network config that takes in a 10x10 random number and produces a 28x28 grayscale image.
|
* Returns a network config that takes in a 10x10 random number and produces a 28x28 grayscale image.
|
||||||
*
|
*
|
||||||
* @return config
|
* @return config
|
||||||
*/
|
*/
|
||||||
private static MultiLayerConfiguration generator() {
|
private static NeuralNetConfiguration generator() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(42)
|
.seed(42)
|
||||||
.updater(UPDATER)
|
.updater(UPDATER)
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
|
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
|
||||||
|
//.weightInit(WeightInit.XAVIER)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.IDENTITY)
|
.activation(Activation.IDENTITY)
|
||||||
.list(genLayers())
|
.layersFromArray(genLayers())
|
||||||
.setInputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
|
.inputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
|
||||||
|
// .inputPreProcessor("CNN1", new FeedForwardToCnnPreProcessor(Y_DIM, X_DIM, CHANNELS))
|
||||||
.build();
|
.build();
|
||||||
|
((NeuralNetConfiguration) conf).init();
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Layer[] disLayers() {
|
private static LayerConfiguration[] disLayers() {
|
||||||
return new Layer[]{
|
return new LayerConfiguration[]{
|
||||||
new DenseLayer.Builder().nOut(X_DIM*Y_DIM*CHANNELS*2).build(), //input is set by setInputType on the network
|
new DenseLayer.Builder().nOut(X_DIM*Y_DIM*CHANNELS*2).build(), //input is set by setInputType on the network
|
||||||
new ActivationLayer.Builder(new ActivationLReLU(0.2)).build(),
|
new ActivationLayer.Builder(new ActivationLReLU(0.2)).build(),
|
||||||
new DropoutLayer.Builder(1 - 0.5).build(),
|
new DropoutLayer.Builder(1 - 0.5).build(),
|
||||||
|
@ -146,44 +147,51 @@ public class App {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MultiLayerConfiguration discriminator() {
|
private static NeuralNetConfiguration discriminator() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
|
||||||
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(42)
|
.seed(42)
|
||||||
.updater(UPDATER)
|
.updater(UPDATER)
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
|
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
//.weightInitFn(new WeightInitXavier())
|
||||||
|
//.activationFn(new ActivationIdentity())
|
||||||
.activation(Activation.IDENTITY)
|
.activation(Activation.IDENTITY)
|
||||||
.list(disLayers())
|
.layersFromArray(disLayers())
|
||||||
.setInputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
|
.inputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
|
||||||
.build();
|
.build();
|
||||||
|
((NeuralNetConfiguration) conf).init();
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MultiLayerConfiguration gan() {
|
private static NeuralNetConfiguration gan() {
|
||||||
Layer[] genLayers = genLayers();
|
LayerConfiguration[] genLayers = genLayers();
|
||||||
Layer[] disLayers = Arrays.stream(disLayers())
|
LayerConfiguration[] disLayers = Arrays.stream(disLayers())
|
||||||
.map((layer) -> {
|
.map((layer) -> {
|
||||||
if (layer instanceof DenseLayer || layer instanceof OutputLayer) {
|
if (layer instanceof DenseLayer || layer instanceof OutputLayer) {
|
||||||
return new FrozenLayerWithBackprop(layer);
|
return new FrozenLayerWithBackprop(layer);
|
||||||
} else {
|
} else {
|
||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
}).toArray(Layer[]::new);
|
}).toArray(LayerConfiguration[]::new);
|
||||||
Layer[] layers = ArrayUtils.addAll(genLayers, disLayers);
|
LayerConfiguration[] layers = ArrayUtils.addAll(genLayers, disLayers);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(42)
|
.seed(42)
|
||||||
.updater(UPDATER)
|
.updater( Adam.builder().learningRate(0.0002).beta1(0.5).build() )
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization( GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
|
.gradientNormalizationThreshold( 100 )
|
||||||
.weightInit(WeightInit.XAVIER)
|
//.weightInitFn( new WeightInitXavier() ) //this is internal
|
||||||
.activation(Activation.IDENTITY)
|
.weightNoise(new WeightNoise(new NormalDistribution(0.5, 0.5)))
|
||||||
.list(layers)
|
.weightInit( WeightInit.XAVIER)
|
||||||
.setInputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
|
//.activationFn( new ActivationIdentity()) //this is internal
|
||||||
|
.activation( Activation.IDENTITY )
|
||||||
|
.layersFromArray( layers )
|
||||||
|
.inputType( InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
|
||||||
.build();
|
.build();
|
||||||
|
((NeuralNetConfiguration) conf).init();
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +202,8 @@ public class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
|
|
||||||
|
log.info("\u001B[32m Some \u001B[1m green \u001B[22m text \u001B[0m \u001B[7m Inverted\u001B[0m ");
|
||||||
Nd4j.getMemoryManager().setAutoGcWindow(15 * 1000);
|
Nd4j.getMemoryManager().setAutoGcWindow(15 * 1000);
|
||||||
|
|
||||||
// MnistDataSetIterator trainData = new MnistDataSetIterator(128, true, 45);
|
// MnistDataSetIterator trainData = new MnistDataSetIterator(128, true, 45);
|
||||||
|
@ -219,16 +229,17 @@ public class App {
|
||||||
MultiLayerNetwork gen = new MultiLayerNetwork(generator());
|
MultiLayerNetwork gen = new MultiLayerNetwork(generator());
|
||||||
MultiLayerNetwork dis = new MultiLayerNetwork(discriminator());
|
MultiLayerNetwork dis = new MultiLayerNetwork(discriminator());
|
||||||
MultiLayerNetwork gan = new MultiLayerNetwork(gan());
|
MultiLayerNetwork gan = new MultiLayerNetwork(gan());
|
||||||
gen.init();
|
gen.init(); log.debug("Generator network: {}", gen);
|
||||||
dis.init();
|
dis.init(); log.debug("Discriminator network: {}", dis);
|
||||||
gan.init();
|
gan.init(); log.debug("Complete GAN network: {}", gan);
|
||||||
|
|
||||||
|
|
||||||
copyParams(gen, dis, gan);
|
copyParams(gen, dis, gan);
|
||||||
|
|
||||||
//gen.setListeners(new PerformanceListener(10, true));
|
gen.addTrainingListeners(new PerformanceListener(10, true));
|
||||||
//dis.setListeners(new PerformanceListener(10, true));
|
dis.addTrainingListeners(new PerformanceListener(10, true));
|
||||||
//gan.setListeners(new PerformanceListener(10, true));
|
gan.addTrainingListeners(new PerformanceListener(10, true));
|
||||||
gan.setListeners(new ScoreToChartListener("gan"));
|
gan.addTrainingListeners(new ScoreToChartListener("gan"));
|
||||||
//dis.setListeners(new ScoreToChartListener("dis"));
|
//dis.setListeners(new ScoreToChartListener("dis"));
|
||||||
|
|
||||||
gan.fit(Nd4j.rand(batchSize, CHANNELS, X_DIM, Y_DIM), Nd4j.zeros(batchSize, 1));
|
gan.fit(Nd4j.rand(batchSize, CHANNELS, X_DIM, Y_DIM), Nd4j.zeros(batchSize, 1));
|
||||||
|
@ -315,23 +326,25 @@ public class App {
|
||||||
int genLayerCount = gen.getLayers().length;
|
int genLayerCount = gen.getLayers().length;
|
||||||
for (int i = 0; i < gan.getLayers().length; i++) {
|
for (int i = 0; i < gan.getLayers().length; i++) {
|
||||||
if (i < genLayerCount) {
|
if (i < genLayerCount) {
|
||||||
gen.getLayer(i).setParams(gan.getLayer(i).params());
|
if(gan.getLayer(i).getParams() != null)
|
||||||
|
gen.getLayer(i).setParams(gan.getLayer(i).getParams());
|
||||||
} else {
|
} else {
|
||||||
dis.getLayer(i - genLayerCount).setParams(gan.getLayer(i).params());
|
if(gan.getLayer(i).getParams() != null)
|
||||||
|
dis.getLayer(i - genLayerCount).setParams(gan.getLayer(i).getParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateGen(MultiLayerNetwork gen, MultiLayerNetwork gan) {
|
private static void updateGen(MultiLayerNetwork gen, MultiLayerNetwork gan) {
|
||||||
for (int i = 0; i < gen.getLayers().length; i++) {
|
for (int i = 0; i < gen.getLayers().length; i++) {
|
||||||
gen.getLayer(i).setParams(gan.getLayer(i).params());
|
gen.getLayer(i).setParams(gan.getLayer(i).getParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateGan(MultiLayerNetwork gen, MultiLayerNetwork dis, MultiLayerNetwork gan) {
|
private static void updateGan(MultiLayerNetwork gen, MultiLayerNetwork dis, MultiLayerNetwork gan) {
|
||||||
int genLayerCount = gen.getLayers().length;
|
int genLayerCount = gen.getLayers().length;
|
||||||
for (int i = genLayerCount; i < gan.getLayers().length; i++) {
|
for (int i = genLayerCount; i < gan.getLayers().length; i++) {
|
||||||
gan.getLayer(i).setParams(dis.getLayer(i - genLayerCount).params());
|
gan.getLayer(i).setParams(dis.getLayer(i - genLayerCount).getParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.deeplearning4j.nn.api.Layer;
|
import org.deeplearning4j.nn.api.Layer;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.*;
|
import org.deeplearning4j.nn.conf.*;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.LayerConfiguration;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.optimize.api.BaseTrainingListener;
|
import org.deeplearning4j.optimize.api.BaseTrainingListener;
|
||||||
import org.nd4j.evaluation.classification.Evaluation;
|
import org.nd4j.evaluation.classification.Evaluation;
|
||||||
|
@ -114,15 +115,15 @@ public class GAN {
|
||||||
|
|
||||||
|
|
||||||
public void setGeneratorListeners(BaseTrainingListener[] listeners) {
|
public void setGeneratorListeners(BaseTrainingListener[] listeners) {
|
||||||
generator.setListeners(listeners);
|
generator.addTrainingListeners(listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDiscriminatorListeners(BaseTrainingListener[] listeners) {
|
public void setDiscriminatorListeners(BaseTrainingListener[] listeners) {
|
||||||
discriminator.setListeners(listeners);
|
discriminator.addTrainingListeners(listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGanListeners(BaseTrainingListener[] listeners) {
|
public void setGanListeners(BaseTrainingListener[] listeners) {
|
||||||
gan.setListeners(listeners);
|
gan.addTrainingListeners(listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fit(DataSetIterator realData, int numEpochs) {
|
public void fit(DataSetIterator realData, int numEpochs) {
|
||||||
|
@ -199,13 +200,13 @@ public class GAN {
|
||||||
|
|
||||||
Layer[] disLayers = ganDiscriminator.getLayers();
|
Layer[] disLayers = ganDiscriminator.getLayers();
|
||||||
Layer[] layers = ArrayUtils.addAll(genLayers, disLayers);
|
Layer[] layers = ArrayUtils.addAll(genLayers, disLayers);
|
||||||
MultiLayerConfiguration genConf = generator.getLayerWiseConfigurations();
|
NeuralNetConfiguration genConf = generator.getNetConfiguration();
|
||||||
MultiLayerConfiguration disConf = ganDiscriminator.getLayerWiseConfigurations();
|
NeuralNetConfiguration disConf = ganDiscriminator.getNetConfiguration();
|
||||||
org.deeplearning4j.nn.conf.layers.Layer[] confLayers = new org.deeplearning4j.nn.conf.layers.Layer[layers.length];
|
LayerConfiguration[] confLayers = new LayerConfiguration[layers.length];
|
||||||
|
|
||||||
Map<Integer, InputPreProcessor> preProcessors = new HashMap<>();
|
Map<Integer, InputPreProcessor> preProcessors = new HashMap<>();
|
||||||
for (int i = 0; i < layers.length; i++) {
|
for (int i = 0; i < layers.length; i++) {
|
||||||
confLayers[i] = layers[i].conf().getLayer();
|
confLayers[i] = layers[i].getLayerConfiguration();
|
||||||
if (i < numGenLayers) {
|
if (i < numGenLayers) {
|
||||||
preProcessors.put(i, genConf.getInputPreProcess(i));
|
preProcessors.put(i, genConf.getInputPreProcess(i));
|
||||||
} else {
|
} else {
|
||||||
|
@ -213,7 +214,7 @@ public class GAN {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration ganConf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration ganConf = NeuralNetConfiguration.builder()
|
||||||
.seed(seed)
|
.seed(seed)
|
||||||
.updater(updater)
|
.updater(updater)
|
||||||
.biasUpdater(biasUpdater)
|
.biasUpdater(biasUpdater)
|
||||||
|
@ -224,7 +225,7 @@ public class GAN {
|
||||||
.trainingWorkspaceMode(trainingWorkSpaceMode)
|
.trainingWorkspaceMode(trainingWorkSpaceMode)
|
||||||
.inferenceWorkspaceMode(inferenceWorkspaceMode)
|
.inferenceWorkspaceMode(inferenceWorkspaceMode)
|
||||||
.cacheMode(cacheMode)
|
.cacheMode(cacheMode)
|
||||||
.list(confLayers)
|
.layersFromArray(confLayers)
|
||||||
.inputPreProcessors(preProcessors)
|
.inputPreProcessors(preProcessors)
|
||||||
.build();
|
.build();
|
||||||
gan = new MultiLayerNetwork(ganConf);
|
gan = new MultiLayerNetwork(ganConf);
|
||||||
|
@ -238,9 +239,9 @@ public class GAN {
|
||||||
int genLayerCount = generator.getLayers().length;
|
int genLayerCount = generator.getLayers().length;
|
||||||
for (int i = 0; i < gan.getLayers().length; i++) {
|
for (int i = 0; i < gan.getLayers().length; i++) {
|
||||||
if (i < genLayerCount) {
|
if (i < genLayerCount) {
|
||||||
generator.getLayer(i).setParams(gan.getLayer(i).params());
|
generator.getLayer(i).setParams(gan.getLayer(i).getParams());
|
||||||
} else {
|
} else {
|
||||||
discriminator.getLayer(i - genLayerCount).setParams(gan.getLayer(i).params());
|
discriminator.getLayer(i - genLayerCount).setParams(gan.getLayer(i).getParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +252,7 @@ public class GAN {
|
||||||
*/
|
*/
|
||||||
private void updateGeneratorFromGan() {
|
private void updateGeneratorFromGan() {
|
||||||
for (int i = 0; i < generator.getLayers().length; i++) {
|
for (int i = 0; i < generator.getLayers().length; i++) {
|
||||||
generator.getLayer(i).setParams(gan.getLayer(i).params());
|
generator.getLayer(i).setParams(gan.getLayer(i).getParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,12 +263,12 @@ public class GAN {
|
||||||
private void updateGanWithDiscriminator() {
|
private void updateGanWithDiscriminator() {
|
||||||
int genLayerCount = generator.getLayers().length;
|
int genLayerCount = generator.getLayers().length;
|
||||||
for (int i = genLayerCount; i < gan.getLayers().length; i++) {
|
for (int i = genLayerCount; i < gan.getLayers().length; i++) {
|
||||||
gan.getLayer(i).setParams(discriminator.getLayer(i - genLayerCount).params());
|
gan.getLayer(i).setParams(discriminator.getLayer(i - genLayerCount).getParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GAN builder, used as a starting point for creating a MultiLayerConfiguration or
|
* GAN builder, used as a starting point for creating a NeuralNetConfiguration or
|
||||||
* ComputationGraphConfiguration.<br>
|
* ComputationGraphConfiguration.<br>
|
||||||
*/
|
*/
|
||||||
public static class Builder implements Cloneable {
|
public static class Builder implements Cloneable {
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class MnistDCGANExample {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Supplier<MultiLayerNetwork> genSupplier = () -> {
|
Supplier<MultiLayerNetwork> genSupplier = () -> {
|
||||||
return new MultiLayerNetwork(new NeuralNetConfiguration.Builder().list()
|
return new MultiLayerNetwork(NeuralNetConfiguration.builder()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(latentDim).nOut(width / 2 * height / 2 * 128)
|
.layer(0, new DenseLayer.Builder().nIn(latentDim).nOut(width / 2 * height / 2 * 128)
|
||||||
.activation(Activation.LEAKYRELU).weightInit(WeightInit.NORMAL).build())
|
.activation(Activation.LEAKYRELU).weightInit(WeightInit.NORMAL).build())
|
||||||
.layer(1, new Convolution2D.Builder().nIn(128).nOut(128).kernelSize(5, 5)
|
.layer(1, new Convolution2D.Builder().nIn(128).nOut(128).kernelSize(5, 5)
|
||||||
|
@ -119,16 +119,16 @@ public class MnistDCGANExample {
|
||||||
.inputPreProcessor(1,
|
.inputPreProcessor(1,
|
||||||
new FeedForwardToCnnPreProcessor(height / 2, width / 2, 128))
|
new FeedForwardToCnnPreProcessor(height / 2, width / 2, 128))
|
||||||
.inputPreProcessor(6, new CnnToFeedForwardPreProcessor(height, width, channels))
|
.inputPreProcessor(6, new CnnToFeedForwardPreProcessor(height, width, channels))
|
||||||
.setInputType(InputType.feedForward(latentDim))
|
.inputType(InputType.feedForward(latentDim))
|
||||||
.build());
|
.build());
|
||||||
};
|
};
|
||||||
|
|
||||||
GAN.DiscriminatorProvider discriminatorProvider = (updater) -> {
|
GAN.DiscriminatorProvider discriminatorProvider = (updater) -> {
|
||||||
return new MultiLayerNetwork(new NeuralNetConfiguration.Builder()
|
return new MultiLayerNetwork(NeuralNetConfiguration.builder()
|
||||||
.updater(new RmsProp.Builder().learningRate(0.0008).rmsDecay(1e-8).build())
|
.updater(new RmsProp.Builder().learningRate(0.0008).rmsDecay(1e-8).build())
|
||||||
//.gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)
|
//.gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)
|
||||||
//.gradientNormalizationThreshold(100.0)
|
//.gradientNormalizationThreshold(100.0)
|
||||||
.list()
|
|
||||||
.layer(0, new Convolution2D.Builder().nIn(channels).nOut(64).kernelSize(3, 3)
|
.layer(0, new Convolution2D.Builder().nIn(channels).nOut(64).kernelSize(3, 3)
|
||||||
.activation(Activation.LEAKYRELU).build())
|
.activation(Activation.LEAKYRELU).build())
|
||||||
.layer(1, new Convolution2D.Builder().nIn(64).nOut(64).kernelSize(3, 3).stride(2, 2)
|
.layer(1, new Convolution2D.Builder().nIn(64).nOut(64).kernelSize(3, 3).stride(2, 2)
|
||||||
|
@ -142,7 +142,7 @@ public class MnistDCGANExample {
|
||||||
.layer(6, new LossLayer.Builder().lossFunction(LossFunctions.LossFunction.XENT).build())
|
.layer(6, new LossLayer.Builder().lossFunction(LossFunctions.LossFunction.XENT).build())
|
||||||
.inputPreProcessor(0, new FeedForwardToCnnPreProcessor(height, width, channels))
|
.inputPreProcessor(0, new FeedForwardToCnnPreProcessor(height, width, channels))
|
||||||
.inputPreProcessor(4, new CnnToFeedForwardPreProcessor(2, 2, 64))
|
.inputPreProcessor(4, new CnnToFeedForwardPreProcessor(2, 2, 64))
|
||||||
.setInputType(InputType.convolutionalFlat(height, width, channels))
|
.inputType(InputType.convolutionalFlat(height, width, channels))
|
||||||
.build());
|
.build());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ public class MnistDCGANExample {
|
||||||
.updater(new RmsProp.Builder().learningRate(0.0008).rmsDecay(1e-8).build())
|
.updater(new RmsProp.Builder().learningRate(0.0008).rmsDecay(1e-8).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
gan.getGenerator().setListeners(new PerformanceListener(1, true));
|
gan.getGenerator().addTrainingListeners(new PerformanceListener(1, true));
|
||||||
gan.getDiscriminator().setListeners(new PerformanceListener(1, true));
|
gan.getDiscriminator().addTrainingListeners(new PerformanceListener(1, true));
|
||||||
|
|
||||||
Nd4j.getMemoryManager().setAutoGcWindow(15 * 1000);
|
Nd4j.getMemoryManager().setAutoGcWindow(15 * 1000);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ package net.brutex.gan;
|
||||||
|
|
||||||
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.GradientNormalization;
|
import org.deeplearning4j.nn.conf.GradientNormalization;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.ActivationLayer;
|
import org.deeplearning4j.nn.conf.layers.ActivationLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
|
@ -57,12 +56,12 @@ public class MnistSimpleGAN {
|
||||||
|
|
||||||
|
|
||||||
public static MultiLayerNetwork getGenerator() {
|
public static MultiLayerNetwork getGenerator() {
|
||||||
MultiLayerConfiguration genConf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration genConf = NeuralNetConfiguration.builder()
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.IDENTITY)
|
.activation(Activation.IDENTITY)
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.gradientNormalizationThreshold(100)
|
.gradientNormalizationThreshold(100)
|
||||||
.list()
|
|
||||||
.layer(new DenseLayer.Builder().nIn(100).nOut(256).weightInit(WeightInit.NORMAL).build())
|
.layer(new DenseLayer.Builder().nIn(100).nOut(256).weightInit(WeightInit.NORMAL).build())
|
||||||
.layer(new ActivationLayer.Builder(new ActivationLReLU(0.2)).build())
|
.layer(new ActivationLayer.Builder(new ActivationLReLU(0.2)).build())
|
||||||
.layer(new DenseLayer.Builder().nIn(256).nOut(512).build())
|
.layer(new DenseLayer.Builder().nIn(256).nOut(512).build())
|
||||||
|
@ -76,14 +75,14 @@ public class MnistSimpleGAN {
|
||||||
|
|
||||||
|
|
||||||
public static MultiLayerNetwork getDiscriminator(IUpdater updater) {
|
public static MultiLayerNetwork getDiscriminator(IUpdater updater) {
|
||||||
MultiLayerConfiguration discConf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration discConf = NeuralNetConfiguration.builder()
|
||||||
.seed(42)
|
.seed(42)
|
||||||
.updater(updater)
|
.updater(updater)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.IDENTITY)
|
.activation(Activation.IDENTITY)
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.gradientNormalizationThreshold(100)
|
.gradientNormalizationThreshold(100)
|
||||||
.list()
|
|
||||||
.layer(new DenseLayer.Builder().nIn(784).nOut(1024).updater(updater).build())
|
.layer(new DenseLayer.Builder().nIn(784).nOut(1024).updater(updater).build())
|
||||||
.layer(new ActivationLayer.Builder(new ActivationLReLU(0.2)).build())
|
.layer(new ActivationLayer.Builder(new ActivationLReLU(0.2)).build())
|
||||||
.layer(new DropoutLayer.Builder(1 - 0.5).build())
|
.layer(new DropoutLayer.Builder(1 - 0.5).build())
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.apache.spark.sql.RowFactory;
|
||||||
import org.apache.spark.sql.SparkSession;
|
import org.apache.spark.sql.SparkSession;
|
||||||
import org.apache.spark.sql.types.DataTypes;
|
import org.apache.spark.sql.types.DataTypes;
|
||||||
import org.apache.spark.sql.types.Metadata;
|
import org.apache.spark.sql.types.Metadata;
|
||||||
import org.apache.spark.sql.types.StringType;
|
|
||||||
import org.apache.spark.sql.types.StructField;
|
import org.apache.spark.sql.types.StructField;
|
||||||
import org.apache.spark.sql.types.StructType;
|
import org.apache.spark.sql.types.StructType;
|
||||||
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
|
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
|
||||||
|
@ -43,12 +42,10 @@ import org.datavec.api.transform.TransformProcess;
|
||||||
import org.datavec.api.transform.filter.FilterInvalidValues;
|
import org.datavec.api.transform.filter.FilterInvalidValues;
|
||||||
import org.datavec.api.transform.schema.Schema;
|
import org.datavec.api.transform.schema.Schema;
|
||||||
import org.datavec.api.Writable;
|
import org.datavec.api.Writable;
|
||||||
import org.datavec.spark.transform.Normalization;
|
|
||||||
import org.datavec.spark.transform.SparkTransformExecutor;
|
import org.datavec.spark.transform.SparkTransformExecutor;
|
||||||
import org.datavec.spark.transform.misc.StringToWritablesFunction;
|
import org.datavec.spark.transform.misc.StringToWritablesFunction;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator.Set;
|
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator.Set;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -287,15 +284,15 @@ public class BrianTest extends BaseSparkSessionTest {
|
||||||
|
|
||||||
//Define Network
|
//Define Network
|
||||||
|
|
||||||
MultiLayerConfiguration multiLayerConfiguration = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration multiLayerConfiguration = NeuralNetConfiguration.builder()
|
||||||
.seed(123)
|
.seed(123)
|
||||||
.updater(new Nesterovs(0.1, 0.9))
|
.updater(new Nesterovs(0.1, 0.9))
|
||||||
.list()
|
|
||||||
.layer(0, new DenseLayer.Builder().nIn(5).nOut(20).weightInit(WeightInit.XAVIER)
|
.layer(0, new DenseLayer.Builder().nIn(5).nOut(20).weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.RELU).l2(0.001).build())
|
.activation(Activation.RELU).l2(0.001).build())
|
||||||
.layer(1, new DenseLayer.Builder().nIn(20).nOut(20).weightInit(WeightInit.XAVIER)
|
.layer(1, new DenseLayer.Builder().nIn(20).nOut(20).weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.RELU).build())
|
.activation(Activation.RELU).build())
|
||||||
//.layer(2, new DenseLayer.Builder().nIn(9).nOut(9).weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
//.layer(2, new DenseLayerConfiguration.Builder().nIn(9).nOut(9).weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.XENT).nIn(20).nOut(4)
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.XENT).nIn(20).nOut(4)
|
||||||
.weightInit(WeightInit.XAVIER).activation(Activation.SIGMOID).build())
|
.weightInit(WeightInit.XAVIER).activation(Activation.SIGMOID).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.datavec.api.transform.schema.Schema;
|
||||||
import org.datavec.api.Writable;
|
import org.datavec.api.Writable;
|
||||||
import org.datavec.spark.transform.SparkTransformExecutor;
|
import org.datavec.spark.transform.SparkTransformExecutor;
|
||||||
import org.datavec.spark.transform.misc.StringToWritablesFunction;
|
import org.datavec.spark.transform.misc.StringToWritablesFunction;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -295,13 +294,13 @@ public class BrianTest2 /*extends BaseDL4JTest*/ {
|
||||||
*/
|
*/
|
||||||
//Define Network
|
//Define Network
|
||||||
|
|
||||||
MultiLayerConfiguration multiLayerConfiguration = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration multiLayerConfiguration = NeuralNetConfiguration.builder()
|
||||||
.seed(123)
|
.seed(123)
|
||||||
.updater(new Nesterovs(0.1, 0.9))
|
.updater(new Nesterovs(0.1, 0.9))
|
||||||
.list()
|
|
||||||
.layer(0, new DenseLayer.Builder().nIn(5).nOut(20).weightInit(WeightInit.XAVIER).activation(Activation.RELU).l2(0.001).build())
|
.layer(0, new DenseLayer.Builder().nIn(5).nOut(20).weightInit(WeightInit.XAVIER).activation(Activation.RELU).l2(0.001).build())
|
||||||
.layer(1, new DenseLayer.Builder().nIn(20).nOut(20).weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
.layer(1, new DenseLayer.Builder().nIn(20).nOut(20).weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
||||||
//.layer(2, new DenseLayer.Builder().nIn(9).nOut(9).weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
//.layer(2, new DenseLayerConfiguration.Builder().nIn(9).nOut(9).weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.XENT).nIn(20).nOut(4).weightInit(WeightInit.XAVIER).activation(Activation.SIGMOID).build())
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.XENT).nIn(20).nOut(4).weightInit(WeightInit.XAVIER).activation(Activation.SIGMOID).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
package net.brutex.spark;
|
package net.brutex.spark;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
//import net.brutex.ai.performance.storage.PostgresStatsStorage;
|
//import net.brutex.ai.performance.storage.PostgresStatsStorage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.datavec.api.records.reader.RecordReader;
|
import org.datavec.api.records.reader.RecordReader;
|
||||||
|
@ -29,22 +28,17 @@ import org.datavec.api.records.reader.impl.collection.ListStringRecordReader;
|
||||||
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
|
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
|
||||||
import org.datavec.api.split.FileSplit;
|
import org.datavec.api.split.FileSplit;
|
||||||
import org.datavec.api.split.ListStringSplit;
|
import org.datavec.api.split.ListStringSplit;
|
||||||
import org.deeplearning4j.core.storage.StatsStorage;
|
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.LSTM;
|
import org.deeplearning4j.nn.conf.layers.LSTM;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
|
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
|
||||||
import org.deeplearning4j.nn.conf.preprocessor.RnnToFeedForwardPreProcessor;
|
import org.deeplearning4j.nn.conf.preprocessor.RnnToFeedForwardPreProcessor;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.nn.weights.WeightInit;
|
import org.deeplearning4j.nn.weights.WeightInit;
|
||||||
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
|
import org.deeplearning4j.ui.api.UIServer;
|
||||||
import org.deeplearning4j.ui.api.UIServer;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.deeplearning4j.ui.model.stats.StatsListener;
|
|
||||||
import org.deeplearning4j.ui.model.storage.FileStatsStorage;
|
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.Tag;
|
import org.junit.jupiter.api.Tag;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.evaluation.classification.Evaluation;
|
import org.nd4j.evaluation.classification.Evaluation;
|
||||||
|
@ -86,16 +80,16 @@ public class TestServer {
|
||||||
int i = 2000;
|
int i = 2000;
|
||||||
int numClasses = 10;
|
int numClasses = 10;
|
||||||
int numBatchSize = 100;
|
int numBatchSize = 100;
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(1234)
|
.seed(1234)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Nesterovs.Builder().learningRate(0.15).build())
|
.updater(new Nesterovs.Builder().learningRate(0.15).build())
|
||||||
.activation(Activation.RELU)
|
.activation(Activation.RELU)
|
||||||
.l2(0)
|
.l2(0)
|
||||||
.list()
|
|
||||||
//.layer(0, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 5).stride(1,1).padding(0,2).nOut(1).name("1st Filter").updater(new Adam.Builder().learningRate(0.2).build()).build())
|
//.layer(0, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 5).stride(1,1).padding(0,2).nOut(1).name("1st Filter").updater(new Adam.Builder().learningRate(0.2).build()).build())
|
||||||
//.layer(1, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 2).stride(1,2).padding(0,0).nOut(1).name("2nd Filter").updater(new Adam.Builder().learningRate(0.1).build()).build())
|
//.layer(1, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 2).stride(1,2).padding(0,0).nOut(1).name("2nd Filter").updater(new Adam.Builder().learningRate(0.1).build()).build())
|
||||||
// .layer(1, new DenseLayer.Builder().nIn(10).nOut(64).activation(Activation.RELU).build())
|
// .layer(1, new DenseLayerConfiguration.Builder().nIn(10).nOut(64).activation(Activation.RELU).build())
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(100).activation(Activation.RELU).l2(0.003).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(100).activation(Activation.RELU).l2(0.003).build())
|
||||||
.layer(1, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
.layer(1, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
||||||
.layer(2, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
.layer(2, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
package net.brutex.spark;
|
package net.brutex.spark;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
//import net.brutex.ai.performance.storage.PostgresStatsStorage;
|
//import net.brutex.ai.performance.storage.PostgresStatsStorage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.datavec.api.records.reader.RecordReader;
|
import org.datavec.api.records.reader.RecordReader;
|
||||||
|
@ -32,9 +31,8 @@ import org.datavec.api.split.ListStringSplit;
|
||||||
import org.datavec.image.recordreader.ImageRecordReader;
|
import org.datavec.image.recordreader.ImageRecordReader;
|
||||||
import org.deeplearning4j.core.storage.StatsStorage;
|
import org.deeplearning4j.core.storage.StatsStorage;
|
||||||
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.LSTM;
|
import org.deeplearning4j.nn.conf.layers.LSTM;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
|
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
|
||||||
|
@ -122,16 +120,16 @@ public class TestServer2 {
|
||||||
int i = 2000;
|
int i = 2000;
|
||||||
int numClasses = 10;
|
int numClasses = 10;
|
||||||
int numBatchSize = 100;
|
int numBatchSize = 100;
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(1234)
|
.seed(1234)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Nesterovs.Builder().learningRate(0.15).build())
|
.updater(new Nesterovs.Builder().learningRate(0.15).build())
|
||||||
.activation(Activation.RELU)
|
.activation(Activation.RELU)
|
||||||
.l2(0)
|
.l2(0)
|
||||||
.list()
|
|
||||||
//.layer(0, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 5).stride(1,1).padding(0,2).nOut(1).name("1st Filter").updater(new Adam.Builder().learningRate(0.2).build()).build())
|
//.layer(0, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 5).stride(1,1).padding(0,2).nOut(1).name("1st Filter").updater(new Adam.Builder().learningRate(0.2).build()).build())
|
||||||
//.layer(1, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 2).stride(1,2).padding(0,0).nOut(1).name("2nd Filter").updater(new Adam.Builder().learningRate(0.1).build()).build())
|
//.layer(1, new ConvolutionLayer.Builder().nIn(1).kernelSize(1, 2).stride(1,2).padding(0,0).nOut(1).name("2nd Filter").updater(new Adam.Builder().learningRate(0.1).build()).build())
|
||||||
// .layer(1, new DenseLayer.Builder().nIn(10).nOut(64).activation(Activation.RELU).build())
|
// .layer(1, new DenseLayerConfiguration.Builder().nIn(10).nOut(64).activation(Activation.RELU).build())
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(100).activation(Activation.RELU).l2(0.003).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(100).activation(Activation.RELU).l2(0.003).build())
|
||||||
.layer(1, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
.layer(1, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
||||||
.layer(2, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
.layer(2, new LSTM.Builder().nIn(100).nOut(100).activation(Activation.TANH).build())
|
||||||
|
@ -207,7 +205,7 @@ public class TestServer2 {
|
||||||
//PostgresStatsStorage psqlStore = new PostgresStatsStorage();
|
//PostgresStatsStorage psqlStore = new PostgresStatsStorage();
|
||||||
int listenerFrequency = 2;
|
int listenerFrequency = 2;
|
||||||
//net.setListeners(new StatsListener(psqlStore, listenerFrequency), new StatsListener(statsStorage, listenerFrequency), new ScoreIterationListener(200));
|
//net.setListeners(new StatsListener(psqlStore, listenerFrequency), new StatsListener(statsStorage, listenerFrequency), new ScoreIterationListener(200));
|
||||||
net.setListeners(new StatsListener(statsStorage, listenerFrequency), new ScoreIterationListener(200));
|
net.addTrainingListeners(new StatsListener(statsStorage, listenerFrequency), new ScoreIterationListener(200));
|
||||||
|
|
||||||
|
|
||||||
//Attach the StatsStorage instance to the UI: this allows the contents of the StatsStorage to be visualized
|
//Attach the StatsStorage instance to the UI: this allows the contents of the StatsStorage to be visualized
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
package org.deeplearning4j.integration;
|
package org.deeplearning4j.integration;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.deeplearning4j.datasets.iterator.MultiDataSetWrapperIterator;
|
import org.deeplearning4j.datasets.iterator.MultiDataSetWrapperIterator;
|
||||||
import org.deeplearning4j.integration.testcases.samediff.SameDiffCNNCases;
|
import org.deeplearning4j.integration.testcases.samediff.SameDiffCNNCases;
|
||||||
import org.deeplearning4j.integration.testcases.samediff.SameDiffMLPTestCases;
|
import org.deeplearning4j.integration.testcases.samediff.SameDiffMLPTestCases;
|
||||||
import org.deeplearning4j.integration.testcases.samediff.SameDiffRNNTestCases;
|
import org.deeplearning4j.integration.testcases.samediff.SameDiffRNNTestCases;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.optimize.listeners.CollectScoresListener;
|
import org.deeplearning4j.optimize.listeners.CollectScoresListener;
|
||||||
|
@ -135,12 +135,12 @@ public class IntegrationTestBaselineGenerator {
|
||||||
MultiLayerNetwork mln = null;
|
MultiLayerNetwork mln = null;
|
||||||
ComputationGraph cg = null;
|
ComputationGraph cg = null;
|
||||||
SameDiff sd = null;
|
SameDiff sd = null;
|
||||||
Model m = null;
|
IModel m = null;
|
||||||
if (tc.getTestType() == TestCase.TestType.RANDOM_INIT) {
|
if (tc.getTestType() == TestCase.TestType.RANDOM_INIT) {
|
||||||
Object config = tc.getConfiguration();
|
Object config = tc.getConfiguration();
|
||||||
String json = null;
|
String json = null;
|
||||||
if (config instanceof MultiLayerConfiguration) {
|
if (config instanceof NeuralNetConfiguration) {
|
||||||
MultiLayerConfiguration mlc = (MultiLayerConfiguration) config;
|
NeuralNetConfiguration mlc = (NeuralNetConfiguration) config;
|
||||||
json = mlc.toJson();
|
json = mlc.toJson();
|
||||||
mln = new MultiLayerNetwork(mlc);
|
mln = new MultiLayerNetwork(mlc);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -284,21 +284,21 @@ public class IntegrationTestBaselineGenerator {
|
||||||
INDArray paramsPostTraining;
|
INDArray paramsPostTraining;
|
||||||
if (modelType == ModelType.MLN) {
|
if (modelType == ModelType.MLN) {
|
||||||
int[] layersToTrain = tc.getUnsupervisedTrainLayersMLN();
|
int[] layersToTrain = tc.getUnsupervisedTrainLayersMLN();
|
||||||
Preconditions.checkState(layersToTrain != null, "Layer indices must not be null");
|
Preconditions.checkState(layersToTrain != null, "ILayer indices must not be null");
|
||||||
DataSetIterator dsi = new MultiDataSetWrapperIterator(iter);
|
DataSetIterator dsi = new MultiDataSetWrapperIterator(iter);
|
||||||
|
|
||||||
for (int i : layersToTrain) {
|
for (int i : layersToTrain) {
|
||||||
mln.pretrainLayer(i, dsi);
|
mln.pretrainLayer(i, dsi);
|
||||||
}
|
}
|
||||||
paramsPostTraining = mln.params();
|
paramsPostTraining = mln.getModelParams();
|
||||||
} else if (modelType == ModelType.CG) {
|
} else if (modelType == ModelType.CG) {
|
||||||
String[] layersToTrain = tc.getUnsupervisedTrainLayersCG();
|
String[] layersToTrain = tc.getUnsupervisedTrainLayersCG();
|
||||||
Preconditions.checkState(layersToTrain != null, "Layer names must not be null");
|
Preconditions.checkState(layersToTrain != null, "ILayer names must not be null");
|
||||||
|
|
||||||
for (String i : layersToTrain) {
|
for (String i : layersToTrain) {
|
||||||
cg.pretrainLayer(i, iter);
|
cg.pretrainLayer(i, iter);
|
||||||
}
|
}
|
||||||
paramsPostTraining = cg.params();
|
paramsPostTraining = cg.getModelParams();
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("SameDiff not supported for unsupervised training tests");
|
throw new UnsupportedOperationException("SameDiff not supported for unsupervised training tests");
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ public class IntegrationTestBaselineGenerator {
|
||||||
|
|
||||||
CollectScoresListener l = new CollectScoresListener(1);
|
CollectScoresListener l = new CollectScoresListener(1);
|
||||||
if (modelType != ModelType.SAMEDIFF)
|
if (modelType != ModelType.SAMEDIFF)
|
||||||
m.setListeners(l);
|
m.addTrainingListeners(l);
|
||||||
|
|
||||||
History h = null;
|
History h = null;
|
||||||
if (modelType == ModelType.MLN) {
|
if (modelType == ModelType.MLN) {
|
||||||
|
@ -349,7 +349,7 @@ public class IntegrationTestBaselineGenerator {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
File p = new File(testBaseDir, IntegrationTestRunner.PARAMS_POST_TRAIN_FILENAME);
|
File p = new File(testBaseDir, IntegrationTestRunner.PARAMS_POST_TRAIN_FILENAME);
|
||||||
IntegrationTestRunner.write(m.params(), p);
|
IntegrationTestRunner.write(m.getModelParams(), p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,18 +25,18 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.common.config.DL4JClassLoading;
|
import org.deeplearning4j.common.config.DL4JClassLoading;
|
||||||
import org.deeplearning4j.datasets.iterator.MultiDataSetWrapperIterator;
|
import org.deeplearning4j.datasets.iterator.MultiDataSetWrapperIterator;
|
||||||
import org.deeplearning4j.integration.util.CountingMultiDataSetIterator;
|
import org.deeplearning4j.integration.util.CountingMultiDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
|
||||||
import org.deeplearning4j.nn.conf.BackpropType;
|
import org.deeplearning4j.nn.conf.BackpropType;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.InputPreProcessor;
|
import org.deeplearning4j.nn.conf.InputPreProcessor;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.graph.LayerVertex;
|
import org.deeplearning4j.nn.conf.graph.LayerVertex;
|
||||||
import org.deeplearning4j.nn.conf.layers.Layer;
|
import org.deeplearning4j.nn.conf.layers.LayerConfiguration;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.graph.vertex.GraphVertex;
|
import org.deeplearning4j.nn.graph.vertex.GraphVertex;
|
||||||
import org.deeplearning4j.nn.layers.BaseOutputLayer;
|
import org.deeplearning4j.nn.layers.BaseOutputLayer;
|
||||||
|
@ -177,22 +177,22 @@ public class IntegrationTestRunner {
|
||||||
MultiLayerNetwork mln = null;
|
MultiLayerNetwork mln = null;
|
||||||
ComputationGraph cg = null;
|
ComputationGraph cg = null;
|
||||||
SameDiff sd = null;
|
SameDiff sd = null;
|
||||||
Model m = null;
|
IModel m = null;
|
||||||
if (tc.getTestType() == TestCase.TestType.RANDOM_INIT) {
|
if (tc.getTestType() == TestCase.TestType.RANDOM_INIT) {
|
||||||
log.info("Checking RANDOM_INIT test case: saved model vs. initialized model");
|
log.info("Checking RANDOM_INIT test case: saved model vs. initialized model");
|
||||||
//Checking randomly initialized model:
|
//Checking randomly initialized model:
|
||||||
File savedModel = new File(testBaseDir, IntegrationTestRunner.RANDOM_INIT_UNTRAINED_MODEL_FILENAME);
|
File savedModel = new File(testBaseDir, IntegrationTestRunner.RANDOM_INIT_UNTRAINED_MODEL_FILENAME);
|
||||||
Object config = tc.getConfiguration();
|
Object config = tc.getConfiguration();
|
||||||
if (config instanceof MultiLayerConfiguration) {
|
if (config instanceof NeuralNetConfiguration) {
|
||||||
MultiLayerConfiguration mlc = (MultiLayerConfiguration) config;
|
NeuralNetConfiguration mlc = (NeuralNetConfiguration) config;
|
||||||
mln = new MultiLayerNetwork(mlc);
|
mln = new MultiLayerNetwork(mlc);
|
||||||
mln.init();
|
mln.init();
|
||||||
m = mln;
|
m = mln;
|
||||||
|
|
||||||
MultiLayerNetwork loaded = MultiLayerNetwork.load(savedModel, true);
|
MultiLayerNetwork loaded = MultiLayerNetwork.load(savedModel, true);
|
||||||
assertEquals(loaded.getLayerWiseConfigurations(), mln.getLayerWiseConfigurations(), "Configs not equal");
|
assertEquals(loaded.getNetConfiguration(), mln.getNetConfiguration(), "Configs not equal");
|
||||||
assertEquals( loaded.params(), mln.params(), "Params not equal");
|
assertEquals( loaded.getModelParams(), mln.getModelParams(), "Params not equal");
|
||||||
assertEquals( loaded.paramTable(), mln.paramTable(), "Param table not equal");
|
assertEquals( loaded.getParamTable(), mln.getParamTable(), "Param table not equal");
|
||||||
} else if(config instanceof ComputationGraphConfiguration ){
|
} else if(config instanceof ComputationGraphConfiguration ){
|
||||||
ComputationGraphConfiguration cgc = (ComputationGraphConfiguration) config;
|
ComputationGraphConfiguration cgc = (ComputationGraphConfiguration) config;
|
||||||
cg = new ComputationGraph(cgc);
|
cg = new ComputationGraph(cgc);
|
||||||
|
@ -200,9 +200,9 @@ public class IntegrationTestRunner {
|
||||||
m = cg;
|
m = cg;
|
||||||
|
|
||||||
ComputationGraph loaded = ComputationGraph.load(savedModel, true);
|
ComputationGraph loaded = ComputationGraph.load(savedModel, true);
|
||||||
assertEquals(loaded.getConfiguration(), cg.getConfiguration(), "Configs not equal" );
|
assertEquals(loaded.getComputationGraphConfiguration(), cg.getComputationGraphConfiguration(), "Configs not equal" );
|
||||||
assertEquals( loaded.params(), cg.params(), "Params not equal");
|
assertEquals( loaded.getModelParams(), cg.getModelParams(), "Params not equal");
|
||||||
assertEquals(loaded.paramTable(), cg.paramTable(), "Param table not equal");
|
assertEquals(loaded.getParamTable(), cg.getParamTable(), "Param table not equal");
|
||||||
} else if(config instanceof SameDiff){
|
} else if(config instanceof SameDiff){
|
||||||
sd = (SameDiff)config;
|
sd = (SameDiff)config;
|
||||||
SameDiff loaded = SameDiff.load(savedModel, true);
|
SameDiff loaded = SameDiff.load(savedModel, true);
|
||||||
|
@ -383,22 +383,22 @@ public class IntegrationTestRunner {
|
||||||
org.deeplearning4j.nn.api.Layer[] layers;
|
org.deeplearning4j.nn.api.Layer[] layers;
|
||||||
if(modelType == ModelType.MLN){
|
if(modelType == ModelType.MLN){
|
||||||
int[] layersToTrain = tc.getUnsupervisedTrainLayersMLN();
|
int[] layersToTrain = tc.getUnsupervisedTrainLayersMLN();
|
||||||
Preconditions.checkState(layersToTrain != null, "Layer indices must not be null");
|
Preconditions.checkState(layersToTrain != null, "ILayer indices must not be null");
|
||||||
DataSetIterator dsi = new MultiDataSetWrapperIterator(iter);
|
DataSetIterator dsi = new MultiDataSetWrapperIterator(iter);
|
||||||
|
|
||||||
for( int i : layersToTrain){
|
for( int i : layersToTrain){
|
||||||
mln.pretrainLayer(i, dsi);
|
mln.pretrainLayer(i, dsi);
|
||||||
}
|
}
|
||||||
paramsPostTraining = mln.params();
|
paramsPostTraining = mln.getModelParams();
|
||||||
layers = mln.getLayers();
|
layers = mln.getLayers();
|
||||||
} else if(modelType == ModelType.CG) {
|
} else if(modelType == ModelType.CG) {
|
||||||
String[] layersToTrain = tc.getUnsupervisedTrainLayersCG();
|
String[] layersToTrain = tc.getUnsupervisedTrainLayersCG();
|
||||||
Preconditions.checkState(layersToTrain != null, "Layer names must not be null");
|
Preconditions.checkState(layersToTrain != null, "ILayer names must not be null");
|
||||||
|
|
||||||
for( String i : layersToTrain){
|
for( String i : layersToTrain){
|
||||||
cg.pretrainLayer(i, iter);
|
cg.pretrainLayer(i, iter);
|
||||||
}
|
}
|
||||||
paramsPostTraining = cg.params();
|
paramsPostTraining = cg.getModelParams();
|
||||||
layers = cg.getLayers();
|
layers = cg.getLayers();
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Unsupported layerwise pretraining not supported for SameDiff models");
|
throw new UnsupportedOperationException("Unsupported layerwise pretraining not supported for SameDiff models");
|
||||||
|
@ -426,11 +426,11 @@ public class IntegrationTestRunner {
|
||||||
boolean isTbptt;
|
boolean isTbptt;
|
||||||
int tbpttLength;
|
int tbpttLength;
|
||||||
if(modelType == ModelType.MLN){
|
if(modelType == ModelType.MLN){
|
||||||
isTbptt = mln.getLayerWiseConfigurations().getBackpropType() == BackpropType.TruncatedBPTT;
|
isTbptt = mln.getNetConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
|
||||||
tbpttLength = mln.getLayerWiseConfigurations().getTbpttFwdLength();
|
tbpttLength = mln.getNetConfiguration().getTbpttFwdLength();
|
||||||
} else if(modelType == ModelType.CG) {
|
} else if(modelType == ModelType.CG) {
|
||||||
isTbptt = cg.getConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
|
isTbptt = cg.getComputationGraphConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
|
||||||
tbpttLength = cg.getConfiguration().getTbpttFwdLength();
|
tbpttLength = cg.getComputationGraphConfiguration().getTbpttFwdLength();
|
||||||
} else {
|
} else {
|
||||||
isTbptt = false;
|
isTbptt = false;
|
||||||
tbpttLength = 0;
|
tbpttLength = 0;
|
||||||
|
@ -439,7 +439,7 @@ public class IntegrationTestRunner {
|
||||||
CountingMultiDataSetIterator countingIter = new CountingMultiDataSetIterator(trainData, isTbptt, tbpttLength);
|
CountingMultiDataSetIterator countingIter = new CountingMultiDataSetIterator(trainData, isTbptt, tbpttLength);
|
||||||
CollectScoresListener l = new CollectScoresListener(1);
|
CollectScoresListener l = new CollectScoresListener(1);
|
||||||
if(modelType != ModelType.SAMEDIFF) {
|
if(modelType != ModelType.SAMEDIFF) {
|
||||||
m.setListeners(l);
|
m.addTrainingListeners(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
int iterBefore;
|
int iterBefore;
|
||||||
|
@ -458,11 +458,11 @@ public class IntegrationTestRunner {
|
||||||
epochAfter = mln.getEpochCount();
|
epochAfter = mln.getEpochCount();
|
||||||
layers = mln.getLayers();
|
layers = mln.getLayers();
|
||||||
} else if(modelType == ModelType.CG){
|
} else if(modelType == ModelType.CG){
|
||||||
iterBefore = cg.getConfiguration().getIterationCount();
|
iterBefore = cg.getComputationGraphConfiguration().getIterationCount();
|
||||||
epochBefore = cg.getConfiguration().getEpochCount();
|
epochBefore = cg.getComputationGraphConfiguration().getEpochCount();
|
||||||
cg.fit(countingIter);
|
cg.fit(countingIter);
|
||||||
iterAfter = cg.getConfiguration().getIterationCount();
|
iterAfter = cg.getComputationGraphConfiguration().getIterationCount();
|
||||||
epochAfter = cg.getConfiguration().getEpochCount();
|
epochAfter = cg.getComputationGraphConfiguration().getEpochCount();
|
||||||
layers = cg.getLayers();
|
layers = cg.getLayers();
|
||||||
} else {
|
} else {
|
||||||
iterBefore = sd.getTrainingConfig().getIterationCount();
|
iterBefore = sd.getTrainingConfig().getIterationCount();
|
||||||
|
@ -519,10 +519,10 @@ public class IntegrationTestRunner {
|
||||||
if(modelType != ModelType.SAMEDIFF) {
|
if(modelType != ModelType.SAMEDIFF) {
|
||||||
File p = new File(testBaseDir, IntegrationTestRunner.PARAMS_POST_TRAIN_FILENAME);
|
File p = new File(testBaseDir, IntegrationTestRunner.PARAMS_POST_TRAIN_FILENAME);
|
||||||
INDArray paramsExp = read(p);
|
INDArray paramsExp = read(p);
|
||||||
INDArray z = exceedsRelError(m.params(), paramsExp, tc.getMaxRelativeErrorParamsPostTraining(), tc.getMinAbsErrorParamsPostTraining());
|
INDArray z = exceedsRelError(m.getModelParams(), paramsExp, tc.getMaxRelativeErrorParamsPostTraining(), tc.getMinAbsErrorParamsPostTraining());
|
||||||
int count = z.sumNumber().intValue();
|
int count = z.sumNumber().intValue();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
logFailedParams(20, "Parameter", layers, z, paramsExp, m.params());
|
logFailedParams(20, "Parameter", layers, z, paramsExp, m.getModelParams());
|
||||||
}
|
}
|
||||||
assertEquals( 0, count, "Number of params exceeded max relative error");
|
assertEquals( 0, count, "Number of params exceeded max relative error");
|
||||||
} else {
|
} else {
|
||||||
|
@ -606,13 +606,13 @@ public class IntegrationTestRunner {
|
||||||
if (modelType == ModelType.MLN) {
|
if (modelType == ModelType.MLN) {
|
||||||
ModelSerializer.writeModel(m, f, true);
|
ModelSerializer.writeModel(m, f, true);
|
||||||
MultiLayerNetwork restored = MultiLayerNetwork.load(f, true);
|
MultiLayerNetwork restored = MultiLayerNetwork.load(f, true);
|
||||||
assertEquals(mln.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
|
assertEquals(mln.getNetConfiguration(), restored.getNetConfiguration());
|
||||||
assertEquals(mln.params(), restored.params());
|
assertEquals(mln.getModelParams(), restored.getModelParams());
|
||||||
} else if(modelType == ModelType.CG){
|
} else if(modelType == ModelType.CG){
|
||||||
ModelSerializer.writeModel(m, f, true);
|
ModelSerializer.writeModel(m, f, true);
|
||||||
ComputationGraph restored = ComputationGraph.load(f, true);
|
ComputationGraph restored = ComputationGraph.load(f, true);
|
||||||
assertEquals(cg.getConfiguration(), restored.getConfiguration());
|
assertEquals(cg.getComputationGraphConfiguration(), restored.getComputationGraphConfiguration());
|
||||||
assertEquals(cg.params(), restored.params());
|
assertEquals(cg.getModelParams(), restored.getModelParams());
|
||||||
} else {
|
} else {
|
||||||
sd.save(f, true);
|
sd.save(f, true);
|
||||||
SameDiff restored = SameDiff.load(f, true);
|
SameDiff restored = SameDiff.load(f, true);
|
||||||
|
@ -722,7 +722,7 @@ public class IntegrationTestRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Work out which layers, vertices etc we have seen - so we can (at the end of all tests) log our integration test coverage
|
//Work out which layers, vertices etc we have seen - so we can (at the end of all tests) log our integration test coverage
|
||||||
private static void collectCoverageInformation(Model m){
|
private static void collectCoverageInformation(IModel m){
|
||||||
boolean isMLN = (m instanceof MultiLayerNetwork);
|
boolean isMLN = (m instanceof MultiLayerNetwork);
|
||||||
MultiLayerNetwork mln = (isMLN ? (MultiLayerNetwork)m : null);
|
MultiLayerNetwork mln = (isMLN ? (MultiLayerNetwork)m : null);
|
||||||
ComputationGraph cg = (!isMLN ? (ComputationGraph)m : null);
|
ComputationGraph cg = (!isMLN ? (ComputationGraph)m : null);
|
||||||
|
@ -735,17 +735,17 @@ public class IntegrationTestRunner {
|
||||||
layers = cg.getLayers();
|
layers = cg.getLayers();
|
||||||
}
|
}
|
||||||
for (org.deeplearning4j.nn.api.Layer l : layers) {
|
for (org.deeplearning4j.nn.api.Layer l : layers) {
|
||||||
Layer lConf = l.conf().getLayer();
|
LayerConfiguration lConf = l.getLayerConfiguration();
|
||||||
layerConfClassesSeen.put(lConf.getClass(), layerConfClassesSeen.getOrDefault(lConf.getClass(), 0) + 1);
|
layerConfClassesSeen.put(lConf.getClass(), layerConfClassesSeen.getOrDefault(lConf.getClass(), 0) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Collect preprocessor coverage information:
|
//Collect preprocessor coverage information:
|
||||||
Collection<InputPreProcessor> preProcessors;
|
Collection<InputPreProcessor> preProcessors;
|
||||||
if (isMLN) {
|
if (isMLN) {
|
||||||
preProcessors = mln.getLayerWiseConfigurations().getInputPreProcessors().values();
|
preProcessors = mln.getNetConfiguration().getInputPreProcessors().values();
|
||||||
} else {
|
} else {
|
||||||
preProcessors = new ArrayList<>();
|
preProcessors = new ArrayList<>();
|
||||||
for (org.deeplearning4j.nn.conf.graph.GraphVertex gv : cg.getConfiguration().getVertices().values()) {
|
for (org.deeplearning4j.nn.conf.graph.GraphVertex gv : cg.getComputationGraphConfiguration().getVertices().values()) {
|
||||||
if (gv instanceof LayerVertex) {
|
if (gv instanceof LayerVertex) {
|
||||||
InputPreProcessor pp = ((LayerVertex) gv).getPreProcessor();
|
InputPreProcessor pp = ((LayerVertex) gv).getPreProcessor();
|
||||||
if (pp != null) {
|
if (pp != null) {
|
||||||
|
@ -760,14 +760,14 @@ public class IntegrationTestRunner {
|
||||||
|
|
||||||
//Collect vertex coverage information
|
//Collect vertex coverage information
|
||||||
if (!isMLN) {
|
if (!isMLN) {
|
||||||
for (org.deeplearning4j.nn.conf.graph.GraphVertex gv : cg.getConfiguration().getVertices().values()) {
|
for (org.deeplearning4j.nn.conf.graph.GraphVertex gv : cg.getComputationGraphConfiguration().getVertices().values()) {
|
||||||
vertexConfClassesSeen.put(gv.getClass(), vertexConfClassesSeen.getOrDefault(gv.getClass(), 0) + 1);
|
vertexConfClassesSeen.put(gv.getClass(), vertexConfClassesSeen.getOrDefault(gv.getClass(), 0) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void checkLayerClearance(Model m) {
|
private static void checkLayerClearance(IModel m) {
|
||||||
//Check that the input fields for all layers have been cleared
|
//Check that the input fields for all layers have been cleared
|
||||||
org.deeplearning4j.nn.api.Layer[] layers;
|
org.deeplearning4j.nn.api.Layer[] layers;
|
||||||
if (m instanceof MultiLayerNetwork) {
|
if (m instanceof MultiLayerNetwork) {
|
||||||
|
@ -801,7 +801,7 @@ public class IntegrationTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateLayerIterCounts(Model m, int expEpoch, int expIter){
|
private static void validateLayerIterCounts(IModel m, int expEpoch, int expIter){
|
||||||
//Check that the iteration and epoch counts - on the layers - are synced
|
//Check that the iteration and epoch counts - on the layers - are synced
|
||||||
org.deeplearning4j.nn.api.Layer[] layers;
|
org.deeplearning4j.nn.api.Layer[] layers;
|
||||||
if (m instanceof MultiLayerNetwork) {
|
if (m instanceof MultiLayerNetwork) {
|
||||||
|
@ -817,7 +817,7 @@ public class IntegrationTestRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Map<String,INDArray> getFrozenLayerParamCopies(Model m){
|
private static Map<String,INDArray> getFrozenLayerParamCopies(IModel m){
|
||||||
Map<String,INDArray> out = new LinkedHashMap<>();
|
Map<String,INDArray> out = new LinkedHashMap<>();
|
||||||
org.deeplearning4j.nn.api.Layer[] layers;
|
org.deeplearning4j.nn.api.Layer[] layers;
|
||||||
if (m instanceof MultiLayerNetwork) {
|
if (m instanceof MultiLayerNetwork) {
|
||||||
|
@ -832,9 +832,9 @@ public class IntegrationTestRunner {
|
||||||
if(m instanceof MultiLayerNetwork){
|
if(m instanceof MultiLayerNetwork){
|
||||||
paramPrefix = l.getIndex() + "_";
|
paramPrefix = l.getIndex() + "_";
|
||||||
} else {
|
} else {
|
||||||
paramPrefix = l.conf().getLayer().getLayerName() + "_";
|
paramPrefix = l.getLayerConfiguration().getLayerName() + "_";
|
||||||
}
|
}
|
||||||
Map<String,INDArray> paramTable = l.paramTable();
|
Map<String,INDArray> paramTable = l.getParamTable();
|
||||||
for(Map.Entry<String,INDArray> e : paramTable.entrySet()){
|
for(Map.Entry<String,INDArray> e : paramTable.entrySet()){
|
||||||
out.put(paramPrefix + e.getKey(), e.getValue().dup());
|
out.put(paramPrefix + e.getKey(), e.getValue().dup());
|
||||||
}
|
}
|
||||||
|
@ -854,7 +854,7 @@ public class IntegrationTestRunner {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkFrozenParams(Map<String,INDArray> copiesBeforeTraining, Model m){
|
public static void checkFrozenParams(Map<String,INDArray> copiesBeforeTraining, IModel m){
|
||||||
for(Map.Entry<String,INDArray> e : copiesBeforeTraining.entrySet()){
|
for(Map.Entry<String,INDArray> e : copiesBeforeTraining.entrySet()){
|
||||||
INDArray actual = m.getParam(e.getKey());
|
INDArray actual = m.getParam(e.getKey());
|
||||||
assertEquals(e.getValue(), actual, e.getKey());
|
assertEquals(e.getValue(), actual, e.getKey());
|
||||||
|
@ -872,14 +872,14 @@ public class IntegrationTestRunner {
|
||||||
|
|
||||||
log.info("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
|
log.info("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
|
||||||
|
|
||||||
log.info("Layer coverage - classes seen:");
|
log.info("ILayer coverage - classes seen:");
|
||||||
for (Class<?> c : layerClasses) {
|
for (Class<?> c : layerClasses) {
|
||||||
if (layerConfClassesSeen.containsKey(c)) {
|
if (layerConfClassesSeen.containsKey(c)) {
|
||||||
log.info("Class seen {} times in tests: {}", layerConfClassesSeen.get(c), c.getName());
|
log.info("Class seen {} times in tests: {}", layerConfClassesSeen.get(c), c.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Layer classes NOT seen in any tests:");
|
log.info("ILayer classes NOT seen in any tests:");
|
||||||
for (Class<?> c : layerClasses) {
|
for (Class<?> c : layerClasses) {
|
||||||
if (!layerConfClassesSeen.containsKey(c)) {
|
if (!layerConfClassesSeen.containsKey(c)) {
|
||||||
log.info("Class NOT seen in any tests: {}", c.getName());
|
log.info("Class NOT seen in any tests: {}", c.getName());
|
||||||
|
@ -939,7 +939,7 @@ public class IntegrationTestRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isLayerConfig(Class<?> c) {
|
private static boolean isLayerConfig(Class<?> c) {
|
||||||
return Layer.class.isAssignableFrom(c);
|
return LayerConfiguration.class.isAssignableFrom(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isPreprocessorConfig(Class<?> c) {
|
private static boolean isPreprocessorConfig(Class<?> c) {
|
||||||
|
@ -1088,7 +1088,7 @@ public class IntegrationTestRunner {
|
||||||
if(pSoFar + n < i){
|
if(pSoFar + n < i){
|
||||||
pSoFar += n;
|
pSoFar += n;
|
||||||
} else {
|
} else {
|
||||||
for(Map.Entry<String,INDArray> e : l.paramTable().entrySet()){
|
for(Map.Entry<String,INDArray> e : l.getParamTable().entrySet()){
|
||||||
pSoFar += e.getValue().length();
|
pSoFar += e.getValue().length();
|
||||||
if(pSoFar >= i){
|
if(pSoFar >= i){
|
||||||
pName = e.getKey();
|
pName = e.getKey();
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
package org.deeplearning4j.integration;
|
package org.deeplearning4j.integration;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.nd4j.autodiff.samediff.SameDiff;
|
import org.nd4j.autodiff.samediff.SameDiff;
|
||||||
import org.nd4j.evaluation.IEvaluation;
|
import org.nd4j.evaluation.IEvaluation;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
|
@ -89,7 +89,7 @@ public abstract class TestCase {
|
||||||
/**
|
/**
|
||||||
* Required for pretrained models (testType == TestType.PRETRAINED)
|
* Required for pretrained models (testType == TestType.PRETRAINED)
|
||||||
*/
|
*/
|
||||||
public Model getPretrainedModel() throws Exception {
|
public IModel getPretrainedModel() throws Exception {
|
||||||
throw new RuntimeException("Implementations must override this method if used");
|
throw new RuntimeException("Implementations must override this method if used");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.integration;
|
||||||
|
|
||||||
import org.apache.commons.compress.utils.IOUtils;
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.util.ModelSerializer;
|
import org.deeplearning4j.util.ModelSerializer;
|
||||||
|
@ -48,15 +48,15 @@ public class TestUtils {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||||
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
|
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
|
||||||
|
|
||||||
assertEquals(net.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
|
assertEquals(net.getNetConfiguration(), restored.getNetConfiguration());
|
||||||
assertEquals(net.params(), restored.params());
|
assertEquals(net.getModelParams(), restored.getModelParams());
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
//Should never happen
|
//Should never happen
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Also check the MultiLayerConfiguration is serializable (required by Spark etc)
|
//Also check the NeuralNetConfiguration is serializable (required by Spark etc)
|
||||||
MultiLayerConfiguration conf = net.getLayerWiseConfigurations();
|
NeuralNetConfiguration conf = net.getNetConfiguration();
|
||||||
serializeDeserializeJava(conf);
|
serializeDeserializeJava(conf);
|
||||||
|
|
||||||
return restored;
|
return restored;
|
||||||
|
@ -73,15 +73,15 @@ public class TestUtils {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||||
restored = ModelSerializer.restoreComputationGraph(bais, true);
|
restored = ModelSerializer.restoreComputationGraph(bais, true);
|
||||||
|
|
||||||
assertEquals(net.getConfiguration(), restored.getConfiguration());
|
assertEquals(net.getComputationGraphConfiguration(), restored.getComputationGraphConfiguration());
|
||||||
assertEquals(net.params(), restored.params());
|
assertEquals(net.getModelParams(), restored.getModelParams());
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
//Should never happen
|
//Should never happen
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Also check the ComputationGraphConfiguration is serializable (required by Spark etc)
|
//Also check the ComputationGraphConfiguration is serializable (required by Spark etc)
|
||||||
ComputationGraphConfiguration conf = net.getConfiguration();
|
ComputationGraphConfiguration conf = net.getComputationGraphConfiguration();
|
||||||
serializeDeserializeJava(conf);
|
serializeDeserializeJava(conf);
|
||||||
|
|
||||||
return restored;
|
return restored;
|
||||||
|
|
|
@ -80,12 +80,12 @@ public class CNN1DTestCases {
|
||||||
CharacterIterator iter = CharacterIterator.getShakespeareIterator(miniBatchSize,exampleLength);
|
CharacterIterator iter = CharacterIterator.getShakespeareIterator(miniBatchSize,exampleLength);
|
||||||
int nOut = iter.totalOutcomes();
|
int nOut = iter.totalOutcomes();
|
||||||
|
|
||||||
return new NeuralNetConfiguration.Builder()
|
return ((NeuralNetConfiguration.NeuralNetConfigurationBuilder)NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Adam(0.01))
|
.updater(new Adam(0.01))
|
||||||
.convolutionMode(ConvolutionMode.Same)
|
.convolutionMode(ConvolutionMode.Same))
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.layer("0", new Convolution1DLayer.Builder().nOut(32).activation(Activation.TANH).kernelSize(3).stride(1).build(), "in")
|
.layer("0", new Convolution1DLayer.Builder().nOut(32).activation(Activation.TANH).kernelSize(3).stride(1).build(), "in")
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.deeplearning4j.datasets.fetchers.DataSetType;
|
||||||
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.TinyImageNetDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.TinyImageNetDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.*;
|
import org.deeplearning4j.nn.conf.*;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
|
@ -98,13 +98,13 @@ public class CNN2DTestCases {
|
||||||
int outputNum = 10; // The number of possible outcomes
|
int outputNum = 10; // The number of possible outcomes
|
||||||
int seed = 123;
|
int seed = 123;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(seed)
|
.seed(seed)
|
||||||
.l2(0.0005)
|
.l2(0.0005)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Nesterovs(0.01, 0.9))
|
.updater(new Nesterovs(0.01, 0.9))
|
||||||
.list()
|
|
||||||
.layer(0, new ConvolutionLayer.Builder(5, 5)
|
.layer(0, new ConvolutionLayer.Builder(5, 5)
|
||||||
//nIn and nOut specify depth. nIn here is the nChannels and nOut is the number of filters to be applied
|
//nIn and nOut specify depth. nIn here is the nChannels and nOut is the number of filters to be applied
|
||||||
.nIn(nChannels)
|
.nIn(nChannels)
|
||||||
|
@ -132,7 +132,7 @@ public class CNN2DTestCases {
|
||||||
.nOut(outputNum)
|
.nOut(outputNum)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
|
.inputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
|
@ -207,7 +207,7 @@ public class CNN2DTestCases {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Model getPretrainedModel() throws Exception {
|
public IModel getPretrainedModel() throws Exception {
|
||||||
VGG16 vgg16 = VGG16.builder()
|
VGG16 vgg16 = VGG16.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.build();
|
.build();
|
||||||
|
@ -294,7 +294,7 @@ public class CNN2DTestCases {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Model getPretrainedModel() throws Exception {
|
public IModel getPretrainedModel() throws Exception {
|
||||||
int nClasses = 10;
|
int nClasses = 10;
|
||||||
int nBoxes = 5;
|
int nBoxes = 5;
|
||||||
double lambdaNoObj = 0.5;
|
double lambdaNoObj = 0.5;
|
||||||
|
@ -403,20 +403,20 @@ public class CNN2DTestCases {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Model getPretrainedModel() throws Exception {
|
public IModel getPretrainedModel() throws Exception {
|
||||||
|
|
||||||
Map<Integer, Double> lrSchedule = new HashMap<>();
|
Map<Integer, Double> lrSchedule = new HashMap<>();
|
||||||
lrSchedule.put(0, 0.01);
|
lrSchedule.put(0, 0.01);
|
||||||
lrSchedule.put(1000, 0.005);
|
lrSchedule.put(1000, 0.005);
|
||||||
lrSchedule.put(3000, 0.001);
|
lrSchedule.put(3000, 0.001);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.l2(0.0005)
|
.l2(0.0005)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Nesterovs(0.01, 0.9))
|
.updater(new Nesterovs(0.01, 0.9))
|
||||||
.list()
|
|
||||||
.layer(0, new ConvolutionLayer.Builder(5, 5)
|
.layer(0, new ConvolutionLayer.Builder(5, 5)
|
||||||
//nIn and nOut specify depth. nIn here is the nChannels and nOut is the number of filters to be applied
|
//nIn and nOut specify depth. nIn here is the nChannels and nOut is the number of filters to be applied
|
||||||
.nIn(1)
|
.nIn(1)
|
||||||
|
@ -446,7 +446,7 @@ public class CNN2DTestCases {
|
||||||
.nOut(10)
|
.nOut(10)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
|
.inputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.deeplearning4j.datasets.iterator.impl.SingletonMultiDataSetIterator;
|
||||||
import org.deeplearning4j.integration.ModelType;
|
import org.deeplearning4j.integration.ModelType;
|
||||||
import org.deeplearning4j.integration.TestCase;
|
import org.deeplearning4j.integration.TestCase;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.Convolution3D;
|
import org.deeplearning4j.nn.conf.layers.Convolution3D;
|
||||||
|
@ -76,13 +75,13 @@ public class CNN3DTestCases {
|
||||||
int outputNum = 10; // The number of possible outcomes
|
int outputNum = 10; // The number of possible outcomes
|
||||||
int seed = 123;
|
int seed = 123;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(seed)
|
.seed(seed)
|
||||||
.l2(0.0005)
|
.l2(0.0005)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Nesterovs(0.01, 0.9))
|
.updater(new Nesterovs(0.01, 0.9))
|
||||||
.convolutionMode(ConvolutionMode.Same)
|
.convolutionMode(ConvolutionMode.Same)
|
||||||
.list()
|
|
||||||
.layer(new Convolution3D.Builder(3,3,3)
|
.layer(new Convolution3D.Builder(3,3,3)
|
||||||
.dataFormat(Convolution3D.DataFormat.NCDHW)
|
.dataFormat(Convolution3D.DataFormat.NCDHW)
|
||||||
.nIn(nChannels)
|
.nIn(nChannels)
|
||||||
|
@ -98,7 +97,7 @@ public class CNN3DTestCases {
|
||||||
.nOut(outputNum)
|
.nOut(outputNum)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutional3D(8,8,8,nChannels))
|
.inputType(InputType.convolutional3D(8,8,8,nChannels))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.datavec.api.split.FileSplit;
|
||||||
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
|
@ -93,7 +92,7 @@ public class MLPTestCases {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getConfiguration() {
|
public Object getConfiguration() {
|
||||||
return new NeuralNetConfiguration.Builder()
|
return NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new Adam(new MapSchedule.Builder(ScheduleType.ITERATION)
|
.updater(new Adam(new MapSchedule.Builder(ScheduleType.ITERATION)
|
||||||
|
@ -104,13 +103,13 @@ public class MLPTestCases {
|
||||||
.add(14, 1e-2)
|
.add(14, 1e-2)
|
||||||
.build()))
|
.build()))
|
||||||
.l1(1e-3).l2(1e-3)
|
.l1(1e-3).l2(1e-3)
|
||||||
.list()
|
|
||||||
.layer(new DenseLayer.Builder().activation(Activation.TANH).nOut(64).build())
|
.layer(new DenseLayer.Builder().activation(Activation.TANH).nOut(64).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(10)
|
.layer(new OutputLayer.Builder().nOut(10)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT)
|
.lossFunction(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutionalFlat(28,28,1))
|
.inputType(InputType.convolutionalFlat(28,28,1))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,11 +197,11 @@ public class MLPTestCases {
|
||||||
int numHiddenNodes = 20;
|
int numHiddenNodes = 20;
|
||||||
|
|
||||||
//log.info("Build model....");
|
//log.info("Build model....");
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(seed)
|
.seed(seed)
|
||||||
.updater(new Nesterovs(learningRate, 0.9))
|
.updater(new Nesterovs(learningRate, 0.9))
|
||||||
.list()
|
|
||||||
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes)
|
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.RELU)
|
.activation(Activation.RELU)
|
||||||
|
|
|
@ -112,20 +112,20 @@ public class RNNTestCases {
|
||||||
int lstmLayerSize = 200; //Number of units in each GravesLSTM layer
|
int lstmLayerSize = 200; //Number of units in each GravesLSTM layer
|
||||||
int tbpttLength = 50; //Length for truncated backpropagation through time. i.e., do parameter updates ever 50 characters
|
int tbpttLength = 50; //Length for truncated backpropagation through time. i.e., do parameter updates ever 50 characters
|
||||||
|
|
||||||
return new NeuralNetConfiguration.Builder()
|
return NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.l2(0.001)
|
.l2(0.001)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Adam(1e-3))
|
.updater(new Adam(1e-3))
|
||||||
.list()
|
|
||||||
.layer(0, new LSTM.Builder().nIn(iter.inputColumns()).nOut(lstmLayerSize)
|
.layer(0, new LSTM.Builder().nIn(iter.inputColumns()).nOut(lstmLayerSize)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
.layer(1, new LSTM.Builder().nIn(lstmLayerSize).nOut(lstmLayerSize)
|
.layer(1, new LSTM.Builder().nIn(lstmLayerSize).nOut(lstmLayerSize)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
.layer(2, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation(Activation.SOFTMAX) //MCXENT + softmax for classification
|
.layer(2, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation(Activation.SOFTMAX) //MCXENT + softmax for classification
|
||||||
.nIn(lstmLayerSize).nOut(nOut).build())
|
.nIn(lstmLayerSize).nOut(nOut).build())
|
||||||
.backpropType(BackpropType.TruncatedBPTT).tBPTTForwardLength(tbpttLength).tBPTTBackwardLength(tbpttLength)
|
.backpropType(BackpropType.TruncatedBPTT).tbpttFwdLength(tbpttLength).tbpttBackLength(tbpttLength)
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -195,19 +195,19 @@ public class RNNTestCases {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getConfiguration() throws Exception {
|
public Object getConfiguration() throws Exception {
|
||||||
return new NeuralNetConfiguration.Builder()
|
return NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new Adam(5e-2))
|
.updater(new Adam(5e-2))
|
||||||
.l1(1e-3).l2(1e-3)
|
.l1(1e-3).l2(1e-3)
|
||||||
.list()
|
|
||||||
.layer(0, new LSTM.Builder().activation(Activation.TANH).nOut(10).build())
|
.layer(0, new LSTM.Builder().activation(Activation.TANH).nOut(10).build())
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(6)
|
.layer(new OutputLayer.Builder().nOut(6)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT)
|
.lossFunction(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.recurrent(1))
|
.inputType(InputType.recurrent(1))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,19 +316,19 @@ public class RNNTestCases {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getConfiguration() throws Exception {
|
public Object getConfiguration() throws Exception {
|
||||||
return new NeuralNetConfiguration.Builder()
|
return NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new Adam(5e-2))
|
.updater(new Adam(5e-2))
|
||||||
.l1(1e-3).l2(1e-3)
|
.l1(1e-3).l2(1e-3)
|
||||||
.list()
|
|
||||||
.layer(0, new Bidirectional(new LSTM.Builder().activation(Activation.TANH).nOut(10).build()))
|
.layer(0, new Bidirectional(new LSTM.Builder().activation(Activation.TANH).nOut(10).build()))
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(6)
|
.layer(new OutputLayer.Builder().nOut(6)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT)
|
.lossFunction(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.recurrent(1))
|
.inputType(InputType.recurrent(1))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,13 +72,13 @@ public class UnsupervisedTestCases {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getConfiguration() {
|
public Object getConfiguration() {
|
||||||
return new NeuralNetConfiguration.Builder()
|
return NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.FLOAT)
|
.dataType(DataType.FLOAT)
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new Adam(1e-3))
|
.updater(new Adam(1e-3))
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.l2(1e-4)
|
.l2(1e-4)
|
||||||
.list()
|
|
||||||
.layer(0, new VariationalAutoencoder.Builder()
|
.layer(0, new VariationalAutoencoder.Builder()
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
.encoderLayerSizes(256, 256) //2 encoder layers, each of size 256
|
.encoderLayerSizes(256, 256) //2 encoder layers, each of size 256
|
||||||
|
|
19
build.gradle
19
build.gradle
|
@ -44,6 +44,7 @@ ext {
|
||||||
|
|
||||||
scalaVersion = "2.12"
|
scalaVersion = "2.12"
|
||||||
logger.quiet("Scala main version is set to {}", scalaVersion)
|
logger.quiet("Scala main version is set to {}", scalaVersion)
|
||||||
|
logger.quiet("Running java {}", JavaVersion.current())
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations.all {
|
configurations.all {
|
||||||
|
@ -64,10 +65,10 @@ allprojects { Project proj ->
|
||||||
|
|
||||||
|
|
||||||
plugins.withType(JavaPlugin) {
|
plugins.withType(JavaPlugin) {
|
||||||
sourceCompatibility = 11
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.release = 8
|
options.release = 11
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
|
@ -85,7 +86,6 @@ allprojects { Project proj ->
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
|
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-params'
|
testImplementation 'org.junit.jupiter:junit-jupiter-params'
|
||||||
|
|
||||||
implementation "org.slf4j:slf4j-api"
|
implementation "org.slf4j:slf4j-api"
|
||||||
implementation "org.slf4j:slf4j-simple"
|
implementation "org.slf4j:slf4j-simple"
|
||||||
|
|
||||||
|
@ -107,14 +107,17 @@ allprojects { Project proj ->
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.withType(MavenPublishPlugin) {
|
plugins.withType(MavenPublishPlugin) {
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
if(! proj.name.contains("cavis-full")) {
|
||||||
/* Need to verify the property exists, as some
|
mavenJava(MavenPublication) {
|
||||||
|
/* Need to verify the property exists, as some
|
||||||
modules may not declare it (i.e. the java-platform plugin)
|
modules may not declare it (i.e. the java-platform plugin)
|
||||||
*/
|
*/
|
||||||
if (components.hasProperty("java") && !proj.name.equals("cavis-native-lib")) {
|
if (components.hasProperty("java")) {
|
||||||
from components.java
|
from components.java
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.nd4j.common.primitives.Pair;
|
||||||
import org.nd4j.linalg.activations.BaseActivationFunction;
|
import org.nd4j.linalg.activations.BaseActivationFunction;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
|
|
||||||
/**
|
/** The ActivationIdentity activation function, just returns the input as is.
|
||||||
* f(x) = x
|
* f(x) = x
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
|
|
@ -195,7 +195,7 @@ public abstract class BaseWorkspaceMgr<T extends Enum<T>> implements WorkspaceMg
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public INDArray validateArrayLocation(@NonNull T arrayType, @NonNull INDArray array, boolean migrateIfInvalid, boolean exceptionIfDetached) {
|
public INDArray validateArrayLocation(T arrayType, INDArray array, boolean migrateIfInvalid, boolean exceptionIfDetached) {
|
||||||
validateConfig(arrayType);
|
validateConfig(arrayType);
|
||||||
|
|
||||||
if(scopeOutOfWs.contains(arrayType)){
|
if(scopeOutOfWs.contains(arrayType)){
|
||||||
|
|
|
@ -67,7 +67,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set arrays to be scoped out (not in any workspace) for the specified array type.
|
* Set arrays to be scoped out (not in any workspace) for the specified array type.
|
||||||
* This means that create, dup, leverage etc methods will return result arrays that are not attached to any workspace
|
* This means that create, dup, leverage etc. methods will return result arrays that are not attached to any workspace
|
||||||
*
|
*
|
||||||
* @param arrayType Array type to set scoped out for
|
* @param arrayType Array type to set scoped out for
|
||||||
*/
|
*/
|
||||||
|
@ -120,7 +120,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
|
||||||
boolean isWorkspaceOpen(T arrayType);
|
boolean isWorkspaceOpen(T arrayType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert thath the workspace for the specified array type is open.
|
* Assert that the workspace for the specified array type is open.
|
||||||
* For array types that are set to scoped out, this will be treated as a no-op
|
* For array types that are set to scoped out, this will be treated as a no-op
|
||||||
* @param arrayType Array type to check
|
* @param arrayType Array type to check
|
||||||
* @param msg May be null. If non-null: include this in the exception
|
* @param msg May be null. If non-null: include this in the exception
|
||||||
|
@ -129,7 +129,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
|
||||||
void assertOpen(T arrayType, String msg) throws ND4JWorkspaceException;
|
void assertOpen(T arrayType, String msg) throws ND4JWorkspaceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert thath the workspace for the specified array type is not open.
|
* Assert that the workspace for the specified array type is not open.
|
||||||
* For array types that are set to scoped out, this will be treated as a no-op
|
* For array types that are set to scoped out, this will be treated as a no-op
|
||||||
* @param arrayType Array type to check
|
* @param arrayType Array type to check
|
||||||
* @param msg May be null. If non-null: include this in the exception
|
* @param msg May be null. If non-null: include this in the exception
|
||||||
|
@ -193,7 +193,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an uninitialized array in the specified array type's workspace (or detached if none is specified).
|
* Create an uninitialized array in the specified array type's workspace (or detached if none is specified).
|
||||||
* Equivalent to {@link org.nd4j.linalg.factory.Nd4j#createUninitialized(int)} (int...)}, other than the array location
|
* Equivalent to {@link org.nd4j.linalg.factory.Nd4j#createUninitialized(int...)}, other than the array location
|
||||||
* @param arrayType Array type
|
* @param arrayType Array type
|
||||||
* @param dataType Data type of the created array
|
* @param dataType Data type of the created array
|
||||||
* @param shape Shape
|
* @param shape Shape
|
||||||
|
@ -231,7 +231,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast the specified array to the specified datatype.<br>
|
* Cast the specified array to the specified datatype.<br>
|
||||||
* If the array is already the correct type, the bahaviour depends on the 'dupIfCorrectType' argument.<br>
|
* If the array is already the correct type, the behaviour depends on the 'dupIfCorrectType' argument.<br>
|
||||||
* dupIfCorrectType = false && toCast.dataType() == dataType: return input array as-is (unless workspace is wrong)<br>
|
* dupIfCorrectType = false && toCast.dataType() == dataType: return input array as-is (unless workspace is wrong)<br>
|
||||||
* dupIfCorrectType = true && toCast.dataType() == dataType: duplicate the array into the specified workspace<br>
|
* dupIfCorrectType = true && toCast.dataType() == dataType: duplicate the array into the specified workspace<br>
|
||||||
* @param arrayType Array type
|
* @param arrayType Array type
|
||||||
|
|
|
@ -19,6 +19,7 @@ dependencies {
|
||||||
testImplementation projects.cavisNative.cavisNativeCommon
|
testImplementation projects.cavisNative.cavisNativeCommon
|
||||||
testImplementation projects.cavisNd4j.cavisNd4jCommonTests
|
testImplementation projects.cavisNd4j.cavisNd4jCommonTests
|
||||||
testImplementation projects.cavisDnn.cavisDnnCommonTests
|
testImplementation projects.cavisDnn.cavisDnnCommonTests
|
||||||
|
testImplementation projects.cavisDnn.cavisDnnNn
|
||||||
|
|
||||||
implementation "org.apache.commons:commons-lang3"
|
implementation "org.apache.commons:commons-lang3"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ******************************************************************************
|
||||||
|
* *
|
||||||
|
* * This program and the accompanying materials are made available under the
|
||||||
|
* * terms of the Apache License, Version 2.0 which is available at
|
||||||
|
* * https://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
* *
|
||||||
|
* * See the NOTICE file distributed with this work for additional
|
||||||
|
* * information regarding copyright ownership.
|
||||||
|
* * Unless required by applicable law or agreed to in writing, software
|
||||||
|
* * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* * License for the specific language governing permissions and limitations
|
||||||
|
* * under the License.
|
||||||
|
* *
|
||||||
|
* * SPDX-License-Identifier: Apache-2.0
|
||||||
|
* *****************************************************************************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.brutex.ai.dnn.core.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ANSI colour codes
|
||||||
|
*/
|
||||||
|
public enum ANSI {
|
||||||
|
BLACK("\u001B[30m"),
|
||||||
|
RED("\u001B[31m"),
|
||||||
|
GREEN("\u001B[32m"),
|
||||||
|
YELLOW("\u001B[33m"),
|
||||||
|
BLUE("\u001B[34m"),
|
||||||
|
PURPLE("\u001B[35m"),
|
||||||
|
CYAN("\u001B[36m"),
|
||||||
|
WHITE("\u001B[37m"),
|
||||||
|
|
||||||
|
ANSI_RESET("\u001B[0m"),
|
||||||
|
|
||||||
|
BLACK_BACKGROUND("\u001B[40m"),
|
||||||
|
RED_BACKGROUND("\u001B[41m"),
|
||||||
|
GREEN_BACKGROUND("\u001B[42m"),
|
||||||
|
YELLOW_BACKGROUND("\u001B[43m"),
|
||||||
|
BLUE_BACKGROUND("\u001B[44m"),
|
||||||
|
PURPLE_BACKGROUND("\u001B[45m"),
|
||||||
|
CYAN_BACKGROUND("\u001B[46m"),
|
||||||
|
WHITE_BACKGROUND("\u001B[47m");
|
||||||
|
|
||||||
|
String code;
|
||||||
|
ANSI(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,8 +23,8 @@ package org.deeplearning4j.core.listener;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
|
||||||
import org.deeplearning4j.optimize.api.TrainingListener;
|
import org.deeplearning4j.optimize.api.TrainingListener;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import oshi.json.SystemInfo;
|
import oshi.json.SystemInfo;
|
||||||
|
@ -56,12 +56,12 @@ public class SystemInfoFilePrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void iterationDone(Model model, int iteration, int epoch) {
|
public void iterationDone(IModel model, int iteration, int epoch) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEpochStart(Model model) {
|
public void onEpochStart(IModel model) {
|
||||||
if(!printOnEpochStart || printFileTarget == null)
|
if(!printOnEpochStart || printFileTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEpochEnd(Model model) {
|
public void onEpochEnd(IModel model) {
|
||||||
if(!printOnEpochEnd || printFileTarget == null)
|
if(!printOnEpochEnd || printFileTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForwardPass(Model model, List<INDArray> activations) {
|
public void onForwardPass(IModel model, List<INDArray> activations) {
|
||||||
if(!printOnBackwardPass || printFileTarget == null)
|
if(!printOnBackwardPass || printFileTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForwardPass(Model model, Map<String, INDArray> activations) {
|
public void onForwardPass(IModel model, Map<String, INDArray> activations) {
|
||||||
if(!printOnForwardPass || printFileTarget == null)
|
if(!printOnForwardPass || printFileTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGradientCalculation(Model model) {
|
public void onGradientCalculation(IModel model) {
|
||||||
if(!printOnGradientCalculation || printFileTarget == null)
|
if(!printOnGradientCalculation || printFileTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackwardPass(Model model) {
|
public void onBackwardPass(IModel model) {
|
||||||
if(!printOnBackwardPass || printFileTarget == null)
|
if(!printOnBackwardPass || printFileTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.deeplearning4j.core.listener;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.deeplearning4j.optimize.api.TrainingListener;
|
import org.deeplearning4j.optimize.api.TrainingListener;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import oshi.json.SystemInfo;
|
import oshi.json.SystemInfo;
|
||||||
|
@ -49,12 +49,12 @@ public class SystemInfoPrintListener implements TrainingListener {
|
||||||
|
|
||||||
private static final String SYSTEM_INFO = "System info on epoch end: ";
|
private static final String SYSTEM_INFO = "System info on epoch end: ";
|
||||||
@Override
|
@Override
|
||||||
public void iterationDone(Model model, int iteration, int epoch) {
|
public void iterationDone(IModel model, int iteration, int epoch) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEpochStart(Model model) {
|
public void onEpochStart(IModel model) {
|
||||||
if(!printOnEpochStart)
|
if(!printOnEpochStart)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class SystemInfoPrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEpochEnd(Model model) {
|
public void onEpochEnd(IModel model) {
|
||||||
if(!printOnEpochEnd)
|
if(!printOnEpochEnd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class SystemInfoPrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForwardPass(Model model, List<INDArray> activations) {
|
public void onForwardPass(IModel model, List<INDArray> activations) {
|
||||||
if(!printOnBackwardPass)
|
if(!printOnBackwardPass)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class SystemInfoPrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForwardPass(Model model, Map<String, INDArray> activations) {
|
public void onForwardPass(IModel model, Map<String, INDArray> activations) {
|
||||||
if(!printOnForwardPass)
|
if(!printOnForwardPass)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public class SystemInfoPrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGradientCalculation(Model model) {
|
public void onGradientCalculation(IModel model) {
|
||||||
if(!printOnGradientCalculation)
|
if(!printOnGradientCalculation)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class SystemInfoPrintListener implements TrainingListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackwardPass(Model model) {
|
public void onBackwardPass(IModel model) {
|
||||||
if(!printOnBackwardPass)
|
if(!printOnBackwardPass)
|
||||||
return;
|
return;
|
||||||
SystemInfo systemInfo = new SystemInfo();
|
SystemInfo systemInfo = new SystemInfo();
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
package org.deeplearning4j.core.util;
|
package org.deeplearning4j.core.util;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.deeplearning4j.common.util.DL4JFileUtils;
|
import org.deeplearning4j.common.util.DL4JFileUtils;
|
||||||
import org.deeplearning4j.common.config.DL4JSystemProperties;
|
import org.deeplearning4j.common.config.DL4JSystemProperties;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.modelimport.keras.KerasModelImport;
|
import org.deeplearning4j.nn.modelimport.keras.KerasModelImport;
|
||||||
import org.deeplearning4j.util.ModelSerializer;
|
import org.deeplearning4j.util.ModelSerializer;
|
||||||
import org.nd4j.linalg.dataset.api.preprocessor.Normalizer;
|
import org.nd4j.linalg.dataset.api.preprocessor.Normalizer;
|
||||||
|
@ -80,7 +80,7 @@ public class ModelGuesser {
|
||||||
//note here that we load json BEFORE YAML. YAML
|
//note here that we load json BEFORE YAML. YAML
|
||||||
//turns out to load just fine *accidentally*
|
//turns out to load just fine *accidentally*
|
||||||
try {
|
try {
|
||||||
return MultiLayerConfiguration.fromJson(input);
|
return NeuralNetConfiguration.fromJson(input);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Tried multi layer config from json", e);
|
log.warn("Tried multi layer config from json", e);
|
||||||
try {
|
try {
|
||||||
|
@ -96,7 +96,7 @@ public class ModelGuesser {
|
||||||
} catch (Exception e3) {
|
} catch (Exception e3) {
|
||||||
log.warn("Tried computation graph from json");
|
log.warn("Tried computation graph from json");
|
||||||
try {
|
try {
|
||||||
return MultiLayerConfiguration.fromYaml(input);
|
return NeuralNetConfiguration.fromYaml(input);
|
||||||
} catch (Exception e4) {
|
} catch (Exception e4) {
|
||||||
log.warn("Tried multi layer configuration from yaml");
|
log.warn("Tried multi layer configuration from yaml");
|
||||||
try {
|
try {
|
||||||
|
@ -142,7 +142,7 @@ public class ModelGuesser {
|
||||||
* @return the loaded model
|
* @return the loaded model
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static Model loadModelGuess(String path) throws Exception {
|
public static IModel loadModelGuess(String path) throws Exception {
|
||||||
try {
|
try {
|
||||||
return ModelSerializer.restoreMultiLayerNetwork(new File(path), true);
|
return ModelSerializer.restoreMultiLayerNetwork(new File(path), true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -185,7 +185,7 @@ public class ModelGuesser {
|
||||||
* @return the loaded model
|
* @return the loaded model
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static Model loadModelGuess(InputStream stream) throws Exception {
|
public static IModel loadModelGuess(InputStream stream) throws Exception {
|
||||||
return loadModelGuess(stream, null);
|
return loadModelGuess(stream, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ public class ModelGuesser {
|
||||||
* @param stream Stream of the model file
|
* @param stream Stream of the model file
|
||||||
* @param tempDirectory Temporary/working directory. May be null.
|
* @param tempDirectory Temporary/working directory. May be null.
|
||||||
*/
|
*/
|
||||||
public static Model loadModelGuess(InputStream stream, File tempDirectory) throws Exception {
|
public static IModel loadModelGuess(InputStream stream, File tempDirectory) throws Exception {
|
||||||
//Currently (Nov 2017): KerasModelImport doesn't support loading from input streams
|
//Currently (Nov 2017): KerasModelImport doesn't support loading from input streams
|
||||||
//Simplest solution here: write to a temporary file
|
//Simplest solution here: write to a temporary file
|
||||||
File f;
|
File f;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.deeplearning4j.common.config.DL4JClassLoading;
|
import org.deeplearning4j.common.config.DL4JClassLoading;
|
||||||
import org.deeplearning4j.nn.api.Layer;
|
import org.deeplearning4j.nn.api.Layer;
|
||||||
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.LayerConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.SubsamplingLayer;
|
import org.deeplearning4j.nn.conf.layers.SubsamplingLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.optimize.listeners.CollectScoresListener;
|
import org.deeplearning4j.optimize.listeners.CollectScoresListener;
|
||||||
|
@ -99,7 +100,7 @@ public class LayerHelperValidationUtil {
|
||||||
|
|
||||||
//Don't allow fallback:
|
//Don't allow fallback:
|
||||||
for(Layer l : netOrig.getLayers()){
|
for(Layer l : netOrig.getLayers()){
|
||||||
org.deeplearning4j.nn.conf.layers.Layer lConf = l.conf().getLayer();
|
LayerConfiguration lConf = l.getLayerConfiguration();
|
||||||
if(lConf instanceof ConvolutionLayer){
|
if(lConf instanceof ConvolutionLayer){
|
||||||
((ConvolutionLayer) lConf).setCudnnAllowFallback(false);
|
((ConvolutionLayer) lConf).setCudnnAllowFallback(false);
|
||||||
} else if(lConf instanceof SubsamplingLayer){
|
} else if(lConf instanceof SubsamplingLayer){
|
||||||
|
@ -108,14 +109,14 @@ public class LayerHelperValidationUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MultiLayerNetwork net1NoHelper = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
|
MultiLayerNetwork net1NoHelper = new MultiLayerNetwork(netOrig.getNetConfiguration().clone());
|
||||||
net1NoHelper.init();
|
net1NoHelper.init();
|
||||||
log.info("Removing all layer helpers from network copy 1");
|
log.info("Removing all layer helpers from network copy 1");
|
||||||
removeHelpers(net1NoHelper.getLayers(), null);
|
removeHelpers(net1NoHelper.getLayers(), null);
|
||||||
|
|
||||||
MultiLayerNetwork net2With = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
|
MultiLayerNetwork net2With = new MultiLayerNetwork(netOrig.getNetConfiguration().clone());
|
||||||
net2With.init();
|
net2With.init();
|
||||||
net2With.params().assign(netOrig.params());
|
net2With.getModelParams().assign(netOrig.getModelParams());
|
||||||
log.info("Removing all except for specified helpers from network copy 2: " + t.getAllowHelpersForClasses());
|
log.info("Removing all except for specified helpers from network copy 2: " + t.getAllowHelpersForClasses());
|
||||||
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
|
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ public class LayerHelperValidationUtil {
|
||||||
Preconditions.checkNotNull(t.getFeatures(), "Features are not set (null)");
|
Preconditions.checkNotNull(t.getFeatures(), "Features are not set (null)");
|
||||||
|
|
||||||
for (boolean train : new boolean[]{false, true}) {
|
for (boolean train : new boolean[]{false, true}) {
|
||||||
assertEquals(net1NoHelper.params(), net2With.params());
|
assertEquals(net1NoHelper.getModelParams(), net2With.getModelParams());
|
||||||
String s = "Feed forward test - " + t.getTestName() + " - " + (train ? "Train: " : "Test: ");
|
String s = "Feed forward test - " + t.getTestName() + " - " + (train ? "Train: " : "Test: ");
|
||||||
List<INDArray> ff1;
|
List<INDArray> ff1;
|
||||||
try {
|
try {
|
||||||
|
@ -133,7 +134,7 @@ public class LayerHelperValidationUtil {
|
||||||
enableCppHelpers();
|
enableCppHelpers();
|
||||||
}
|
}
|
||||||
List<INDArray> ff2 = net2With.feedForward(t.getFeatures(), train);
|
List<INDArray> ff2 = net2With.feedForward(t.getFeatures(), train);
|
||||||
List<String> paramKeys = new ArrayList<>(net1NoHelper.paramTable().keySet());
|
List<String> paramKeys = new ArrayList<>(net1NoHelper.getParamTable().keySet());
|
||||||
Collections.sort(paramKeys);
|
Collections.sort(paramKeys);
|
||||||
for (String p : paramKeys) {
|
for (String p : paramKeys) {
|
||||||
INDArray p1 = net1NoHelper.getParam(p);
|
INDArray p1 = net1NoHelper.getParam(p);
|
||||||
|
@ -179,7 +180,7 @@ public class LayerHelperValidationUtil {
|
||||||
double maxRE = relError.maxNumber().doubleValue();
|
double maxRE = relError.maxNumber().doubleValue();
|
||||||
log.info(s + "Output, max relative error: " + maxRE);
|
log.info(s + "Output, max relative error: " + maxRE);
|
||||||
|
|
||||||
assertEquals(net1NoHelper.params(), net2With.params()); //Check that forward pass does not modify params
|
assertEquals(net1NoHelper.getModelParams(), net2With.getModelParams()); //Check that forward pass does not modify params
|
||||||
assertTrue(maxRE < t.getMaxRelError(), s + "Max RE: " + maxRE);
|
assertTrue(maxRE < t.getMaxRelError(), s + "Max RE: " + maxRE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,7 +225,7 @@ public class LayerHelperValidationUtil {
|
||||||
}
|
}
|
||||||
net2With.computeGradientAndScore();
|
net2With.computeGradientAndScore();
|
||||||
|
|
||||||
List<String> paramKeys = new ArrayList<>(net1NoHelper.paramTable().keySet());
|
List<String> paramKeys = new ArrayList<>(net1NoHelper.getParamTable().keySet());
|
||||||
Collections.sort(paramKeys);
|
Collections.sort(paramKeys);
|
||||||
for(String p : paramKeys){
|
for(String p : paramKeys){
|
||||||
INDArray g1 = net1NoHelper.gradient().gradientForVariable().get(p);
|
INDArray g1 = net1NoHelper.gradient().gradientForVariable().get(p);
|
||||||
|
@ -252,26 +253,26 @@ public class LayerHelperValidationUtil {
|
||||||
Preconditions.checkNotNull(t.getData(), "DataSetIterator is not set (null)");
|
Preconditions.checkNotNull(t.getData(), "DataSetIterator is not set (null)");
|
||||||
log.info("Testing run-to-run consistency of training with layer helper");
|
log.info("Testing run-to-run consistency of training with layer helper");
|
||||||
|
|
||||||
net2With = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
|
net2With = new MultiLayerNetwork(netOrig.getNetConfiguration().clone());
|
||||||
net2With.init();
|
net2With.init();
|
||||||
net2With.params().assign(netOrig.params());
|
net2With.getModelParams().assign(netOrig.getModelParams());
|
||||||
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());
|
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());
|
||||||
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
|
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
|
||||||
|
|
||||||
CollectScoresListener listener = new CollectScoresListener(1);
|
CollectScoresListener listener = new CollectScoresListener(1);
|
||||||
net2With.setListeners(listener);
|
net2With.addTrainingListeners(listener);
|
||||||
net2With.fit(t.getData());
|
net2With.fit(t.getData());
|
||||||
|
|
||||||
for( int i=0; i<2; i++ ) {
|
for( int i=0; i<2; i++ ) {
|
||||||
|
|
||||||
net2With = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
|
net2With = new MultiLayerNetwork(netOrig.getNetConfiguration().clone());
|
||||||
net2With.init();
|
net2With.init();
|
||||||
net2With.params().assign(netOrig.params());
|
net2With.getModelParams().assign(netOrig.getModelParams());
|
||||||
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());
|
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());
|
||||||
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
|
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
|
||||||
|
|
||||||
CollectScoresListener listener2 = new CollectScoresListener(1);
|
CollectScoresListener listener2 = new CollectScoresListener(1);
|
||||||
net2With.setListeners(listener2);
|
net2With.addTrainingListeners(listener2);
|
||||||
net2With.fit(t.getData());
|
net2With.fit(t.getData());
|
||||||
|
|
||||||
DoubleArrayList listOrig = listener.getListScore();
|
DoubleArrayList listOrig = listener.getListScore();
|
||||||
|
|
|
@ -23,19 +23,15 @@ package org.deeplearning4j;
|
||||||
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.common.resources.Resources;
|
|
||||||
import org.nd4j.linalg.activations.Activation;
|
import org.nd4j.linalg.activations.Activation;
|
||||||
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
||||||
import org.nd4j.linalg.factory.Nd4j;
|
|
||||||
import org.nd4j.linalg.learning.config.RmsProp;
|
import org.nd4j.linalg.learning.config.RmsProp;
|
||||||
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
//@Ignore
|
//@Ignore
|
||||||
|
@ -44,8 +40,8 @@ public class RandomTests extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testReproduce() throws Exception {
|
public void testReproduce() throws Exception {
|
||||||
|
|
||||||
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
|
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(10)
|
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(10)
|
||||||
.activation(Activation.TANH).build())
|
.activation(Activation.TANH).build())
|
||||||
.layer(1, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder(
|
.layer(1, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder(
|
||||||
|
|
|
@ -23,9 +23,9 @@ package org.deeplearning4j;
|
||||||
import org.apache.commons.compress.utils.IOUtils;
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
import org.deeplearning4j.nn.api.Layer;
|
import org.deeplearning4j.nn.api.Layer;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.RNNFormat;
|
import org.deeplearning4j.nn.conf.RNNFormat;
|
||||||
import org.deeplearning4j.nn.conf.layers.BaseLayer;
|
import org.deeplearning4j.nn.conf.layers.BaseLayerConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.samediff.AbstractSameDiffLayer;
|
import org.deeplearning4j.nn.conf.layers.samediff.AbstractSameDiffLayer;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
import org.deeplearning4j.nn.layers.convolution.ConvolutionLayer;
|
import org.deeplearning4j.nn.layers.convolution.ConvolutionLayer;
|
||||||
|
@ -66,15 +66,15 @@ public class TestUtils {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||||
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
|
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
|
||||||
|
|
||||||
assertEquals(net.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
|
assertEquals(net.getNetConfiguration(), restored.getNetConfiguration());
|
||||||
assertEquals(net.params(), restored.params());
|
assertEquals(net.getModelParams(), restored.getModelParams());
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
//Should never happen
|
//Should never happen
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Also check the MultiLayerConfiguration is serializable (required by Spark etc)
|
//Also check the NeuralNetConfiguration is serializable (required by Spark etc)
|
||||||
MultiLayerConfiguration conf = net.getLayerWiseConfigurations();
|
NeuralNetConfiguration conf = net.getNetConfiguration();
|
||||||
serializeDeserializeJava(conf);
|
serializeDeserializeJava(conf);
|
||||||
|
|
||||||
return restored;
|
return restored;
|
||||||
|
@ -90,15 +90,15 @@ public class TestUtils {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||||
restored = ModelSerializer.restoreComputationGraph(bais, true);
|
restored = ModelSerializer.restoreComputationGraph(bais, true);
|
||||||
|
|
||||||
assertEquals(net.getConfiguration(), restored.getConfiguration());
|
assertEquals(net.getComputationGraphConfiguration(), restored.getComputationGraphConfiguration());
|
||||||
assertEquals(net.params(), restored.params());
|
assertEquals(net.getModelParams(), restored.getModelParams());
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
//Should never happen
|
//Should never happen
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Also check the ComputationGraphConfiguration is serializable (required by Spark etc)
|
//Also check the ComputationGraphConfiguration is serializable (required by Spark etc)
|
||||||
ComputationGraphConfiguration conf = net.getConfiguration();
|
ComputationGraphConfiguration conf = net.getComputationGraphConfiguration();
|
||||||
serializeDeserializeJava(conf);
|
serializeDeserializeJava(conf);
|
||||||
|
|
||||||
return restored;
|
return restored;
|
||||||
|
@ -205,8 +205,8 @@ public class TestUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static L2Regularization getL2Reg(BaseLayer baseLayer){
|
public static L2Regularization getL2Reg(BaseLayerConfiguration baseLayerConfiguration){
|
||||||
return getL2Reg(baseLayer.getRegularization());
|
return getL2Reg(baseLayerConfiguration.getRegularization());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static L2Regularization getL2Reg(List<Regularization> l){
|
public static L2Regularization getL2Reg(List<Regularization> l){
|
||||||
|
@ -218,7 +218,7 @@ public class TestUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WeightDecay getWeightDecayReg(BaseLayer bl){
|
public static WeightDecay getWeightDecayReg(BaseLayerConfiguration bl){
|
||||||
return getWeightDecayReg(bl.getRegularization());
|
return getWeightDecayReg(bl.getRegularization());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ public class TestUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getL1(BaseLayer layer) {
|
public static double getL1(BaseLayerConfiguration layer) {
|
||||||
List<Regularization> l = layer.getRegularization();
|
List<Regularization> l = layer.getRegularization();
|
||||||
return getL1(l);
|
return getL1(l);
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ public class TestUtils {
|
||||||
return l1Reg.getL1().valueAt(0,0);
|
return l1Reg.getL1().valueAt(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getL2(BaseLayer layer) {
|
public static double getL2(BaseLayerConfiguration layer) {
|
||||||
List<Regularization> l = layer.getRegularization();
|
List<Regularization> l = layer.getRegularization();
|
||||||
return getL2(l);
|
return getL2(l);
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ public class TestUtils {
|
||||||
return getL2(layer.getRegularization());
|
return getL2(layer.getRegularization());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getWeightDecay(BaseLayer layer) {
|
public static double getWeightDecay(BaseLayerConfiguration layer) {
|
||||||
return getWeightDecayReg(layer.getRegularization()).getCoeff().valueAt(0,0);
|
return getWeightDecayReg(layer.getRegularization()).getCoeff().valueAt(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,14 +317,14 @@ public class TestUtils {
|
||||||
for(Layer l : layers){
|
for(Layer l : layers){
|
||||||
//Don't use instanceof here - there are sub conv subclasses
|
//Don't use instanceof here - there are sub conv subclasses
|
||||||
if(l.getClass() == ConvolutionLayer.class || l instanceof SubsamplingLayer || l instanceof BatchNormalization || l instanceof LSTM){
|
if(l.getClass() == ConvolutionLayer.class || l instanceof SubsamplingLayer || l instanceof BatchNormalization || l instanceof LSTM){
|
||||||
Preconditions.checkNotNull(l.getHelper(), l.conf().getLayer().getLayerName());
|
Preconditions.checkNotNull(l.getHelper(), l.getLayerConfiguration().getLayerName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertHelpersAbsent(Layer[] layers) throws Exception {
|
public static void assertHelpersAbsent(Layer[] layers) throws Exception {
|
||||||
for(Layer l : layers){
|
for(Layer l : layers){
|
||||||
Preconditions.checkState(l.getHelper() == null, l.conf().getLayer().getLayerName());
|
Preconditions.checkState(l.getHelper() == null, l.getLayerConfiguration().getLayerName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.deeplearning4j.datasets.iterator.impl.*;
|
||||||
import org.deeplearning4j.eval.Evaluation;
|
import org.deeplearning4j.eval.Evaluation;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.GradientNormalization;
|
import org.deeplearning4j.nn.conf.GradientNormalization;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
|
||||||
|
@ -168,9 +167,9 @@ public class DataSetIteratorTest extends BaseDL4JTest {
|
||||||
LFWDataSetIterator lfw = new LFWDataSetIterator(batchSize, numSamples,
|
LFWDataSetIterator lfw = new LFWDataSetIterator(batchSize, numSamples,
|
||||||
new int[] {numRows, numColumns, numChannels}, outputNum, false, true, 1.0, new Random(seed));
|
new int[] {numRows, numColumns, numChannels}, outputNum, false, true, 1.0, new Random(seed));
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(seed)
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().seed(seed)
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.layer(0, new ConvolutionLayer.Builder(5, 5).nIn(numChannels).nOut(6)
|
.layer(0, new ConvolutionLayer.Builder(5, 5).nIn(numChannels).nOut(6)
|
||||||
.weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
.weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
|
||||||
.layer(1, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
|
.layer(1, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
|
||||||
|
@ -178,13 +177,12 @@ public class DataSetIteratorTest extends BaseDL4JTest {
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
|
||||||
.nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
|
.nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutionalFlat(numRows, numColumns, numChannels))
|
.inputType(InputType.convolutionalFlat(numRows, numColumns, numChannels));
|
||||||
;
|
|
||||||
|
|
||||||
MultiLayerNetwork model = new MultiLayerNetwork(builder.build());
|
MultiLayerNetwork model = new MultiLayerNetwork(builder.build());
|
||||||
model.init();
|
model.init();
|
||||||
|
|
||||||
model.setListeners(new ScoreIterationListener(listenerFreq));
|
model.addTrainingListeners(new ScoreIterationListener(listenerFreq));
|
||||||
|
|
||||||
model.fit(lfw.next());
|
model.fit(lfw.next());
|
||||||
|
|
||||||
|
@ -229,9 +227,9 @@ public class DataSetIteratorTest extends BaseDL4JTest {
|
||||||
|
|
||||||
Cifar10DataSetIterator cifar = new Cifar10DataSetIterator(batchSize);
|
Cifar10DataSetIterator cifar = new Cifar10DataSetIterator(batchSize);
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(seed)
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().seed(seed)
|
||||||
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.layer(0, new ConvolutionLayer.Builder(5, 5).nIn(channels).nOut(6).weightInit(WeightInit.XAVIER)
|
.layer(0, new ConvolutionLayer.Builder(5, 5).nIn(channels).nOut(6).weightInit(WeightInit.XAVIER)
|
||||||
.activation(Activation.RELU).build())
|
.activation(Activation.RELU).build())
|
||||||
.layer(1, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
|
.layer(1, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
|
||||||
|
@ -240,7 +238,7 @@ public class DataSetIteratorTest extends BaseDL4JTest {
|
||||||
.nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
|
.nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
|
||||||
.build())
|
.build())
|
||||||
|
|
||||||
.setInputType(InputType.convolutionalFlat(height, width, channels));
|
.inputType(InputType.convolutionalFlat(height, width, channels));
|
||||||
|
|
||||||
MultiLayerNetwork model = new MultiLayerNetwork(builder.build());
|
MultiLayerNetwork model = new MultiLayerNetwork(builder.build());
|
||||||
model.init();
|
model.init();
|
||||||
|
@ -248,7 +246,7 @@ public class DataSetIteratorTest extends BaseDL4JTest {
|
||||||
//model.setListeners(Arrays.asList((TrainingListener) new ScoreIterationListener(listenerFreq)));
|
//model.setListeners(Arrays.asList((TrainingListener) new ScoreIterationListener(listenerFreq)));
|
||||||
|
|
||||||
CollectScoresIterationListener listener = new CollectScoresIterationListener(listenerFreq);
|
CollectScoresIterationListener listener = new CollectScoresIterationListener(listenerFreq);
|
||||||
model.setListeners(listener);
|
model.addTrainingListeners(listener);
|
||||||
|
|
||||||
model.fit(cifar);
|
model.fit(cifar);
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,9 @@ import org.deeplearning4j.earlystopping.scorecalc.*;
|
||||||
import org.deeplearning4j.earlystopping.termination.*;
|
import org.deeplearning4j.earlystopping.termination.*;
|
||||||
import org.deeplearning4j.earlystopping.trainer.EarlyStoppingTrainer;
|
import org.deeplearning4j.earlystopping.trainer.EarlyStoppingTrainer;
|
||||||
import org.deeplearning4j.earlystopping.trainer.IEarlyStoppingTrainer;
|
import org.deeplearning4j.earlystopping.trainer.IEarlyStoppingTrainer;
|
||||||
import org.deeplearning4j.nn.api.Model;
|
import net.brutex.ai.dnn.api.IModel;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.GradientNormalization;
|
import org.deeplearning4j.nn.conf.GradientNormalization;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.*;
|
||||||
import org.deeplearning4j.nn.conf.layers.variational.BernoulliReconstructionDistribution;
|
import org.deeplearning4j.nn.conf.layers.variational.BernoulliReconstructionDistribution;
|
||||||
|
@ -133,9 +132,9 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
String msg = i + " - " + sc.getClass().getSimpleName();
|
String msg = i + " - " + sc.getClass().getSimpleName();
|
||||||
log.info("Starting test - {}", msg);
|
log.info("Starting test - {}", msg);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.updater(new Sgd(0.5)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.5)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build())
|
.layer(new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build())
|
||||||
.layer(new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
|
@ -219,15 +218,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEarlyStoppingEveryNEpoch() {
|
public void testEarlyStoppingEveryNEpoch() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.01)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.01)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -248,15 +247,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEarlyStoppingIrisMultiEpoch() {
|
public void testEarlyStoppingIrisMultiEpoch() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
MultipleEpochsIterator mIter = new MultipleEpochsIterator(10, irisIter);
|
MultipleEpochsIterator mIter = new MultipleEpochsIterator(10, irisIter);
|
||||||
|
@ -297,15 +296,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
//Test poor tuning (high LR): should terminate on MaxScoreIterationTerminationCondition
|
//Test poor tuning (high LR): should terminate on MaxScoreIterationTerminationCondition
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(5.0)) //Intentionally huge LR
|
.updater(new Sgd(5.0)) //Intentionally huge LR
|
||||||
.weightInit(WeightInit.XAVIER).list()
|
.weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -336,15 +335,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
//test termination after max time
|
//test termination after max time
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
|
@ -379,15 +378,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
//Simulate this by setting LR = 0.0
|
//Simulate this by setting LR = 0.0
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
|
@ -419,9 +418,9 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
//Simulate this by setting LR = 0.0
|
//Simulate this by setting LR = 0.0
|
||||||
Random rng = new Random(123);
|
Random rng = new Random(123);
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Nesterovs(0.0,0.9)).list()
|
.updater(new Nesterovs(0.0,0.9))
|
||||||
.layer(0, new DenseLayer.Builder().nIn(1).nOut(20)
|
.layer(0, new DenseLayer.Builder().nIn(1).nOut(20)
|
||||||
.weightInit(WeightInit.XAVIER).activation(
|
.weightInit(WeightInit.XAVIER).activation(
|
||||||
Activation.TANH)
|
Activation.TANH)
|
||||||
|
@ -431,7 +430,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
int nSamples = 100;
|
int nSamples = 100;
|
||||||
//Generate the training data
|
//Generate the training data
|
||||||
INDArray x = Nd4j.linspace(-10, 10, nSamples).reshape(nSamples, 1);
|
INDArray x = Nd4j.linspace(-10, 10, nSamples).reshape(nSamples, 1);
|
||||||
|
@ -466,15 +465,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEarlyStoppingGetBestModel() {
|
public void testEarlyStoppingGetBestModel() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
MultipleEpochsIterator mIter = new MultipleEpochsIterator(10, irisIter);
|
MultipleEpochsIterator mIter = new MultipleEpochsIterator(10, irisIter);
|
||||||
|
@ -496,23 +495,23 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
MultiLayerNetwork mln = result.getBestModel();
|
MultiLayerNetwork mln = result.getBestModel();
|
||||||
|
|
||||||
assertEquals(net.getnLayers(), mln.getnLayers());
|
assertEquals(net.getnLayers(), mln.getnLayers());
|
||||||
assertEquals(net.conf().getOptimizationAlgo(), mln.conf().getOptimizationAlgo());
|
assertEquals(net.getNetConfiguration().getOptimizationAlgo(), mln.getNetConfiguration().getOptimizationAlgo());
|
||||||
BaseLayer bl = (BaseLayer) net.conf().getLayer();
|
BaseLayerConfiguration bl = (BaseLayerConfiguration) net.getLayerConfiguration();
|
||||||
assertEquals(bl.getActivationFn().toString(), ((BaseLayer) mln.conf().getLayer()).getActivationFn().toString());
|
assertEquals(bl.getActivationFn().toString(), ((BaseLayerConfiguration) mln.getLayerConfiguration()).getActivationFn().toString());
|
||||||
assertEquals(bl.getIUpdater(), ((BaseLayer) mln.conf().getLayer()).getIUpdater());
|
assertEquals(bl.getIUpdater(), ((BaseLayerConfiguration) mln.getLayerConfiguration()).getIUpdater());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListeners() {
|
public void testListeners() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -569,8 +568,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
Metric.MAE}) {
|
Metric.MAE}) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
|
||||||
.layer(new DenseLayer.Builder().nIn(784).nOut(32).build())
|
.layer(new DenseLayer.Builder().nIn(784).nOut(32).build())
|
||||||
.layer(new OutputLayer.Builder().nIn(32).nOut(784).activation(Activation.SIGMOID).lossFunction(LossFunctions.LossFunction.MSE).build())
|
.layer(new OutputLayer.Builder().nIn(32).nOut(784).activation(Activation.SIGMOID).lossFunction(LossFunctions.LossFunction.MSE).build())
|
||||||
.build();
|
.build();
|
||||||
|
@ -612,8 +611,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
Metric.MAE}) {
|
Metric.MAE}) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
|
||||||
.layer(new AutoEncoder.Builder().nIn(784).nOut(32).build())
|
.layer(new AutoEncoder.Builder().nIn(784).nOut(32).build())
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
|
@ -655,8 +654,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
Metric.MAE}) {
|
Metric.MAE}) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
|
||||||
.layer(new VariationalAutoencoder.Builder()
|
.layer(new VariationalAutoencoder.Builder()
|
||||||
.nIn(784).nOut(32)
|
.nIn(784).nOut(32)
|
||||||
.encoderLayerSizes(64)
|
.encoderLayerSizes(64)
|
||||||
|
@ -700,8 +699,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
|
|
||||||
for(boolean logProb : new boolean[]{false, true}) {
|
for(boolean logProb : new boolean[]{false, true}) {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
|
||||||
.layer(new VariationalAutoencoder.Builder()
|
.layer(new VariationalAutoencoder.Builder()
|
||||||
.nIn(784).nOut(32)
|
.nIn(784).nOut(32)
|
||||||
.encoderLayerSizes(64)
|
.encoderLayerSizes(64)
|
||||||
|
@ -747,8 +746,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
for(Evaluation.Metric metric : Evaluation.Metric.values()) {
|
for(Evaluation.Metric metric : Evaluation.Metric.values()) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.list()
|
|
||||||
.layer(new DenseLayer.Builder().nIn(784).nOut(32).build())
|
.layer(new DenseLayer.Builder().nIn(784).nOut(32).build())
|
||||||
.layer(new OutputLayer.Builder().nIn(32).nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(new OutputLayer.Builder().nIn(32).nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
.build();
|
.build();
|
||||||
|
@ -784,8 +783,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEarlyStoppingListeners() {
|
public void testEarlyStoppingListeners() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).list()
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
|
||||||
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
|
@ -793,7 +792,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
|
||||||
TestListener tl = new TestListener();
|
TestListener tl = new TestListener();
|
||||||
net.setListeners(tl);
|
net.addTrainingListeners(tl);
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(50, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(50, 150);
|
||||||
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -827,19 +826,19 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
private int maxEpochEnd = -1;
|
private int maxEpochEnd = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEpochStart(Model model){
|
public void onEpochStart(IModel model){
|
||||||
countEpochStart++;
|
countEpochStart++;
|
||||||
maxEpochStart = Math.max(maxEpochStart, BaseOptimizer.getEpochCount(model));
|
maxEpochStart = Math.max(maxEpochStart, BaseOptimizer.getEpochCount(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEpochEnd(Model model){
|
public void onEpochEnd(IModel model){
|
||||||
countEpochEnd++;
|
countEpochEnd++;
|
||||||
maxEpochEnd = Math.max(maxEpochEnd, BaseOptimizer.getEpochCount(model));
|
maxEpochEnd = Math.max(maxEpochEnd, BaseOptimizer.getEpochCount(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void iterationDone(Model model, int iteration, int epoch){
|
public void iterationDone(IModel model, int iteration, int epoch){
|
||||||
iterCount++;
|
iterCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,7 +858,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
DataSetIterator test = new SingletonDataSetIterator(ds);
|
DataSetIterator test = new SingletonDataSetIterator(ds);
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(123)
|
.seed(123)
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
.updater(new Adam(0.1))
|
.updater(new Adam(0.1))
|
||||||
|
@ -868,7 +867,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
|
||||||
.gradientNormalization(GradientNormalization
|
.gradientNormalization(GradientNormalization
|
||||||
.ClipElementWiseAbsoluteValue)
|
.ClipElementWiseAbsoluteValue)
|
||||||
.gradientNormalizationThreshold(1.0)
|
.gradientNormalizationThreshold(1.0)
|
||||||
.list()
|
|
||||||
.layer(0, new LSTM.Builder()
|
.layer(0, new LSTM.Builder()
|
||||||
.nIn(10)
|
.nIn(10)
|
||||||
.nOut(10)
|
.nOut(10)
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEarlyStoppingIris() {
|
public void testEarlyStoppingIris() {
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -84,7 +84,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
||||||
.setOutputs("0").build();
|
.setOutputs("0").build();
|
||||||
ComputationGraph net = new ComputationGraph(conf);
|
ComputationGraph net = new ComputationGraph(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -120,7 +120,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
//Test poor tuning (high LR): should terminate on MaxScoreIterationTerminationCondition
|
//Test poor tuning (high LR): should terminate on MaxScoreIterationTerminationCondition
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(5.0)) //Intentionally huge LR
|
.updater(new Sgd(5.0)) //Intentionally huge LR
|
||||||
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
|
@ -128,7 +128,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
||||||
.setOutputs("0").build();
|
.setOutputs("0").build();
|
||||||
ComputationGraph net = new ComputationGraph(conf);
|
ComputationGraph net = new ComputationGraph(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -156,7 +156,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
//test termination after max time
|
//test termination after max time
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).graphBuilder()
|
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -165,7 +165,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
||||||
.setOutputs("0").build();
|
.setOutputs("0").build();
|
||||||
ComputationGraph net = new ComputationGraph(conf);
|
ComputationGraph net = new ComputationGraph(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
//Simulate this by setting LR = 0.0
|
//Simulate this by setting LR = 0.0
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).graphBuilder()
|
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -207,7 +207,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
||||||
.setOutputs("0").build();
|
.setOutputs("0").build();
|
||||||
ComputationGraph net = new ComputationGraph(conf);
|
ComputationGraph net = new ComputationGraph(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListeners() {
|
public void testListeners() {
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
|
||||||
|
@ -241,7 +241,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
|
||||||
.setOutputs("0").build();
|
.setOutputs("0").build();
|
||||||
ComputationGraph net = new ComputationGraph(conf);
|
ComputationGraph net = new ComputationGraph(conf);
|
||||||
net.setListeners(new ScoreIterationListener(1));
|
net.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
|
||||||
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
||||||
|
@ -297,7 +297,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
Metric.MAE}) {
|
Metric.MAE}) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.layer("0", new DenseLayer.Builder().nIn(784).nOut(32).build(), "in")
|
.layer("0", new DenseLayer.Builder().nIn(784).nOut(32).build(), "in")
|
||||||
|
@ -343,7 +343,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
Metric.MAE}) {
|
Metric.MAE}) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.layer("0", new AutoEncoder.Builder().nIn(784).nOut(32).build(), "in")
|
.layer("0", new AutoEncoder.Builder().nIn(784).nOut(32).build(), "in")
|
||||||
|
@ -388,7 +388,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
Metric.MAE}) {
|
Metric.MAE}) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.layer("0", new VariationalAutoencoder.Builder()
|
.layer("0", new VariationalAutoencoder.Builder()
|
||||||
|
@ -435,7 +435,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
|
|
||||||
for(boolean logProb : new boolean[]{false, true}) {
|
for(boolean logProb : new boolean[]{false, true}) {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.updater(new Adam(1e-5))
|
.updater(new Adam(1e-5))
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -486,7 +486,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
for(Evaluation.Metric metric : Evaluation.Metric.values()) {
|
for(Evaluation.Metric metric : Evaluation.Metric.values()) {
|
||||||
log.info("Metric: " + metric);
|
log.info("Metric: " + metric);
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.layer("0", new DenseLayer.Builder().nIn(784).nOut(32).build(), "in")
|
.layer("0", new DenseLayer.Builder().nIn(784).nOut(32).build(), "in")
|
||||||
|
@ -526,7 +526,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEarlyStoppingListenersCG() {
|
public void testEarlyStoppingListenersCG() {
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
|
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -538,7 +538,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
|
||||||
ComputationGraph net = new ComputationGraph(conf);
|
ComputationGraph net = new ComputationGraph(conf);
|
||||||
|
|
||||||
TestEarlyStopping.TestListener tl = new TestEarlyStopping.TestListener();
|
TestEarlyStopping.TestListener tl = new TestEarlyStopping.TestListener();
|
||||||
net.setListeners(tl);
|
net.addTrainingListeners(tl);
|
||||||
|
|
||||||
DataSetIterator irisIter = new IrisDataSetIterator(50, 150);
|
DataSetIterator irisIter = new IrisDataSetIterator(50, 150);
|
||||||
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
public void testIris() {
|
public void testIris() {
|
||||||
|
|
||||||
// Network config
|
// Network config
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
|
|
||||||
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).seed(42)
|
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).seed(42)
|
||||||
.updater(new Sgd(1e-6)).list()
|
.updater(new Sgd(1e-6)).list()
|
||||||
|
@ -84,7 +84,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
// Instantiate model
|
// Instantiate model
|
||||||
MultiLayerNetwork model = new MultiLayerNetwork(conf);
|
MultiLayerNetwork model = new MultiLayerNetwork(conf);
|
||||||
model.init();
|
model.init();
|
||||||
model.addListeners(new ScoreIterationListener(1));
|
model.addTrainingListeners(new ScoreIterationListener(1));
|
||||||
|
|
||||||
// Train-test split
|
// Train-test split
|
||||||
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
||||||
|
@ -177,7 +177,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
rrdsi.reset();
|
rrdsi.reset();
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).updater(new Sgd(0.1))
|
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).updater(new Sgd(0.1))
|
||||||
.list()
|
.list()
|
||||||
.layer(0, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(0, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
|
@ -295,7 +295,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
int tbpttLength = 10;
|
int tbpttLength = 10;
|
||||||
int tsLength = 5 * tbpttLength + tbpttLength / 2;
|
int tsLength = 5 * tbpttLength + tbpttLength / 2;
|
||||||
|
|
||||||
MultiLayerConfiguration conf1 = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf1 = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.trainingWorkspaceMode(ws)
|
.trainingWorkspaceMode(ws)
|
||||||
.inferenceWorkspaceMode(ws)
|
.inferenceWorkspaceMode(ws)
|
||||||
|
@ -306,7 +306,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerConfiguration conf2 = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf2 = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.trainingWorkspaceMode(ws)
|
.trainingWorkspaceMode(ws)
|
||||||
.inferenceWorkspaceMode(ws)
|
.inferenceWorkspaceMode(ws)
|
||||||
|
@ -314,7 +314,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
.layer(new LSTM.Builder().nIn(nIn).nOut(layerSize).build())
|
.layer(new LSTM.Builder().nIn(nIn).nOut(layerSize).build())
|
||||||
.layer(new RnnOutputLayer.Builder().nIn(layerSize).nOut(nOut)
|
.layer(new RnnOutputLayer.Builder().nIn(layerSize).nOut(nOut)
|
||||||
.activation(Activation.SOFTMAX).build())
|
.activation(Activation.SOFTMAX).build())
|
||||||
.tBPTTLength(10)
|
.tbpttFwdLength(10).tbpttBackLength(10)
|
||||||
.backpropType(BackpropType.TruncatedBPTT)
|
.backpropType(BackpropType.TruncatedBPTT)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
MultiLayerNetwork net2 = new MultiLayerNetwork(conf2);
|
MultiLayerNetwork net2 = new MultiLayerNetwork(conf2);
|
||||||
net2.init();
|
net2.init();
|
||||||
|
|
||||||
net2.setParams(net1.params());
|
net2.setParams(net1.getModelParams());
|
||||||
|
|
||||||
for(boolean useMask : new boolean[]{false, true}) {
|
for(boolean useMask : new boolean[]{false, true}) {
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
int tbpttLength = 10;
|
int tbpttLength = 10;
|
||||||
int tsLength = 5 * tbpttLength + tbpttLength / 2;
|
int tsLength = 5 * tbpttLength + tbpttLength / 2;
|
||||||
|
|
||||||
ComputationGraphConfiguration conf1 = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf1 = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.trainingWorkspaceMode(ws)
|
.trainingWorkspaceMode(ws)
|
||||||
.inferenceWorkspaceMode(ws)
|
.inferenceWorkspaceMode(ws)
|
||||||
|
@ -384,7 +384,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
.setOutputs("1")
|
.setOutputs("1")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ComputationGraphConfiguration conf2 = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf2 = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.trainingWorkspaceMode(ws)
|
.trainingWorkspaceMode(ws)
|
||||||
.inferenceWorkspaceMode(ws)
|
.inferenceWorkspaceMode(ws)
|
||||||
|
@ -405,7 +405,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
ComputationGraph net2 = new ComputationGraph(conf2);
|
ComputationGraph net2 = new ComputationGraph(conf2);
|
||||||
net2.init();
|
net2.init();
|
||||||
|
|
||||||
net2.setParams(net1.params());
|
net2.setParams(net1.getModelParams());
|
||||||
|
|
||||||
for (boolean useMask : new boolean[]{false, true}) {
|
for (boolean useMask : new boolean[]{false, true}) {
|
||||||
|
|
||||||
|
@ -455,12 +455,12 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
DataSetIterator testData = new SequenceRecordReaderDataSetIterator(fsr, lsr, 1, -1, true,
|
DataSetIterator testData = new SequenceRecordReaderDataSetIterator(fsr, lsr, 1, -1, true,
|
||||||
SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END);
|
SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
|
||||||
.list()
|
.list()
|
||||||
.layer(0, new LSTM.Builder().activation(Activation.TANH).nIn(3).nOut(3).build())
|
.layer(0, new LSTM.Builder().activation(Activation.TANH).nIn(3).nOut(3).build())
|
||||||
.layer(1, new RnnOutputLayer.Builder().activation(Activation.SIGMOID).lossFunction(LossFunctions.LossFunction.XENT)
|
.layer(1, new RnnOutputLayer.Builder().activation(Activation.SIGMOID).lossFunction(LossFunctions.LossFunction.XENT)
|
||||||
.nIn(3).nOut(1).build())
|
.nIn(3).nOut(1).build())
|
||||||
.backpropType(BackpropType.TruncatedBPTT).tBPTTForwardLength(10).tBPTTBackwardLength(10)
|
.backpropType(BackpropType.TruncatedBPTT).tbpttFwdLength(10).tbpttBackLength(10)
|
||||||
.build();
|
.build();
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -473,7 +473,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
//Sanity check: https://github.com/eclipse/deeplearning4j/issues/5351
|
//Sanity check: https://github.com/eclipse/deeplearning4j/issues/5351
|
||||||
|
|
||||||
// Network config
|
// Network config
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
|
|
||||||
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).seed(42)
|
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).seed(42)
|
||||||
.updater(new Sgd(1e-6)).list()
|
.updater(new Sgd(1e-6)).list()
|
||||||
|
@ -492,7 +492,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
DataSetIterator iter = new IrisDataSetIterator(30, 150);
|
DataSetIterator iter = new IrisDataSetIterator(30, 150);
|
||||||
DataSetIterator iterTest = new IrisDataSetIterator(30, 150);
|
DataSetIterator iterTest = new IrisDataSetIterator(30, 150);
|
||||||
|
|
||||||
net.setListeners(new EvaluativeListener(iterTest, 3));
|
net.addTrainingListeners(new EvaluativeListener(iterTest, 3));
|
||||||
|
|
||||||
for( int i=0; i<3; i++ ){
|
for( int i=0; i<3; i++ ){
|
||||||
net.fit(iter);
|
net.fit(iter);
|
||||||
|
@ -503,7 +503,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
public void testMultiOutputEvalSimple(){
|
public void testMultiOutputEvalSimple(){
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.seed(12345)
|
.seed(12345)
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
|
@ -538,7 +538,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
public void testMultiOutputEvalCG(){
|
public void testMultiOutputEvalCG(){
|
||||||
//Simple sanity check on evaluation
|
//Simple sanity check on evaluation
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.graphBuilder()
|
.graphBuilder()
|
||||||
.addInputs("in")
|
.addInputs("in")
|
||||||
.layer("0", new EmbeddingSequenceLayer.Builder().nIn(10).nOut(10).build(), "in")
|
.layer("0", new EmbeddingSequenceLayer.Builder().nIn(10).nOut(10).build(), "in")
|
||||||
|
@ -566,7 +566,7 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidEvaluation(){
|
public void testInvalidEvaluation(){
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
|
|
||||||
.list()
|
.list()
|
||||||
.layer(new DenseLayer.Builder().nIn(4).nOut(10).build())
|
.layer(new DenseLayer.Builder().nIn(4).nOut(10).build())
|
||||||
|
@ -622,11 +622,11 @@ public class EvalTest extends BaseDL4JTest {
|
||||||
|
|
||||||
|
|
||||||
//Disable validation, and check same thing:
|
//Disable validation, and check same thing:
|
||||||
net.getLayerWiseConfigurations().setValidateOutputLayerConfig(false);
|
net.getNetConfiguration().setValidateOutputLayerConfig(false);
|
||||||
net.evaluate(iter);
|
net.evaluate(iter);
|
||||||
net.evaluateROCMultiClass(iter, 0);
|
net.evaluateROCMultiClass(iter, 0);
|
||||||
|
|
||||||
cg.getConfiguration().setValidateOutputLayerConfig(false);
|
cg.getComputationGraphConfiguration().setValidateOutputLayerConfig(false);
|
||||||
cg.evaluate(iter);
|
cg.evaluate(iter);
|
||||||
cg.evaluateROCMultiClass(iter, 0);
|
cg.evaluateROCMultiClass(iter, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ package org.deeplearning4j.eval;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.core.evaluation.EvaluationTools;
|
import org.deeplearning4j.core.evaluation.EvaluationTools;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
@ -48,7 +47,7 @@ public class EvaluationToolsTests extends BaseDL4JTest {
|
||||||
|
|
||||||
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build()).layer(1,
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build()).layer(1,
|
||||||
new OutputLayer.Builder().nIn(4).nOut(2).activation(Activation.SOFTMAX)
|
new OutputLayer.Builder().nIn(4).nOut(2).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
|
@ -82,7 +81,7 @@ public class EvaluationToolsTests extends BaseDL4JTest {
|
||||||
|
|
||||||
|
|
||||||
String str = EvaluationTools.rocChartToHtml(roc);
|
String str = EvaluationTools.rocChartToHtml(roc);
|
||||||
// System.out.println(str);
|
System.out.println(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ public class EvaluationToolsTests extends BaseDL4JTest {
|
||||||
public void testRocMultiToHtml() throws Exception {
|
public void testRocMultiToHtml() throws Exception {
|
||||||
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build()).layer(1,
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build()).layer(1,
|
||||||
new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
|
new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
|
|
|
@ -22,23 +22,19 @@ package org.deeplearning4j.eval;
|
||||||
|
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.nn.weights.WeightInit;
|
import org.deeplearning4j.nn.weights.WeightInit;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.evaluation.curves.PrecisionRecallCurve;
|
|
||||||
import org.nd4j.evaluation.curves.RocCurve;
|
import org.nd4j.evaluation.curves.RocCurve;
|
||||||
import org.nd4j.linalg.activations.Activation;
|
import org.nd4j.linalg.activations.Activation;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.api.ops.random.impl.BernoulliDistribution;
|
|
||||||
import org.nd4j.linalg.dataset.api.DataSet;
|
import org.nd4j.linalg.dataset.api.DataSet;
|
||||||
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
||||||
import org.nd4j.linalg.dataset.api.preprocessor.NormalizerStandardize;
|
import org.nd4j.linalg.dataset.api.preprocessor.NormalizerStandardize;
|
||||||
import org.nd4j.linalg.factory.Nd4j;
|
import org.nd4j.linalg.factory.Nd4j;
|
||||||
import org.nd4j.linalg.indexing.NDArrayIndex;
|
|
||||||
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -86,7 +82,7 @@ public class ROCTest extends BaseDL4JTest {
|
||||||
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
DataSetIterator iter = new IrisDataSetIterator(150, 150);
|
||||||
|
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).seed(12345)
|
||||||
.list()
|
.list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build()).layer(1,
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(4).activation(Activation.TANH).build()).layer(1,
|
||||||
new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
|
new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
|
||||||
|
|
|
@ -23,7 +23,6 @@ package org.deeplearning4j.eval;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.datasets.iterator.ExistingDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.ExistingDataSetIterator;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
import org.deeplearning4j.nn.graph.ComputationGraph;
|
import org.deeplearning4j.nn.graph.ComputationGraph;
|
||||||
|
@ -49,7 +48,7 @@ public class RegressionEvalTest extends BaseDL4JTest {
|
||||||
public void testRegressionEvalMethods() {
|
public void testRegressionEvalMethods() {
|
||||||
|
|
||||||
//Basic sanity check
|
//Basic sanity check
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.ZERO).list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.ZERO).list()
|
||||||
.layer(0, new OutputLayer.Builder().activation(Activation.TANH)
|
.layer(0, new OutputLayer.Builder().activation(Activation.TANH)
|
||||||
.lossFunction(LossFunctions.LossFunction.MSE).nIn(10).nOut(5).build())
|
.lossFunction(LossFunctions.LossFunction.MSE).nIn(10).nOut(5).build())
|
||||||
.build();
|
.build();
|
||||||
|
@ -71,7 +70,7 @@ public class RegressionEvalTest extends BaseDL4JTest {
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration graphConf =
|
ComputationGraphConfiguration graphConf =
|
||||||
new NeuralNetConfiguration.Builder().weightInit(WeightInit.ZERO).graphBuilder()
|
NeuralNetConfiguration.builder().weightInit(WeightInit.ZERO).graphBuilder()
|
||||||
.addInputs("in").addLayer("0", new OutputLayer.Builder()
|
.addInputs("in").addLayer("0", new OutputLayer.Builder()
|
||||||
.lossFunction(LossFunctions.LossFunction.MSE)
|
.lossFunction(LossFunctions.LossFunction.MSE)
|
||||||
.activation(Activation.TANH).nIn(10).nOut(5).build(), "in")
|
.activation(Activation.TANH).nIn(10).nOut(5).build(), "in")
|
||||||
|
|
|
@ -24,7 +24,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.exception.DL4JException;
|
import org.deeplearning4j.exception.DL4JException;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.*;
|
||||||
|
@ -41,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||||
public class TestInvalidConfigurations extends BaseDL4JTest {
|
public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
|
|
||||||
public static MultiLayerNetwork getDensePlusOutput(int nIn, int nOut) {
|
public static MultiLayerNetwork getDensePlusOutput(int nIn, int nOut) {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(10).build())
|
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(10).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(10).nOut(nOut).build()).build();
|
.layer(1, new OutputLayer.Builder().nIn(10).nOut(nOut).build()).build();
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiLayerNetwork getLSTMPlusRnnOutput(int nIn, int nOut) {
|
public static MultiLayerNetwork getLSTMPlusRnnOutput(int nIn, int nOut) {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new GravesLSTM.Builder().nIn(nIn).nOut(10).build())
|
.layer(0, new GravesLSTM.Builder().nIn(nIn).nOut(10).build())
|
||||||
.layer(1, new RnnOutputLayer.Builder().nIn(10).nOut(nOut).build()).build();
|
.layer(1, new RnnOutputLayer.Builder().nIn(10).nOut(nOut).build()).build();
|
||||||
|
|
||||||
|
@ -63,10 +62,10 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiLayerNetwork getCnnPlusOutputLayer(int depthIn, int inH, int inW, int nOut) {
|
public static MultiLayerNetwork getCnnPlusOutputLayer(int depthIn, int inH, int inW, int nOut) {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().nIn(depthIn).nOut(5).build())
|
.layer(0, new ConvolutionLayer.Builder().nIn(depthIn).nOut(5).build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(nOut).build())
|
.layer(1, new OutputLayer.Builder().nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(inH, inW, depthIn)).build();
|
.inputType(InputType.convolutional(inH, inW, depthIn)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -90,7 +89,7 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDenseNout0() {
|
public void testDenseNout0() {
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(0).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(0).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build()).build();
|
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build()).build();
|
||||||
|
|
||||||
|
@ -147,7 +146,7 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testLSTMNOut0() {
|
public void testLSTMNOut0() {
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new GravesLSTM.Builder().nIn(10).nOut(0).build())
|
.layer(0, new GravesLSTM.Builder().nIn(10).nOut(0).build())
|
||||||
.layer(1, new RnnOutputLayer.Builder().nIn(10).nOut(10).build()).build();
|
.layer(1, new RnnOutputLayer.Builder().nIn(10).nOut(10).build()).build();
|
||||||
|
|
||||||
|
@ -178,10 +177,10 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testConvolutionalNOut0() {
|
public void testConvolutionalNOut0() {
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().nIn(5).nOut(0).build())
|
.layer(0, new ConvolutionLayer.Builder().nIn(5).nOut(0).build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
||||||
.setInputType(InputType.convolutional(10, 10, 5)).build();
|
.inputType(InputType.convolutional(10, 10, 5)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -207,12 +206,12 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
//(10-3+2*0)/2+1 = 7/2 + 1
|
//(10-3+2*0)/2+1 = 7/2 + 1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict)
|
||||||
.list()
|
.list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().kernelSize(3, 2).stride(2, 2).padding(0, 0).nOut(5)
|
.layer(0, new ConvolutionLayer.Builder().kernelSize(3, 2).stride(2, 2).padding(0, 0).nOut(5)
|
||||||
.build())
|
.build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
||||||
.setInputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
.inputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -234,11 +233,11 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
int hIn = 10;
|
int hIn = 10;
|
||||||
int wIn = 10;
|
int wIn = 10;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().kernelSize(7, 7).stride(1, 1).padding(0, 0).nOut(5)
|
.layer(0, new ConvolutionLayer.Builder().kernelSize(7, 7).stride(1, 1).padding(0, 0).nOut(5)
|
||||||
.build())
|
.build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
.setInputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
.inputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -265,8 +264,8 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
|
|
||||||
//Invalid: (10-3+0)/2+1 = 4.5
|
//Invalid: (10-3+0)/2+1 = 4.5
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict).list()
|
NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict).list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().kernelSize(3, 3).stride(2, 2)
|
.layer(0, new ConvolutionLayer.Builder().kernelSize(3, 3).stride(2, 2)
|
||||||
.padding(0, 0).nIn(depthIn).nOut(5).build())
|
.padding(0, 0).nIn(depthIn).nOut(5).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(5 * 4 * 4).nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(1, new OutputLayer.Builder().nIn(5 * 4 * 4).nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
|
@ -299,22 +298,22 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
//(10-3+2*0)/2+1 = 7/2 + 1
|
//(10-3+2*0)/2+1 = 7/2 + 1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0).nOut(5)
|
.layer(0, new ConvolutionLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0).nOut(5)
|
||||||
.build())
|
.build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
.setInputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
.inputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Did not expect exception with default (truncate)");
|
fail("Did not expect exception with default (truncate)");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict)
|
||||||
.list()
|
.list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0).nOut(5)
|
.layer(0, new ConvolutionLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0).nOut(5)
|
||||||
.build())
|
.build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
||||||
.setInputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
.inputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -338,12 +337,12 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
|
||||||
//(10-3+2*0)/2+1 = 7/2 + 1
|
//(10-3+2*0)/2+1 = 7/2 + 1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict)
|
||||||
.list()
|
.list()
|
||||||
.layer(0, new SubsamplingLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0)
|
.layer(0, new SubsamplingLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0)
|
||||||
.build())
|
.build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).build())
|
||||||
.setInputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
.inputType(InputType.convolutional(hIn, wIn, depthIn)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
|
|
@ -23,7 +23,6 @@ package org.deeplearning4j.exceptions;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.exception.DL4JException;
|
import org.deeplearning4j.exception.DL4JException;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.*;
|
||||||
|
@ -43,7 +42,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInputNinMismatchDense() {
|
public void testInputNinMismatchDense() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
|
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLabelsNOutMismatchOutputLayer() {
|
public void testLabelsNOutMismatchOutputLayer() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
|
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLabelsNOutMismatchRnnOutputLayer() {
|
public void testLabelsNOutMismatchRnnOutputLayer() {
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new LSTM.Builder().nIn(5).nOut(5).build())
|
.layer(0, new LSTM.Builder().nIn(5).nOut(5).build())
|
||||||
.layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
.layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
@ -112,10 +111,10 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
int w = 16;
|
int w = 16;
|
||||||
int d = 3;
|
int d = 3;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).build())
|
.layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
.setInputType(InputType.convolutional(h, w, d)).build();
|
.inputType(InputType.convolutional(h, w, d)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -139,10 +138,10 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
int w = 16;
|
int w = 16;
|
||||||
int d = 3;
|
int d = 3;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).build())
|
.layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
.setInputType(InputType.convolutional(h, w, d)).build();
|
.inputType(InputType.convolutional(h, w, d)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -165,10 +164,10 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
int w = 16;
|
int w = 16;
|
||||||
int d = 3;
|
int d = 3;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new SubsamplingLayer.Builder().kernelSize(2, 2).build())
|
.layer(0, new SubsamplingLayer.Builder().kernelSize(2, 2).build())
|
||||||
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
.layer(1, new OutputLayer.Builder().nOut(10).activation(Activation.SOFTMAX).build())
|
||||||
.setInputType(InputType.convolutional(h, w, d)).build();
|
.inputType(InputType.convolutional(h, w, d)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -188,7 +187,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testInputNinMismatchLSTM() {
|
public void testInputNinMismatchLSTM() {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new GravesLSTM.Builder().nIn(5).nOut(5).build())
|
.layer(0, new GravesLSTM.Builder().nIn(5).nOut(5).build())
|
||||||
.layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
.layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
@ -209,7 +208,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testInputNinMismatchBidirectionalLSTM() {
|
public void testInputNinMismatchBidirectionalLSTM() {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new GravesBidirectionalLSTM.Builder().nIn(5).nOut(5).build())
|
.layer(0, new GravesBidirectionalLSTM.Builder().nIn(5).nOut(5).build())
|
||||||
.layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
.layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
@ -231,7 +230,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
@Test
|
@Test
|
||||||
public void testInputNinMismatchEmbeddingLayer() {
|
public void testInputNinMismatchEmbeddingLayer() {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(0, new EmbeddingLayer.Builder().nIn(10).nOut(10).build())
|
.layer(0, new EmbeddingLayer.Builder().nIn(10).nOut(10).build())
|
||||||
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
|
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
@ -257,7 +256,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
|
|
||||||
for(String layerType : new String[]{"simple", "lstm", "graves"}) {
|
for(String layerType : new String[]{"simple", "lstm", "graves"}) {
|
||||||
|
|
||||||
Layer l;
|
LayerConfiguration l;
|
||||||
switch (layerType){
|
switch (layerType){
|
||||||
case "simple":
|
case "simple":
|
||||||
l = new SimpleRnn.Builder().nIn(5).nOut(5).build();
|
l = new SimpleRnn.Builder().nIn(5).nOut(5).build();
|
||||||
|
@ -272,7 +271,7 @@ public class TestInvalidInput extends BaseDL4JTest {
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
|
||||||
.layer(l)
|
.layer(l)
|
||||||
.layer(new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
.layer(new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ package org.deeplearning4j.gradientcheck;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.TestUtils;
|
import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.graph.AttentionVertex;
|
import org.deeplearning4j.nn.conf.graph.AttentionVertex;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
|
@ -84,7 +83,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
System.out.println("Starting test: " + name);
|
System.out.println("Starting test: " + name);
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -98,7 +97,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.setInputType(InputType.recurrent(nIn))
|
.inputType(InputType.recurrent(nIn))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -145,7 +144,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
System.out.println("Starting test: " + name);
|
System.out.println("Starting test: " + name);
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -159,7 +158,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.setInputType(InputType.recurrent(nIn))
|
.inputType(InputType.recurrent(nIn))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -185,7 +184,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
for (boolean inputMask : new boolean[]{false, true}) {
|
for (boolean inputMask : new boolean[]{false, true}) {
|
||||||
for (boolean projectInput : new boolean[]{false, true}) {
|
for (boolean projectInput : new boolean[]{false, true}) {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -199,7 +198,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.setInputType(InputType.recurrent(nIn))
|
.inputType(InputType.recurrent(nIn))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -240,7 +239,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
int nOut = 5;
|
int nOut = 5;
|
||||||
int layerSize = 8;
|
int layerSize = 8;
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.IDENTITY)
|
.activation(Activation.IDENTITY)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -251,7 +250,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.setInputType(InputType.recurrent(nIn))
|
.inputType(InputType.recurrent(nIn))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -303,7 +302,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
System.out.println("Starting test: " + name);
|
System.out.println("Starting test: " + name);
|
||||||
|
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.IDENTITY)
|
.activation(Activation.IDENTITY)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -314,7 +313,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
|
||||||
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
|
||||||
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
|
||||||
.setInputType(InputType.recurrent(nIn))
|
.inputType(InputType.recurrent(nIn))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -361,7 +360,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
System.out.println("Starting test: " + name);
|
System.out.println("Starting test: " + name);
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration graph = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration graph = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -425,7 +424,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
|
||||||
System.out.println("Starting test: " + name);
|
System.out.println("Starting test: " + name);
|
||||||
|
|
||||||
|
|
||||||
ComputationGraphConfiguration graph = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration graph = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
|
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
|
||||||
|
@ -74,23 +73,23 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
|
|
||||||
for (boolean useLogStd : new boolean[]{true, false}) {
|
for (boolean useLogStd : new boolean[]{true, false}) {
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder =
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder =
|
||||||
new NeuralNetConfiguration.Builder().updater(new NoOp())
|
NeuralNetConfiguration.builder().updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.seed(12345L)
|
.seed(12345L)
|
||||||
.dist(new NormalDistribution(0, 1)).list()
|
.dist(new NormalDistribution(0, 1)).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(4).nOut(3)
|
.layer(0, new DenseLayer.Builder().nIn(4).nOut(3)
|
||||||
.activation(Activation.IDENTITY).build())
|
.activation(Activation.IDENTITY).build())
|
||||||
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).nOut(3).build())
|
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).nOut(3).build())
|
||||||
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
|
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(3).nOut(3).build());
|
.activation(Activation.SOFTMAX).nIn(3).nOut(3).build());
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
|
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
|
||||||
mln.init();
|
mln.init();
|
||||||
|
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
@ -119,7 +118,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (boolean useLogStd : new boolean[]{true, false}) {
|
for (boolean useLogStd : new boolean[]{true, false}) {
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp()).seed(12345L)
|
.updater(new NoOp()).seed(12345L)
|
||||||
.dist(new NormalDistribution(0, 2)).list()
|
.dist(new NormalDistribution(0, 2)).list()
|
||||||
|
@ -129,13 +128,13 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
|
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(hw, hw, depth));
|
.inputType(InputType.convolutional(hw, hw, depth));
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
|
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
|
||||||
mln.init();
|
mln.init();
|
||||||
|
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
@ -188,7 +187,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
LossFunctions.LossFunction lf = lossFunctions[i];
|
LossFunctions.LossFunction lf = lossFunctions[i];
|
||||||
Activation outputActivation = outputActivations[i];
|
Activation outputActivation = outputActivations[i];
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.l2(l2vals[j])
|
.l2(l2vals[j])
|
||||||
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
|
||||||
|
@ -203,9 +202,9 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(4, new ActivationLayer.Builder().activation(afn).build())
|
.layer(4, new ActivationLayer.Builder().activation(afn).build())
|
||||||
.layer(5, new OutputLayer.Builder(lf).activation(outputActivation).nOut(nOut)
|
.layer(5, new OutputLayer.Builder(lf).activation(outputActivation).nOut(nOut)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutional(hw, hw, depth));
|
.inputType(InputType.convolutional(hw, hw, depth));
|
||||||
|
|
||||||
MultiLayerConfiguration conf = builder.build();
|
NeuralNetConfiguration conf = builder.build();
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -219,11 +218,11 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
mln.setInput(ds.getFeatures());
|
mln.setInput(ds.getFeatures());
|
||||||
mln.setLabels(ds.getLabels());
|
mln.setLabels(ds.getLabels());
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreBefore = mln.score();
|
double scoreBefore = mln.getScore();
|
||||||
for (int k = 0; k < 20; k++)
|
for (int k = 0; k < 20; k++)
|
||||||
mln.fit(ds);
|
mln.fit(ds);
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreAfter = mln.score();
|
double scoreAfter = mln.getScore();
|
||||||
//Can't test in 'characteristic mode of operation' if not learning
|
//Can't test in 'characteristic mode of operation' if not learning
|
||||||
String msg = name
|
String msg = name
|
||||||
+ " - score did not (sufficiently) decrease during learning - activationFn="
|
+ " - score did not (sufficiently) decrease during learning - activationFn="
|
||||||
|
@ -237,7 +236,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
||||||
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
|
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
|
||||||
// for (int k = 0; k < mln.getnLayers(); k++)
|
// for (int k = 0; k < mln.getnLayers(); k++)
|
||||||
// System.out.println("Layer " + k + " # params: " + mln.getLayer(k).numParams());
|
// System.out.println("ILayer " + k + " # params: " + mln.getLayer(k).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
@ -294,23 +293,23 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
LossFunctions.LossFunction lf = lossFunctions[i];
|
LossFunctions.LossFunction lf = lossFunctions[i];
|
||||||
Activation outputActivation = outputActivations[i];
|
Activation outputActivation = outputActivations[i];
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder =
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder =
|
||||||
new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.l2(l2vals[j])
|
.l2(l2vals[j])
|
||||||
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
|
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new UniformDistribution(-2, 2)).seed(12345L).list()
|
.dist(new UniformDistribution(-2, 2)).seed(12345L).list()
|
||||||
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(4)
|
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(4)
|
||||||
.activation(afn).build())
|
.activation(afn).build())
|
||||||
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).build())
|
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).build())
|
||||||
.layer(2, new DenseLayer.Builder().nIn(4).nOut(4).build())
|
.layer(2, new DenseLayer.Builder().nIn(4).nOut(4).build())
|
||||||
.layer(3, new BatchNormalization.Builder().useLogStd(useLogStd).build())
|
.layer(3, new BatchNormalization.Builder().useLogStd(useLogStd).build())
|
||||||
.layer(4, new OutputLayer.Builder(lf)
|
.layer(4, new OutputLayer.Builder(lf)
|
||||||
.activation(outputActivation).nOut(nOut)
|
.activation(outputActivation).nOut(nOut)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
MultiLayerConfiguration conf = builder.build();
|
NeuralNetConfiguration conf = builder.build();
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -323,11 +322,11 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
mln.setInput(ds.getFeatures());
|
mln.setInput(ds.getFeatures());
|
||||||
mln.setLabels(ds.getLabels());
|
mln.setLabels(ds.getLabels());
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreBefore = mln.score();
|
double scoreBefore = mln.getScore();
|
||||||
for (int k = 0; k < 10; k++)
|
for (int k = 0; k < 10; k++)
|
||||||
mln.fit(ds);
|
mln.fit(ds);
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreAfter = mln.score();
|
double scoreAfter = mln.getScore();
|
||||||
//Can't test in 'characteristic mode of operation' if not learning
|
//Can't test in 'characteristic mode of operation' if not learning
|
||||||
String msg = name
|
String msg = name
|
||||||
+ " - score did not (sufficiently) decrease during learning - activationFn="
|
+ " - score did not (sufficiently) decrease during learning - activationFn="
|
||||||
|
@ -341,7 +340,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
||||||
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
|
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
|
||||||
// for (int k = 0; k < mln.getnLayers(); k++)
|
// for (int k = 0; k < mln.getnLayers(); k++)
|
||||||
// System.out.println("Layer " + k + " # params: " + mln.getLayer(k).numParams());
|
// System.out.println("ILayer " + k + " # params: " + mln.getLayer(k).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
@ -370,7 +369,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
INDArray labels = ds.getLabels();
|
INDArray labels = ds.getLabels();
|
||||||
|
|
||||||
for (boolean useLogStd : new boolean[]{true, false}) {
|
for (boolean useLogStd : new boolean[]{true, false}) {
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().updater(new NoOp())
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.seed(12345L)
|
.seed(12345L)
|
||||||
.dist(new NormalDistribution(0, 1)).list()
|
.dist(new NormalDistribution(0, 1)).list()
|
||||||
|
@ -385,7 +384,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
mln.init();
|
mln.init();
|
||||||
|
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
@ -414,7 +413,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (boolean useLogStd : new boolean[]{true, false}) {
|
for (boolean useLogStd : new boolean[]{true, false}) {
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().updater(new NoOp())
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.seed(12345L)
|
.seed(12345L)
|
||||||
.dist(new NormalDistribution(0, 2)).list()
|
.dist(new NormalDistribution(0, 2)).list()
|
||||||
|
@ -424,13 +423,13 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
|
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(hw, hw, depth));
|
.inputType(InputType.convolutional(hw, hw, depth));
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
|
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
|
||||||
mln.init();
|
mln.init();
|
||||||
|
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
@ -457,7 +456,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
|
|
||||||
for (boolean useLogStd : new boolean[]{true, false}) {
|
for (boolean useLogStd : new boolean[]{true, false}) {
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(seed).updater(new NoOp())
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(seed).updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
|
||||||
.setInputTypes(InputType.convolutional(height, width, channels))
|
.setInputTypes(InputType.convolutional(height, width, channels))
|
||||||
|
@ -526,7 +525,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
LossFunctions.LossFunction lf = lossFunctions[i];
|
LossFunctions.LossFunction lf = lossFunctions[i];
|
||||||
Activation outputActivation = outputActivations[i];
|
Activation outputActivation = outputActivations[i];
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
|
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
|
@ -554,11 +553,11 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
net.setInput(0, ds.getFeatures());
|
net.setInput(0, ds.getFeatures());
|
||||||
net.setLabels(ds.getLabels());
|
net.setLabels(ds.getLabels());
|
||||||
net.computeGradientAndScore();
|
net.computeGradientAndScore();
|
||||||
double scoreBefore = net.score();
|
double scoreBefore = net.getScore();
|
||||||
for (int k = 0; k < 20; k++)
|
for (int k = 0; k < 20; k++)
|
||||||
net.fit(ds);
|
net.fit(ds);
|
||||||
net.computeGradientAndScore();
|
net.computeGradientAndScore();
|
||||||
double scoreAfter = net.score();
|
double scoreAfter = net.getScore();
|
||||||
//Can't test in 'characteristic mode of operation' if not learning
|
//Can't test in 'characteristic mode of operation' if not learning
|
||||||
String msg = name
|
String msg = name
|
||||||
+ " - score did not (sufficiently) decrease during learning - activationFn="
|
+ " - score did not (sufficiently) decrease during learning - activationFn="
|
||||||
|
@ -572,7 +571,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
|
||||||
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
||||||
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
|
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
|
||||||
// for (int k = 0; k < net.getNumLayers(); k++)
|
// for (int k = 0; k < net.getNumLayers(); k++)
|
||||||
// System.out.println("Layer " + k + " # params: " + net.getLayer(k).numParams());
|
// System.out.println("ILayer " + k + " # params: " + net.getLayer(k).numParams());
|
||||||
|
|
||||||
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
//Mean and variance vars are not gradient checkable; mean/variance "gradient" is used to implement running mean/variance calc
|
||||||
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
|
||||||
|
|
|
@ -24,17 +24,14 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.TestUtils;
|
import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.RNNFormat;
|
import org.deeplearning4j.nn.conf.RNNFormat;
|
||||||
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
import org.deeplearning4j.nn.conf.layers.*;
|
import org.deeplearning4j.nn.conf.layers.*;
|
||||||
import org.deeplearning4j.nn.conf.layers.convolutional.Cropping1D;
|
import org.deeplearning4j.nn.conf.layers.convolutional.Cropping1D;
|
||||||
import org.deeplearning4j.nn.modelimport.keras.KerasModelImport;
|
|
||||||
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.util.Convolution1DUtils;
|
import org.deeplearning4j.util.Convolution1DUtils;
|
||||||
import org.deeplearning4j.util.ConvolutionUtils;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.linalg.activations.Activation;
|
import org.nd4j.linalg.activations.Activation;
|
||||||
import org.nd4j.linalg.api.buffer.DataType;
|
import org.nd4j.linalg.api.buffer.DataType;
|
||||||
|
@ -45,8 +42,6 @@ import org.nd4j.linalg.indexing.NDArrayIndex;
|
||||||
import org.nd4j.linalg.learning.config.NoOp;
|
import org.nd4j.linalg.learning.config.NoOp;
|
||||||
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ -90,7 +85,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
||||||
|
@ -103,10 +98,10 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.recurrent(convNIn, length)).build();
|
.inputType(InputType.recurrent(convNIn, length)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -118,7 +113,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -170,7 +165,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
||||||
|
@ -183,10 +178,10 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
.inputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -198,7 +193,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -251,7 +246,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
||||||
|
@ -267,10 +262,10 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
.stride(stride).padding(padding).pnorm(pnorm).build())
|
.stride(stride).padding(padding).pnorm(pnorm).build())
|
||||||
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
.inputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -282,7 +277,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -330,7 +325,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
|
||||||
|
@ -344,10 +339,10 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
.stride(stride).padding(padding).pnorm(pnorm).build())
|
.stride(stride).padding(padding).pnorm(pnorm).build())
|
||||||
.layer(3, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
.inputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -359,7 +354,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -393,7 +388,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
log.info("Starting test: " + s);
|
log.info("Starting test: " + s);
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
|
@ -413,7 +408,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(new GlobalPoolingLayer(PoolingType.AVG))
|
.layer(new GlobalPoolingLayer(PoolingType.AVG))
|
||||||
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.recurrent(convNIn, length)).build();
|
.inputType(InputType.recurrent(convNIn, length)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -481,7 +476,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
log.info("Starting test: " + s);
|
log.info("Starting test: " + s);
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
|
@ -501,7 +496,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
.inputType(InputType.recurrent(convNIn, length,RNNFormat.NCW)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
|
|
@ -24,7 +24,6 @@ import lombok.extern.java.Log;
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.TestUtils;
|
import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
|
@ -35,7 +34,6 @@ import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
import org.deeplearning4j.nn.weights.WeightInit;
|
import org.deeplearning4j.nn.weights.WeightInit;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.nd4j.linalg.activations.Activation;
|
import org.nd4j.linalg.activations.Activation;
|
||||||
import org.nd4j.linalg.api.buffer.DataBuffer;
|
|
||||||
import org.nd4j.linalg.api.buffer.DataType;
|
import org.nd4j.linalg.api.buffer.DataType;
|
||||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
import org.nd4j.linalg.factory.Nd4j;
|
import org.nd4j.linalg.factory.Nd4j;
|
||||||
|
@ -112,7 +110,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
|
@ -131,10 +129,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
.inputPreProcessor(2,
|
.inputPreProcessor(2,
|
||||||
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
||||||
convNOut2, df == Convolution3D.DataFormat.NCDHW))
|
convNOut2, df == Convolution3D.DataFormat.NCDHW))
|
||||||
.setInputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
.inputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -149,7 +147,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
log.info(msg);
|
log.info(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++) {
|
// for (int j = 0; j < net.getnLayers(); j++) {
|
||||||
// log.info("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// log.info("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +213,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
|
@ -235,10 +233,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
.inputPreProcessor(3,
|
.inputPreProcessor(3,
|
||||||
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
||||||
convNOut2, true))
|
convNOut2, true))
|
||||||
.setInputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
|
.inputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -252,7 +250,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
log.info(msg);
|
log.info(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++) {
|
// for (int j = 0; j < net.getnLayers(); j++) {
|
||||||
// log.info("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// log.info("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +308,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.weightInit(WeightInit.XAVIER)
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
@ -327,10 +325,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.inputPreProcessor(2,
|
.inputPreProcessor(2,
|
||||||
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,convNOut, df))
|
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,convNOut, df))
|
||||||
.setInputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
.inputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -397,7 +395,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
|
@ -414,10 +412,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
.inputPreProcessor(2,
|
.inputPreProcessor(2,
|
||||||
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
||||||
convNOut, true))
|
convNOut, true))
|
||||||
.setInputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
.inputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -431,7 +429,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
log.info(msg);
|
log.info(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++) {
|
// for (int j = 0; j < net.getnLayers(); j++) {
|
||||||
// log.info("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// log.info("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +491,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
|
@ -513,10 +511,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
.inputPreProcessor(3,
|
.inputPreProcessor(3,
|
||||||
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
|
||||||
convNOut2, true))
|
convNOut2, true))
|
||||||
.setInputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
|
.inputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -530,7 +528,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
log.info(msg);
|
log.info(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++) {
|
// for (int j = 0; j < net.getnLayers(); j++) {
|
||||||
// log.info("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// log.info("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +590,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{j, j % finalNOut}, 1.0);
|
labels.putScalar(new int[]{j, j % finalNOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.weightInit(new NormalDistribution(0, 0.1))
|
.weightInit(new NormalDistribution(0, 0.1))
|
||||||
|
@ -607,10 +605,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
|
||||||
.setInputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
.inputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
|
||||||
|
|
||||||
String json = conf.toJson();
|
String json = conf.toJson();
|
||||||
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
|
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
|
||||||
assertEquals(conf, c2);
|
assertEquals(conf, c2);
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
|
||||||
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
|
||||||
import org.deeplearning4j.nn.conf.CNN2DFormat;
|
import org.deeplearning4j.nn.conf.CNN2DFormat;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
|
@ -100,15 +99,15 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
LossFunctions.LossFunction lf = lossFunctions[i];
|
LossFunctions.LossFunction lf = lossFunctions[i];
|
||||||
Activation outputActivation = outputActivations[i];
|
Activation outputActivation = outputActivations[i];
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).updater(new NoOp())
|
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).updater(new NoOp())
|
||||||
.weightInit(WeightInit.XAVIER).seed(12345L).list()
|
.weightInit(WeightInit.XAVIER).seed(12345L).list()
|
||||||
.layer(0, new ConvolutionLayer.Builder(1, 1).nOut(6).activation(afn).build())
|
.layer(0, new ConvolutionLayer.Builder(1, 1).nOut(6).activation(afn).build())
|
||||||
.layer(1, new OutputLayer.Builder(lf).activation(outputActivation).nOut(3).build())
|
.layer(1, new OutputLayer.Builder(lf).activation(outputActivation).nOut(3).build())
|
||||||
.setInputType(InputType.convolutionalFlat(1, 4, 1));
|
.inputType(InputType.convolutionalFlat(1, 4, 1));
|
||||||
|
|
||||||
MultiLayerConfiguration conf = builder.build();
|
NeuralNetConfiguration conf = builder.build();
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -120,11 +119,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
mln.setInput(ds.getFeatures());
|
mln.setInput(ds.getFeatures());
|
||||||
mln.setLabels(ds.getLabels());
|
mln.setLabels(ds.getLabels());
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreBefore = mln.score();
|
double scoreBefore = mln.getScore();
|
||||||
for (int j = 0; j < 10; j++)
|
for (int j = 0; j < 10; j++)
|
||||||
mln.fit(ds);
|
mln.fit(ds);
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreAfter = mln.score();
|
double scoreAfter = mln.getScore();
|
||||||
//Can't test in 'characteristic mode of operation' if not learning
|
//Can't test in 'characteristic mode of operation' if not learning
|
||||||
String msg = name + " - score did not (sufficiently) decrease during learning - activationFn="
|
String msg = name + " - score did not (sufficiently) decrease during learning - activationFn="
|
||||||
+ afn + ", lossFn=" + lf + ", outputActivation=" + outputActivation
|
+ afn + ", lossFn=" + lf + ", outputActivation=" + outputActivation
|
||||||
|
@ -137,7 +136,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
System.out.println(name + " - activationFn=" + afn + ", lossFn=" + lf + ", outputActivation="
|
System.out.println(name + " - activationFn=" + afn + ", lossFn=" + lf + ", outputActivation="
|
||||||
+ outputActivation + ", doLearningFirst=" + doLearningFirst);
|
+ outputActivation + ", doLearningFirst=" + doLearningFirst);
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -186,7 +185,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
double l2 = l2vals[i];
|
double l2 = l2vals[i];
|
||||||
double l1 = l1vals[i];
|
double l1 = l1vals[i];
|
||||||
|
|
||||||
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.l2(l2).l1(l1).l2Bias(biasL2[i]).l1Bias(biasL1[i])
|
.l2(l2).l1(l1).l2Bias(biasL2[i]).l1Bias(biasL1[i])
|
||||||
.optimizationAlgo(
|
.optimizationAlgo(
|
||||||
|
@ -198,9 +197,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(1, new OutputLayer.Builder(lf).activation(outputActivation).nOut(3)
|
.layer(1, new OutputLayer.Builder(lf).activation(outputActivation).nOut(3)
|
||||||
.weightInit(WeightInit.XAVIER).updater(new NoOp()).build())
|
.weightInit(WeightInit.XAVIER).updater(new NoOp()).build())
|
||||||
|
|
||||||
.setInputType(InputType.convolutionalFlat(1, 4, 1));
|
.inputType(InputType.convolutionalFlat(1, 4, 1));
|
||||||
|
|
||||||
MultiLayerConfiguration conf = builder.build();
|
NeuralNetConfiguration conf = builder.build();
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -212,11 +211,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
mln.setInput(ds.getFeatures());
|
mln.setInput(ds.getFeatures());
|
||||||
mln.setLabels(ds.getLabels());
|
mln.setLabels(ds.getLabels());
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreBefore = mln.score();
|
double scoreBefore = mln.getScore();
|
||||||
for (int j = 0; j < 10; j++)
|
for (int j = 0; j < 10; j++)
|
||||||
mln.fit(ds);
|
mln.fit(ds);
|
||||||
mln.computeGradientAndScore();
|
mln.computeGradientAndScore();
|
||||||
double scoreAfter = mln.score();
|
double scoreAfter = mln.getScore();
|
||||||
//Can't test in 'characteristic mode of operation' if not learning
|
//Can't test in 'characteristic mode of operation' if not learning
|
||||||
String msg = testName
|
String msg = testName
|
||||||
+ "- score did not (sufficiently) decrease during learning - activationFn="
|
+ "- score did not (sufficiently) decrease during learning - activationFn="
|
||||||
|
@ -231,7 +230,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
|
||||||
+ doLearningFirst);
|
+ doLearningFirst);
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -269,8 +268,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
|
@ -281,7 +280,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(2 * 2 * 4)
|
.activation(Activation.SOFTMAX).nIn(2 * 2 * 4)
|
||||||
.nOut(nOut).build())
|
.nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutionalFlat(height, width, inputDepth))
|
.inputType(InputType.convolutionalFlat(height, width, inputDepth))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -293,7 +292,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
DEFAULT_MIN_ABS_ERROR, PRINT_RESULTS, RETURN_ON_FIRST_FAILURE, input, labels);
|
DEFAULT_MIN_ABS_ERROR, PRINT_RESULTS, RETURN_ON_FIRST_FAILURE, input, labels);
|
||||||
|
@ -334,8 +333,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp()).weightInit(new NormalDistribution(0, 1))
|
.updater(new NoOp()).weightInit(new NormalDistribution(0, 1))
|
||||||
.list()
|
.list()
|
||||||
|
@ -349,7 +348,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX)
|
.activation(Activation.SOFTMAX)
|
||||||
.nOut(nOut).build())
|
.nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -361,7 +360,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
DEFAULT_MIN_ABS_ERROR, PRINT_RESULTS, RETURN_ON_FIRST_FAILURE, input, labels);
|
DEFAULT_MIN_ABS_ERROR, PRINT_RESULTS, RETURN_ON_FIRST_FAILURE, input, labels);
|
||||||
|
@ -403,8 +402,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
||||||
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
|
@ -416,7 +415,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(8 * 8 * 3)
|
.activation(Activation.SOFTMAX).nIn(8 * 8 * 3)
|
||||||
.nOut(4).build())
|
.nOut(4).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -427,7 +426,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -472,8 +471,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().updater(new NoOp())
|
NeuralNetConfiguration.builder().updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
.list().layer(0,
|
.list().layer(0,
|
||||||
|
@ -488,7 +487,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(3 * 3 * 3)
|
.activation(Activation.SOFTMAX).nIn(3 * 3 * 3)
|
||||||
.nOut(4).build())
|
.nOut(4).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -500,7 +499,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -546,8 +545,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().updater(new NoOp())
|
NeuralNetConfiguration.builder().updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.dist(new NormalDistribution(0, 1))
|
.dist(new NormalDistribution(0, 1))
|
||||||
.list().layer(0,
|
.list().layer(0,
|
||||||
|
@ -562,7 +561,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2)
|
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2)
|
||||||
.nOut(4).build())
|
.nOut(4).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -606,7 +605,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
||||||
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).updater(new NoOp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345).updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(afn)
|
.activation(afn)
|
||||||
.list()
|
.list()
|
||||||
|
@ -623,10 +622,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2).nOut(nOut)
|
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2).nOut(nOut)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format)).build();
|
.inputType(InputType.convolutional(height, width, inputDepth, format)).build();
|
||||||
|
|
||||||
assertEquals(ConvolutionMode.Truncate,
|
assertEquals(ConvolutionMode.Truncate, conf.getConvolutionMode());
|
||||||
((ConvolutionLayer) conf.getConf(0).getLayer()).getConvolutionMode());
|
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -673,7 +671,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).updater(new NoOp())
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345).updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.activation(afn)
|
.activation(afn)
|
||||||
.list()
|
.list()
|
||||||
|
@ -689,10 +687,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2).nOut(nOut)
|
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2).nOut(nOut)
|
||||||
.build())
|
.build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format)).build();
|
.inputType(InputType.convolutional(height, width, inputDepth, format)).build();
|
||||||
|
|
||||||
assertEquals(ConvolutionMode.Truncate,
|
assertEquals(ConvolutionMode.Truncate,conf.getConvolutionMode());
|
||||||
((ConvolutionLayer) conf.getConf(0).getLayer()).getConvolutionMode());
|
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -744,7 +741,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
|
|
||||||
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.SIGMOID).convolutionMode(Same).list()
|
.activation(Activation.SIGMOID).convolutionMode(Same).list()
|
||||||
|
@ -760,7 +757,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.stride(1, 1).padding(0, 0).build())
|
.stride(1, 1).padding(0, 0).build())
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format)).build();
|
.inputType(InputType.convolutional(height, width, inputDepth, format)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -810,14 +807,14 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer convLayer = new ConvolutionLayer.Builder().name("layer 0").kernelSize(k, k).dataFormat(format)
|
LayerConfiguration convLayer = new ConvolutionLayer.Builder().name("layer 0").kernelSize(k, k).dataFormat(format)
|
||||||
.stride(stride, stride).padding(0, 0).nIn(inputDepth).nOut(2).build();
|
.stride(stride, stride).padding(0, 0).nIn(inputDepth).nOut(2).build();
|
||||||
|
|
||||||
Layer poolLayer = new SubsamplingLayer.Builder()
|
LayerConfiguration poolLayer = new SubsamplingLayer.Builder()
|
||||||
.poolingType(SubsamplingLayer.PoolingType.MAX).kernelSize(k, k).dataFormat(format)
|
.poolingType(SubsamplingLayer.PoolingType.MAX).kernelSize(k, k).dataFormat(format)
|
||||||
.stride(stride, stride).padding(0, 0).build();
|
.stride(stride, stride).padding(0, 0).build();
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.TANH).convolutionMode(Same).list()
|
.activation(Activation.TANH).convolutionMode(Same).list()
|
||||||
|
@ -825,7 +822,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(1, convFirst ? poolLayer : convLayer)
|
.layer(1, convFirst ? poolLayer : convLayer)
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -883,8 +880,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
||||||
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder().updater(new NoOp())
|
NeuralNetConfiguration.builder().updater(new NoOp())
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.dist(new NormalDistribution(0, 1)).list()
|
.dist(new NormalDistribution(0, 1)).list()
|
||||||
.layer(0, new ConvolutionLayer.Builder(kernel, stride, padding).dataFormat(format)
|
.layer(0, new ConvolutionLayer.Builder(kernel, stride, padding).dataFormat(format)
|
||||||
|
@ -894,7 +891,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
padding).nIn(3).nOut(3).dataFormat(format).build())//output: (6-2+0)/1+1 = 5
|
padding).nIn(3).nOut(3).dataFormat(format).build())//output: (6-2+0)/1+1 = 5
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(4).build())
|
.activation(Activation.SOFTMAX).nOut(4).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -920,7 +917,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
// for (int j = 0; j < net.getnLayers(); j++)
|
// for (int j = 0; j < net.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + net.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + net.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(net, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -971,7 +968,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{j, j % nOut}, 1.0);
|
labels.putScalar(new int[]{j, j % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder b = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(act)
|
.activation(act)
|
||||||
|
@ -981,11 +978,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.stride(s, s).dataFormat(format)
|
.stride(s, s).dataFormat(format)
|
||||||
.dilation(d, d)
|
.dilation(d, d)
|
||||||
.convolutionMode(cm)
|
.convolutionMode(cm)
|
||||||
.nIn(inputDepth).nOut(nOut).build());
|
.nIn(inputDepth).nOut(nOut).build())
|
||||||
|
|
||||||
MultiLayerConfiguration conf = b.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(h, w, inputDepth, format)).build();
|
.inputType(InputType.convolutional(h, w, inputDepth, format)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -1043,7 +1040,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder b = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
|
@ -1054,11 +1051,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.stride(s, s)
|
.stride(s, s)
|
||||||
.dilation(d, d)
|
.dilation(d, d)
|
||||||
.depthMultiplier(3).dataFormat(format)
|
.depthMultiplier(3).dataFormat(format)
|
||||||
.nIn(inputDepth).nOut(2).build());
|
.nIn(inputDepth).nOut(2).build())
|
||||||
|
|
||||||
MultiLayerConfiguration conf = b.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(h, w, inputDepth, format)).build();
|
.inputType(InputType.convolutional(h, w, inputDepth, format)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -1116,7 +1113,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder b = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder b = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.TANH).convolutionMode(cm).list()
|
.activation(Activation.TANH).convolutionMode(cm).list()
|
||||||
|
@ -1140,9 +1137,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = b.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
NeuralNetConfiguration conf = (NeuralNetConfiguration) b.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(h, w, inputDepth, format)).build();
|
.inputType(InputType.convolutional(h, w, inputDepth, format)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
@ -1190,8 +1187,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
|
||||||
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
|
||||||
|
|
||||||
MultiLayerConfiguration conf =
|
NeuralNetConfiguration conf =
|
||||||
new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.convolutionMode(ConvolutionMode.Same)
|
.convolutionMode(ConvolutionMode.Same)
|
||||||
|
@ -1208,7 +1205,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.build())
|
.build())
|
||||||
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth, format))
|
.inputType(InputType.convolutional(height, width, inputDepth, format))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
@ -1277,7 +1274,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
labels.putScalar(new int[]{i, i % nOut}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder b = new NeuralNetConfiguration.Builder().seed(12345)
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder b = NeuralNetConfiguration.builder().seed(12345)
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.activation(Activation.TANH)
|
.activation(Activation.TANH)
|
||||||
|
@ -1293,9 +1290,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
|
||||||
.depthMultiplier(depthMultiplier)
|
.depthMultiplier(depthMultiplier)
|
||||||
.nIn(nIn).build()); // nOut = nIn * depthMultiplier
|
.nIn(nIn).build()); // nOut = nIn * depthMultiplier
|
||||||
|
|
||||||
MultiLayerConfiguration conf = b.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
NeuralNetConfiguration conf = (NeuralNetConfiguration) b.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(height, width, nIn, format)).build();
|
.inputType(InputType.convolutional(height, width, nIn, format)).build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
net.init();
|
net.init();
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.deeplearning4j.BaseDL4JTest;
|
import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.TestUtils;
|
import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
|
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
|
@ -44,8 +43,6 @@ import org.nd4j.linalg.factory.Nd4j;
|
||||||
import org.nd4j.linalg.learning.config.NoOp;
|
import org.nd4j.linalg.learning.config.NoOp;
|
||||||
import org.nd4j.linalg.lossfunctions.impl.LossNegativeLogLikelihood;
|
import org.nd4j.linalg.lossfunctions.impl.LossNegativeLogLikelihood;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
////@Ignore
|
////@Ignore
|
||||||
public class CapsnetGradientCheckTest extends BaseDL4JTest {
|
public class CapsnetGradientCheckTest extends BaseDL4JTest {
|
||||||
|
|
||||||
|
@ -80,12 +77,11 @@ public class CapsnetGradientCheckTest extends BaseDL4JTest {
|
||||||
labels.putScalar(new int[]{i, i % capsule}, 1.0);
|
labels.putScalar(new int[]{i, i % capsule}, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.seed(123)
|
.seed(123)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.weightInit(new WeightInitDistribution(new UniformDistribution(-6, 6)))
|
.dist(new UniformDistribution(-6, 6))
|
||||||
.list()
|
|
||||||
.layer(new PrimaryCapsules.Builder(primaryCapsDim, primarpCapsChannel)
|
.layer(new PrimaryCapsules.Builder(primaryCapsDim, primarpCapsChannel)
|
||||||
.kernelSize(3, 3)
|
.kernelSize(3, 3)
|
||||||
.stride(2, 2)
|
.stride(2, 2)
|
||||||
|
@ -94,7 +90,7 @@ public class CapsnetGradientCheckTest extends BaseDL4JTest {
|
||||||
.layer(new CapsuleStrengthLayer.Builder().build())
|
.layer(new CapsuleStrengthLayer.Builder().build())
|
||||||
.layer(new ActivationLayer.Builder(new ActivationSoftmax()).build())
|
.layer(new ActivationLayer.Builder(new ActivationSoftmax()).build())
|
||||||
.layer(new LossLayer.Builder(new LossNegativeLogLikelihood()).build())
|
.layer(new LossLayer.Builder(new LossNegativeLogLikelihood()).build())
|
||||||
.setInputType(InputType.convolutional(height, width, inputDepth))
|
.inputType(InputType.convolutional(height, width, inputDepth))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
MultiLayerNetwork net = new MultiLayerNetwork(conf);
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.TestUtils;
|
import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.dropout.*;
|
import org.deeplearning4j.nn.conf.dropout.*;
|
||||||
|
@ -92,7 +91,7 @@ public class DropoutGradientCheck extends BaseDL4JTest {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NeuralNetConfiguration.ListBuilder builder = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.dist(new NormalDistribution(0,1))
|
.dist(new NormalDistribution(0,1))
|
||||||
.convolutionMode(ConvolutionMode.Same)
|
.convolutionMode(ConvolutionMode.Same)
|
||||||
|
@ -104,18 +103,18 @@ public class DropoutGradientCheck extends BaseDL4JTest {
|
||||||
if(cnn){
|
if(cnn){
|
||||||
builder.layer(new ConvolutionLayer.Builder().kernelSize(3,3).stride(2,2).nOut(2).build());
|
builder.layer(new ConvolutionLayer.Builder().kernelSize(3,3).stride(2,2).nOut(2).build());
|
||||||
builder.layer(new ConvolutionLayer.Builder().kernelSize(3,3).stride(2,2).nOut(2).build());
|
builder.layer(new ConvolutionLayer.Builder().kernelSize(3,3).stride(2,2).nOut(2).build());
|
||||||
builder.setInputType(InputType.convolutional(6,6,2));
|
builder.inputType(InputType.convolutional(6,6,2));
|
||||||
} else {
|
} else {
|
||||||
builder.layer(new DenseLayer.Builder().nOut(3).build());
|
builder.layer(new DenseLayer.Builder().nOut(3).build());
|
||||||
builder.layer(new DenseLayer.Builder().nOut(3).build());
|
builder.layer(new DenseLayer.Builder().nOut(3).build());
|
||||||
builder.setInputType(InputType.feedForward(6));
|
builder.inputType(InputType.feedForward(6));
|
||||||
}
|
}
|
||||||
builder.layer(new OutputLayer.Builder().nOut(3).activation(Activation.SOFTMAX).lossFunction(LossFunction.MCXENT).build());
|
builder.layer(new OutputLayer.Builder().nOut(3).activation(Activation.SOFTMAX).lossFunction(LossFunction.MCXENT).build());
|
||||||
|
|
||||||
MultiLayerConfiguration conf = builder.build();
|
NeuralNetConfiguration conf = builder.build();
|
||||||
//Remove spatial dropout from output layer - can't be used for 2d input
|
//Remove spatial dropout from output layer - can't be used for 2d input
|
||||||
if(i == 4){
|
if(i == 4){
|
||||||
conf.getConf(2).getLayer().setIDropout(null);
|
conf.getFlattenedLayerConfigurations().get(2).setIDropout(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
|
@ -149,7 +148,7 @@ public class DropoutGradientCheck extends BaseDL4JTest {
|
||||||
Nd4j.getRandom().setSeed(12345);
|
Nd4j.getRandom().setSeed(12345);
|
||||||
int mb = 3;
|
int mb = 3;
|
||||||
|
|
||||||
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
|
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.dist(new NormalDistribution(0,1))
|
.dist(new NormalDistribution(0,1))
|
||||||
.convolutionMode(ConvolutionMode.Same)
|
.convolutionMode(ConvolutionMode.Same)
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.deeplearning4j.BaseDL4JTest;
|
||||||
import org.deeplearning4j.TestUtils;
|
import org.deeplearning4j.TestUtils;
|
||||||
import org.deeplearning4j.nn.conf.CNN2DFormat;
|
import org.deeplearning4j.nn.conf.CNN2DFormat;
|
||||||
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
import org.deeplearning4j.nn.conf.ConvolutionMode;
|
||||||
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
|
||||||
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
|
||||||
import org.deeplearning4j.nn.conf.inputs.InputType;
|
import org.deeplearning4j.nn.conf.inputs.InputType;
|
||||||
|
@ -72,7 +71,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
for (int miniBatchSize : minibatchSizes) {
|
for (int miniBatchSize : minibatchSizes) {
|
||||||
for (PoolingType pt : poolingTypes) {
|
for (PoolingType pt : poolingTypes) {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
|
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
|
||||||
|
@ -95,7 +94,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
System.out.println("testLSTMGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = "
|
System.out.println("testLSTMGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = "
|
||||||
+ miniBatchSize);
|
+ miniBatchSize);
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -127,7 +126,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
for (int miniBatchSize : minibatchSizes) {
|
for (int miniBatchSize : minibatchSizes) {
|
||||||
for (PoolingType pt : poolingTypes) {
|
for (PoolingType pt : poolingTypes) {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
|
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
|
||||||
|
@ -138,7 +137,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
.layer(1, new GlobalPoolingLayer.Builder().poolingType(pt).build())
|
.layer(1, new GlobalPoolingLayer.Builder().poolingType(pt).build())
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
.setInputType(InputType.convolutional(inputH, inputW, inputDepth, nchw ? CNN2DFormat.NCHW : CNN2DFormat.NHWC)).build();
|
.inputType(InputType.convolutional(inputH, inputW, inputDepth, nchw ? CNN2DFormat.NCHW : CNN2DFormat.NHWC)).build();
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -156,7 +155,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println("testCnnGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = " + miniBatchSize + " - " + (nchw ? "NCHW" : "NHWC"));
|
System.out.println("testCnnGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = " + miniBatchSize + " - " + (nchw ? "NCHW" : "NHWC"));
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
boolean gradOK = GradientCheckUtil.checkGradients(mln, DEFAULT_EPS, DEFAULT_MAX_REL_ERROR,
|
||||||
|
@ -185,7 +184,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
|
|
||||||
for (PoolingType pt : poolingTypes) {
|
for (PoolingType pt : poolingTypes) {
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
|
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
|
||||||
|
@ -216,7 +215,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
if (PRINT_RESULTS) {
|
if (PRINT_RESULTS) {
|
||||||
System.out.println("testLSTMGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = " + miniBatchSize);
|
System.out.println("testLSTMGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = " + miniBatchSize);
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(new GradientCheckUtil.MLNConfig().net(mln).input(input)
|
boolean gradOK = GradientCheckUtil.checkGradients(new GradientCheckUtil.MLNConfig().net(mln).input(input)
|
||||||
|
@ -259,7 +258,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
stride = new int[] {inputH, 1};
|
stride = new int[] {inputH, 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
|
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
|
||||||
.dataType(DataType.DOUBLE)
|
.dataType(DataType.DOUBLE)
|
||||||
.updater(new NoOp())
|
.updater(new NoOp())
|
||||||
.dist(new NormalDistribution(0, 1.0)).convolutionMode(ConvolutionMode.Same)
|
.dist(new NormalDistribution(0, 1.0)).convolutionMode(ConvolutionMode.Same)
|
||||||
|
@ -270,7 +269,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
|
||||||
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
.activation(Activation.SOFTMAX).nOut(nOut).build())
|
||||||
|
|
||||||
.setInputType(InputType.convolutional(inputH, inputW, inputDepth)).build();
|
.inputType(InputType.convolutional(inputH, inputW, inputDepth)).build();
|
||||||
|
|
||||||
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
|
||||||
mln.init();
|
mln.init();
|
||||||
|
@ -299,7 +298,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
|
||||||
System.out.println("testCnnGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = "
|
System.out.println("testCnnGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = "
|
||||||
+ miniBatchSize);
|
+ miniBatchSize);
|
||||||
// for (int j = 0; j < mln.getnLayers(); j++)
|
// for (int j = 0; j < mln.getnLayers(); j++)
|
||||||
// System.out.println("Layer " + j + " # params: " + mln.getLayer(j).numParams());
|
// System.out.println("ILayer " + j + " # params: " + mln.getLayer(j).numParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gradOK = GradientCheckUtil.checkGradients(new GradientCheckUtil.MLNConfig().net(mln).input(input)
|
boolean gradOK = GradientCheckUtil.checkGradients(new GradientCheckUtil.MLNConfig().net(mln).input(input)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue