Refactoring and separation of IModel / Layer

master
Brian Rosenberger 2023-03-23 17:39:00 +01:00
parent 42fb4bd48e
commit d592e02852
672 changed files with 20808 additions and 17478 deletions

View File

@ -205,7 +205,7 @@ public class TupleStreamDataSetIteratorTest extends SolrCloudTestCase {
public void modelFitTest() throws Exception {
final MultiLayerNetwork model = new MultiLayerNetwork(
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration.builder()
.list(
new OutputLayer.Builder(LossFunction.MSE)
.nIn(3)

View File

@ -35,7 +35,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.params.ModifiableSolrParams;
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.layers.OutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
@ -153,7 +153,7 @@ public class ModelTupleStreamIntegrationTest extends SolrCloudTestCase {
final int numInputs = 3;
final int numOutputs = 2;
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.list(
new OutputLayer.Builder()
.nIn(numInputs)

View File

@ -43,7 +43,7 @@ import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.handler.SolrDefaultStreamFactory;
import org.deeplearning4j.nn.api.Model;
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.graph.ComputationGraph;
@ -242,7 +242,7 @@ public class ModelTupleStreamTest {
protected Model buildMultiLayerNetworkModel(int numInputs, int numOutputs) throws Exception {
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.list(
new OutputLayer.Builder()
.nIn(numInputs)
@ -274,7 +274,7 @@ public class ModelTupleStreamTest {
protected Model buildComputationGraphModel(int numInputs, int numOutputs) throws Exception {
final ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
final ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("inputLayer")
.addLayer("outputLayer",

View File

@ -42,7 +42,7 @@ import org.apache.solr.ltr.norm.Normalizer;
import org.apache.solr.request.SolrQueryRequest;
import org.deeplearning4j.nn.api.Model;
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.graph.ComputationGraph;
@ -192,7 +192,7 @@ public class ScoringModelTest {
protected Model buildMultiLayerNetworkModel(int numFeatures) throws Exception {
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.list(
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 {
final ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
final ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("inputLayer")
.addLayer("outputLayer",

View File

@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.deeplearning4j.BaseDL4JTest;
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.MergeVertex;
import org.deeplearning4j.nn.conf.layers.*;
@ -70,7 +70,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
private static final MultiLayerNetwork model;
static {
val conf = new NeuralNetConfiguration.Builder()
val conf = NeuralNetConfiguration.builder()
.seed(119)
.updater(new Adam(0.119f))
.weightInit(WeightInit.XAVIER)
@ -541,7 +541,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
@Test
public void testMlnMnist() throws Exception {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.list()
.layer(new DenseLayer.Builder().nIn(784).nOut(10).build())
.layer(new LossLayer.Builder().activation(Activation.SOFTMAX).build())
@ -597,7 +597,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
@Test
public void testCompGraph() throws Exception {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("input1", "input2")
.addLayer("L1", new DenseLayer.Builder().nIn(3).nOut(4).build(), "input1")
@ -652,7 +652,7 @@ public class JsonModelServerTest extends BaseDL4JTest {
@Test
public void testCompGraph_1() throws Exception {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.updater(new Sgd(0.01))
.graphBuilder()
.addInputs("input")

View File

@ -425,7 +425,7 @@ public class SharedTrainingWrapper {
.setTrainingWorkspaceMode(trainingConfiguration.getWorkspaceMode());
((ComputationGraph) originalModel).setGradientsAccumulator(accumulator);
} else if (model instanceof MultiLayerNetwork) {
((MultiLayerNetwork) originalModel).getLayerWiseConfigurations()
((MultiLayerNetwork) originalModel).getConfiguration()
.setTrainingWorkspaceMode(trainingConfiguration.getWorkspaceMode());
((MultiLayerNetwork) originalModel).setGradientsAccumulator(accumulator);
}

View File

@ -261,7 +261,7 @@ public class SharedTrainingMaster extends BaseTrainingMaster<SharedTrainingResul
/*
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());
voidConfiguration.setUnicastControllerPort(voidConfiguration.getPortSupplier().getPort());

View File

@ -24,7 +24,7 @@ import lombok.Getter;
import org.apache.spark.broadcast.Broadcast;
import org.deeplearning4j.core.storage.StatsStorageRouter;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.optimize.api.TrainingListener;
@ -91,7 +91,7 @@ public class SharedTrainingWorker extends BaseTrainingWorker<SharedTrainingResul
NetBroadcastTuple tuple = broadcastModel.getValue();
if (tuple.getConfiguration() != null) {
MultiLayerConfiguration conf = tuple.getConfiguration();
NeuralNetConfiguration conf = tuple.getConfiguration();
MultiLayerNetwork network = new MultiLayerNetwork(conf);
network.init();

View File

@ -24,7 +24,7 @@ import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
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.spark.impl.multilayer.SparkDl4jMultiLayer;
import org.deeplearning4j.spark.impl.paramavg.ParameterAveragingTrainingMaster;
@ -126,8 +126,8 @@ public abstract class BaseSparkTest extends BaseDL4JTest implements Serializable
return 4;
}
protected MultiLayerConfiguration getBasicConf() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
protected NeuralNetConfiguration getBasicConf() {
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
.updater(new Nesterovs(0.1, 0.9)).list()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
.activation(Activation.TANH).build())

View File

@ -28,7 +28,7 @@ import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
import org.deeplearning4j.eval.Evaluation;
import org.deeplearning4j.nn.api.Model;
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.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -132,7 +132,7 @@ public class GradientSharingTrainingTest extends BaseSparkTest {
.build();
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.seed(12345)
.updater(new AMSGrad(0.1))
.graphBuilder()
@ -266,16 +266,16 @@ public class GradientSharingTrainingTest extends BaseSparkTest {
System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
log.info("Starting: {}", i);
MultiLayerConfiguration conf;
NeuralNetConfiguration conf;
if (i == 0) {
conf = new NeuralNetConfiguration.Builder()
conf = NeuralNetConfiguration.builder()
.weightInit(WeightInit.XAVIER)
.seed(12345)
.list()
.layer(new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX).lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
} else {
conf = new NeuralNetConfiguration.Builder()
conf = NeuralNetConfiguration.builder()
.weightInit(WeightInit.XAVIER)
.seed(12345)
.list()
@ -353,7 +353,7 @@ public class GradientSharingTrainingTest extends BaseSparkTest {
.build();
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.seed(12345)
.updater(new AMSGrad(0.001))
.graphBuilder()

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.spark.api.worker;
import lombok.Data;
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 java.io.Serializable;
@ -31,13 +31,13 @@ import java.util.concurrent.atomic.AtomicInteger;
@Data
public class NetBroadcastTuple implements Serializable {
private final MultiLayerConfiguration configuration;
private final NeuralNetConfiguration configuration;
private final ComputationGraphConfiguration graphConfiguration;
private final INDArray parameters;
private final INDArray updaterState;
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);
}
@ -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) {
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) {
this.configuration = configuration;
this.graphConfiguration = graphConfiguration;

View File

@ -31,7 +31,7 @@ public abstract class BaseVaeReconstructionProbWithKeyFunction<K> extends BaseVa
/**
* @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 batchSize Batch size to use when scoring
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}

View File

@ -45,7 +45,7 @@ public abstract class BaseVaeScoreWithKeyFunction<K> implements PairFlatMapFunct
/**
* @param params MultiLayerNetwork parameters
* @param jsonConfig MultiLayerConfiguration, as json
* @param jsonConfig NeuralNetConfiguration, as json
* @param batchSize Batch size to use when scoring
*/
public BaseVaeScoreWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig, int batchSize) {

View File

@ -27,7 +27,7 @@ import org.deeplearning4j.datasets.iterator.IteratorDataSetIterator;
import org.deeplearning4j.datasets.iterator.IteratorMultiDataSetIterator;
import org.deeplearning4j.nn.api.Model;
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.multilayer.MultiLayerNetwork;
import org.nd4j.common.base.Preconditions;
@ -131,7 +131,7 @@ public class EvaluationRunner {
cg.init(deviceLocalParams.get(), false);
m = cg;
} else {
MultiLayerConfiguration conf = MultiLayerConfiguration.fromJson(json.getValue());
NeuralNetConfiguration conf = NeuralNetConfiguration.fromJson(json.getValue());
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init(deviceLocalParams.get(), false);
m = net;

View File

@ -33,7 +33,7 @@ public class CGVaeReconstructionErrorWithKeyFunction<K> extends BaseVaeScoreWith
/**
* @param params MultiLayerNetwork parameters
* @param jsonConfig MultiLayerConfiguration, as json
* @param jsonConfig NeuralNetConfiguration, as json
* @param batchSize Batch size to use when scoring
*/
public CGVaeReconstructionErrorWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig,

View File

@ -33,7 +33,7 @@ public class CGVaeReconstructionProbWithKeyFunction<K> extends BaseVaeReconstruc
/**
* @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 batchSize Batch size to use when scoring
* @param numSamples Number of samples to use when calling {@link VariationalAutoencoder#reconstructionLogProbability(INDArray, int)}

View File

@ -35,7 +35,7 @@ import org.datavec.spark.util.BroadcastHadoopConfigHolder;
import org.deeplearning4j.core.loader.DataSetLoader;
import org.deeplearning4j.core.loader.MultiDataSetLoader;
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.multilayer.MultiLayerNetwork;
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_EVAL_WORKERS = 4;
private transient JavaSparkContext sc;
private MultiLayerConfiguration conf;
private NeuralNetConfiguration conf;
private MultiLayerNetwork network;
private double lastScore;
private int defaultEvaluationWorkers = DEFAULT_EVAL_WORKERS;
@ -104,7 +104,7 @@ public class SparkDl4jMultiLayer extends SparkListenable {
* @param sparkContext the spark context to use
* @param conf the configuration of the network
*/
public SparkDl4jMultiLayer(SparkContext sparkContext, MultiLayerConfiguration conf,
public SparkDl4jMultiLayer(SparkContext sparkContext, NeuralNetConfiguration conf,
TrainingMaster<?, ?> 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 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);
}
public SparkDl4jMultiLayer(JavaSparkContext javaSparkContext, MultiLayerNetwork network,
TrainingMaster<?, ?> trainingMaster) {
sc = javaSparkContext;
this.conf = network.getLayerWiseConfigurations().clone();
this.conf = network.getConfiguration().clone();
this.network = network;
if (!network.isInitCalled())
network.init();
@ -132,7 +132,7 @@ public class SparkDl4jMultiLayer extends SparkListenable {
SparkUtils.checkKryoConfiguration(javaSparkContext, log);
}
private static MultiLayerNetwork initNetwork(MultiLayerConfiguration conf) {
private static MultiLayerNetwork initNetwork(NeuralNetConfiguration conf) {
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
return net;
@ -315,8 +315,8 @@ public class SparkDl4jMultiLayer extends SparkListenable {
* @return the multi layer network that was fitDataSet
*/
public MultiLayerNetwork fitLabeledPoint(JavaRDD<LabeledPoint> rdd) {
int nLayers = network.getLayerWiseConfigurations().getConfs().size();
FeedForwardLayer ffl = (FeedForwardLayer) network.getLayerWiseConfigurations().getConf(nLayers - 1).getLayer();
int nLayers = network.getConfiguration().getConfs().size();
FeedForwardLayer ffl = (FeedForwardLayer) network.getConfiguration().getConf(nLayers - 1).getLayer();
JavaRDD<DataSet> ds = MLLibUtil.fromLabeledPoint(sc, rdd, ffl.getNOut());
return fit(ds);
}

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
import org.apache.spark.api.java.function.PairFlatMapFunction;
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.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.api.DataSetUtil;
@ -49,7 +49,7 @@ public class FeedForwardWithKeyFunction<K>
/**
* @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)
*/
public FeedForwardWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig, int batchSize) {
@ -65,7 +65,7 @@ public class FeedForwardWithKeyFunction<K>
return Collections.emptyIterator();
}
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(jsonConfig.getValue()));
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(jsonConfig.getValue()));
network.init();
INDArray val = params.value().unsafeDuplication();
if (val.length() != network.numParams(false))

View File

@ -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.FlatMapFunction;
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.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;
@ -60,7 +60,7 @@ public class ScoreExamplesFunction implements DoubleFlatMapFunction<Iterator<Dat
return Collections.emptyIterator();
}
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(jsonConfig.getValue()));
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(jsonConfig.getValue()));
network.init();
INDArray val = params.value().unsafeDuplication();
if (val.length() != network.numParams(false))

View File

@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
import lombok.extern.slf4j.Slf4j;
import org.apache.spark.api.java.function.PairFlatMapFunction;
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.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;
@ -45,7 +45,7 @@ public class ScoreExamplesWithKeyFunction<K> implements PairFlatMapFunction<Iter
/**
* @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 batchSize Batch size to use when scoring
*/
@ -63,7 +63,7 @@ public class ScoreExamplesWithKeyFunction<K> implements PairFlatMapFunction<Iter
return Collections.emptyIterator();
}
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(jsonConfig.getValue()));
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(jsonConfig.getValue()));
network.init();
INDArray val = params.value().unsafeDuplication();
if (val.length() != network.numParams(false))

View File

@ -26,7 +26,7 @@ import lombok.val;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.broadcast.Broadcast;
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.nd4j.linalg.api.ndarray.INDArray;
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
MultiLayerNetwork network = new MultiLayerNetwork(MultiLayerConfiguration.fromJson(json));
MultiLayerNetwork network = new MultiLayerNetwork(NeuralNetConfiguration.fromJson(json));
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
if (val.length() != network.numParams(false))

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
import org.apache.spark.broadcast.Broadcast;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.spark.impl.common.score.BaseVaeScoreWithKeyFunction;
@ -36,7 +36,7 @@ public class VaeReconstructionErrorWithKeyFunction<K> extends BaseVaeScoreWithKe
/**
* @param params MultiLayerNetwork parameters
* @param jsonConfig MultiLayerConfiguration, as json
* @param jsonConfig NeuralNetConfiguration, as json
* @param batchSize Batch size to use when scoring
*/
public VaeReconstructionErrorWithKeyFunction(Broadcast<INDArray> params, Broadcast<String> jsonConfig,
@ -47,7 +47,7 @@ public class VaeReconstructionErrorWithKeyFunction<K> extends BaseVaeScoreWithKe
@Override
public VariationalAutoencoder getVaeLayer() {
MultiLayerNetwork network =
new MultiLayerNetwork(MultiLayerConfiguration.fromJson((String) jsonConfig.getValue()));
new MultiLayerNetwork(NeuralNetConfiguration.fromJson((String) jsonConfig.getValue()));
network.init();
INDArray val = ((INDArray) params.value()).unsafeDuplication();
if (val.length() != network.numParams(false))

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.multilayer.scoring;
import org.apache.spark.broadcast.Broadcast;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.spark.impl.common.score.BaseVaeReconstructionProbWithKeyFunction;
@ -34,7 +34,7 @@ public class VaeReconstructionProbWithKeyFunction<K> extends BaseVaeReconstructi
/**
* @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 batchSize Batch size to use when scoring
* @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
public VariationalAutoencoder getVaeLayer() {
MultiLayerNetwork network =
new MultiLayerNetwork(MultiLayerConfiguration.fromJson((String) jsonConfig.getValue()));
new MultiLayerNetwork(NeuralNetConfiguration.fromJson((String) jsonConfig.getValue()));
network.init();
INDArray val = ((INDArray) params.value()).unsafeDuplication();
if (val.length() != network.numParams(false))

View File

@ -41,7 +41,7 @@ import org.deeplearning4j.core.storage.StatsStorageRouter;
import org.deeplearning4j.core.storage.StatsStorageRouterProvider;
import org.deeplearning4j.core.storage.StorageMetaData;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.optimize.api.TrainingListener;
@ -274,7 +274,7 @@ public class ParameterAveragingTrainingMaster
@Override
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());
if (collectTrainingStats)
@ -726,7 +726,7 @@ public class ParameterAveragingTrainingMaster
if (params != null) {
//Params may be null for edge case (empty RDD)
if (network != null) {
MultiLayerConfiguration conf = network.getNetwork().getLayerWiseConfigurations();
NeuralNetConfiguration conf = network.getNetwork().getConfiguration();
int numUpdates = averagingFrequency;
conf.setIterationCount(conf.getIterationCount() + numUpdates);
} else {

View File

@ -26,7 +26,7 @@ import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.datavec.spark.util.SerializableHadoopConfig;
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.spark.impl.multilayer.SparkDl4jMultiLayer;
import org.deeplearning4j.spark.impl.paramavg.ParameterAveragingTrainingMaster;
@ -129,8 +129,8 @@ public abstract class BaseSparkTest extends BaseDL4JTest implements Serializable
return 4;
}
protected MultiLayerConfiguration getBasicConf() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
protected NeuralNetConfiguration getBasicConf() {
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
.updater(new Nesterovs(0.1, 0.9)).list()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
.activation(Activation.TANH).build())

View File

@ -35,7 +35,7 @@ import org.deeplearning4j.earlystopping.termination.MaxTimeIterationTerminationC
import org.deeplearning4j.earlystopping.termination.ScoreImprovementEpochTerminationCondition;
import org.deeplearning4j.earlystopping.trainer.IEarlyStoppingTrainer;
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.layers.OutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
@ -68,7 +68,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
//Spark tests don't run on windows
return;
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd()).weightInit(WeightInit.XAVIER).list()
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
@ -123,7 +123,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
return;
}
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(10.0)) //Intentionally huge LR
.weightInit(WeightInit.XAVIER).list()
@ -163,7 +163,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
return;
}
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(1e-6)).weightInit(WeightInit.XAVIER).list()
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
@ -209,7 +209,7 @@ public class TestEarlyStoppingSpark extends BaseSparkTest {
return;
}
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.0)).weightInit(WeightInit.XAVIER).list()
.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
return;
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd()).weightInit(WeightInit.XAVIER).list()
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)

View File

@ -71,7 +71,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
//Spark tests don't run on windows
return;
}
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd()).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
@ -124,7 +124,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
return;
}
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(2.0)) //Intentionally huge LR
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
@ -165,7 +165,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
return;
}
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).graphBuilder()
.addInputs("in")
@ -213,7 +213,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
return;
}
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).graphBuilder()
.addInputs("in")
@ -253,7 +253,7 @@ public class TestEarlyStoppingSparkCompGraph extends BaseSparkTest {
//Spark tests don't run on windows
return;
}
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd()).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.spark;
import org.apache.spark.serializer.SerializerInstance;
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.UniformDistribution;
import org.deeplearning4j.nn.conf.graph.*;
@ -68,14 +68,14 @@ public class TestKryo extends BaseSparkKryoTest {
Map<Integer, Double> m = new HashMap<>();
m.put(0, 0.5);
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())
.build();
testSerialization(mlc, si);
ComputationGraphConfiguration cgc = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration cgc = NeuralNetConfiguration.builder()
.dist(new UniformDistribution(-1, 1))
.updater(new Adam(new MapSchedule(ScheduleType.ITERATION,m)))
.graphBuilder()

View File

@ -30,7 +30,7 @@ import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
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.Updater;
import org.deeplearning4j.spark.BaseSparkTest;
@ -84,7 +84,7 @@ public class TestPreProcessedData extends BaseSparkTest {
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()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)
.activation(Activation.TANH).build())
@ -134,7 +134,7 @@ public class TestPreProcessedData extends BaseSparkTest {
iter.next().save(f2);
}
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(Updater.RMSPROP)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(Updater.RMSPROP)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.graphBuilder().addInputs("in")
.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);
}
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(Updater.RMSPROP)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(Updater.RMSPROP)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.graphBuilder().addInputs("in")
.addLayer("0", new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(4).nOut(3)

View File

@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
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.spark.api.TrainingMaster;
@ -40,7 +40,7 @@ public class TestKryoWarning {
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new OutputLayer.Builder().nIn(10).nOut(10).build())
.build();
@ -57,7 +57,7 @@ public class TestKryoWarning {
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")
.build();

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.spark.impl.customlayer;
import com.sun.jna.Platform;
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.layers.DenseLayer;
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
//Custom layers are tested more extensively in dl4j core
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().updater(new Sgd(0.1)).list()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().updater(new Sgd(0.1)).list()
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
.layer(1, new CustomLayer(3.14159)).layer(2,
new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)

View File

@ -77,7 +77,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
public static ComputationGraph getBasicNetIris2Class() {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER)
.graphBuilder().addInputs("in")
.addLayer("l0", new DenseLayer.Builder().nIn(4).nOut(10).build(), "in")
.addLayer("l1", new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
@ -104,7 +104,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
while (iter.hasNext())
list.add(iter.next());
ComputationGraphConfiguration config = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration config = NeuralNetConfiguration.builder()
.updater(new Sgd(0.1))
.graphBuilder().addInputs("in")
.addLayer("dense", new DenseLayer.Builder().nIn(4).nOut(2).build(), "in").addLayer("out",
@ -138,7 +138,7 @@ public class TestSparkComputationGraph extends BaseSparkTest {
@Test
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()
.addInputs("in")
.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")
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)
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
.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);
// simple model
val modelConf = new NeuralNetConfiguration.Builder()
val modelConf = NeuralNetConfiguration.builder()
.updater(new Adam(0.01))
.weightInit(WeightInit.XAVIER_UNIFORM)
.biasInit(0)

View File

@ -53,7 +53,7 @@ public class TestFrozenLayers extends BaseSparkTest {
@Test
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);
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)
.setFeatureExtractor(1).build();
Map<String, INDArray> m = withFrozen.paramTable();
Map<String, INDArray> m = withFrozen.getParamTable();
Map<String, INDArray> pCopy = new HashMap<>();
for (Map.Entry<String, INDArray> entry : m.entrySet()) {
pCopy.put(entry.getKey(), entry.getValue().dup());
@ -110,7 +110,7 @@ public class TestFrozenLayers extends BaseSparkTest {
MultiLayerNetwork fitted = sNet.getNetwork();
Map<String, INDArray> fittedParams = fitted.paramTable();
Map<String, INDArray> fittedParams = fitted.getParamTable();
for (Map.Entry<String, INDArray> entry : fittedParams.entrySet()) {
INDArray orig = pCopy.get(entry.getKey());
@ -136,7 +136,7 @@ public class TestFrozenLayers extends BaseSparkTest {
int nIn = 6;
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")
.addLayer("0", new DenseLayer.Builder().nIn(6).nOut(5).build(), "in")
.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)
.setFeatureExtractor("1").build();
Map<String, INDArray> m = withFrozen.paramTable();
Map<String, INDArray> m = withFrozen.getParamTable();
Map<String, INDArray> pCopy = new HashMap<>();
for (Map.Entry<String, INDArray> entry : m.entrySet()) {
pCopy.put(entry.getKey(), entry.getValue().dup());
@ -187,7 +187,7 @@ public class TestFrozenLayers extends BaseSparkTest {
ComputationGraph fitted = sNet.getNetwork();
Map<String, INDArray> fittedParams = fitted.paramTable();
Map<String, INDArray> fittedParams = fitted.getParamTable();
for (Map.Entry<String, INDArray> entry : fittedParams.entrySet()) {
INDArray orig = pCopy.get(entry.getKey());

View File

@ -23,7 +23,7 @@ package org.deeplearning4j.spark.impl.multilayer;
import org.apache.spark.api.java.JavaPairRDD;
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
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.*;
import org.deeplearning4j.nn.conf.layers.variational.GaussianReconstructionDistribution;
@ -57,7 +57,7 @@ public class TestMiscFunctions extends BaseSparkTest {
@Test
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(1, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT).nIn(3).nOut(3)
.activation(Activation.SOFTMAX).build())
@ -107,7 +107,7 @@ public class TestMiscFunctions extends BaseSparkTest {
@Test
public void testFeedForwardWithKeyInputMask() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER)
.list()
.layer( new LSTM.Builder().nIn(4).nOut(3).build())
.layer(new GlobalPoolingLayer(PoolingType.AVG))
@ -162,7 +162,7 @@ public class TestMiscFunctions extends BaseSparkTest {
@Test
public void testFeedForwardWithKeyGraph() {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER)
.graphBuilder().addInputs("in1", "in2")
.addLayer("0", new DenseLayer.Builder().nIn(4).nOut(3).build(), "in1")
.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;
MultiLayerConfiguration mlc = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration mlc = NeuralNetConfiguration.builder().list()
.layer(0, new org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder.Builder()
.reconstructionDistribution(
new GaussianReconstructionDistribution(Activation.IDENTITY))
@ -259,7 +259,7 @@ public class TestMiscFunctions extends BaseSparkTest {
int nIn = 10;
MultiLayerConfiguration mlc = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration mlc = NeuralNetConfiguration.builder()
.list().layer(0,
new org.deeplearning4j.nn.conf.layers.variational.VariationalAutoencoder.Builder()
.reconstructionDistribution(new LossFunctionWrapper(

View File

@ -25,7 +25,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.spark.api.java.JavaRDD;
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
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.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -102,7 +102,7 @@ public class TestSparkDl4jMultiLayer extends BaseSparkTest {
//----------------------------------
//Create network configuration and conduct network training
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)

View File

@ -26,7 +26,7 @@ import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
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.inputs.InputType;
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);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).list()
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build()).layer(1, new OutputLayer.Builder()
@ -74,9 +74,9 @@ public class TestCompareParameterAveragingSparkVsSingleMachine {
return conf;
}
private static MultiLayerConfiguration getConfCNN(int seed, IUpdater updater) {
private static NeuralNetConfiguration getConfCNN(int seed, IUpdater updater) {
Nd4j.getRandom().setSeed(seed);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).list()
.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())
.layer(1, new OutputLayer.Builder().lossFunction(LossFunctions.LossFunction.MSE).nOut(10)
.build())
.setInputType(InputType.convolutional(10, 10, 3)).build();
.inputType(InputType.convolutional(10, 10, 3)).build();
return conf;
}
private static ComputationGraphConfiguration getGraphConf(int seed, IUpdater updater) {
Nd4j.getRandom().setSeed(seed);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).graphBuilder()
.addInputs("in")
@ -105,7 +105,7 @@ public class TestCompareParameterAveragingSparkVsSingleMachine {
private static ComputationGraphConfiguration getGraphConfCNN(int seed, IUpdater updater) {
Nd4j.getRandom().setSeed(seed);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.weightInit(WeightInit.XAVIER).updater(updater).seed(seed).graphBuilder()
.addInputs("in")

View File

@ -37,7 +37,7 @@ import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
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.BaseLayer;
import org.deeplearning4j.nn.conf.layers.BatchNormalization;
@ -127,7 +127,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
.toJavaRDD().map(new TestFn());
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()
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
.activation(Activation.RELU).build())
@ -162,8 +162,8 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
.getAbsolutePath())
.toJavaRDD().map(new TestFn());
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().seed(123)
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().seed(123)
.updater(new Adam(1e-6))
.weightInit(WeightInit.XAVIER)
.list()
@ -275,7 +275,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
//Spark tests don't run on windows
return;
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
.activation(Activation.TANH).build())
@ -300,7 +300,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
@Test
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()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(nIn).nOut(3)
.activation(Activation.TANH).build())
@ -389,7 +389,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
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()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
.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()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
.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()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
.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)
.graphBuilder().addInputs("in")
.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
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)
.weightInit(WeightInit.XAVIER).list()
.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());
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(50)
.activation(Activation.TANH).build())
@ -791,13 +791,13 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
JavaRDD<DataSet> rdd = sc.parallelize(list);
assertEquals(0, sparkNet.getNetwork().getLayerWiseConfigurations().getIterationCount());
assertEquals(0, sparkNet.getNetwork().getConfiguration().getIterationCount());
sparkNet.fit(rdd);
assertEquals(minibatchesPerWorkerPerEpoch,
sparkNet.getNetwork().getLayerWiseConfigurations().getIterationCount());
sparkNet.getNetwork().getConfiguration().getIterationCount());
sparkNet.fit(rdd);
assertEquals(2 * minibatchesPerWorkerPerEpoch,
sparkNet.getNetwork().getLayerWiseConfigurations().getIterationCount());
sparkNet.getNetwork().getConfiguration().getIterationCount());
sparkNet.getTrainingMaster().deleteTempFiles(sc);
}
@ -819,7 +819,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
list.add(iter.next());
}
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.graphBuilder().addInputs("in")
.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;
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()
.layer(0, new VariationalAutoencoder.Builder().nIn(8).nOut(10).encoderLayerSizes(12)
.decoderLayerSizes(13).reconstructionDistribution(
@ -896,7 +896,7 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
int nIn = 8;
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")
.addLayer("0", new VariationalAutoencoder.Builder().nIn(8).nOut(10).encoderLayerSizes(12)
.decoderLayerSizes(13).reconstructionDistribution(
@ -936,8 +936,8 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
int nOut = 2;
int layerSize = 10;
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(layerSize).build())
.layer(1, new OutputLayer.Builder().nIn(layerSize).nOut(nOut)
.activation(Activation.SOFTMAX).lossFunction(
@ -991,8 +991,8 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
int nOut = 3;
int layerSize = 10;
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).list()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).list()
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(layerSize).build())
.layer(1, new OutputLayer.Builder().nIn(layerSize).nOut(nOut)
.activation(Activation.SOFTMAX).lossFunction(
@ -1045,12 +1045,12 @@ public class TestSparkMultiLayerParameterAveraging extends BaseSparkTest {
//Spark tests don't run on windows
return;
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.list()
.layer(new OutputLayer.Builder().nIn(4).nOut(3).build())
.build();
ComputationGraphConfiguration conf2 = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf2 = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("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++ ){
assertEquals(i, sn1.getNetwork().getLayerWiseConfigurations().getEpochCount());
assertEquals(i, sn1.getNetwork().getConfiguration().getEpochCount());
assertEquals(i, sn2.getNetwork().getConfiguration().getEpochCount());
sn1.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());
}
}

View File

@ -26,7 +26,7 @@ import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
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.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -67,7 +67,7 @@ public class TestTrainingStatsCollection extends BaseSparkTest {
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.layer(0, new DenseLayer.Builder().nIn(10).nOut(10).build())
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build())

View File

@ -27,7 +27,7 @@ import org.deeplearning4j.core.storage.Persistable;
import org.deeplearning4j.core.storage.StatsStorage;
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
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.layers.DenseLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
@ -60,7 +60,7 @@ public class TestListeners extends BaseSparkTest {
JavaSparkContext sc = getContext();
int nExecutors = numExecutors();
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
.activation(Activation.RELU).build())

View File

@ -20,7 +20,7 @@
package org.deeplearning4j.rl4j.network;
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.layers.recurrent.RnnOutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
@ -41,7 +41,7 @@ public class MultiLayerNetworkHandler implements INetworkHandler {
@Getter
private final boolean recurrent;
private final MultiLayerConfiguration configuration;
private final NeuralNetConfiguration configuration;
private final String labelName;
private final String gradientName;
private final int inputFeatureIdx;
@ -59,7 +59,7 @@ public class MultiLayerNetworkHandler implements INetworkHandler {
int inputFeatureIdx) {
this.model = model;
recurrent = model.getOutputLayer() instanceof RnnOutputLayer;
configuration = model.getLayerWiseConfigurations();
configuration = model.getConfiguration();
this.labelName = labelName;
this.gradientName = gradientName;
this.inputFeatureIdx = inputFeatureIdx;

View File

@ -59,7 +59,7 @@ public class ActorCriticFactoryCompGraphStdConv implements ActorCriticFactoryCom
int w = (((shapeInputs[2] - 8) / 4 + 1) - 4) / 2 + 1;
ComputationGraphConfiguration.GraphBuilder confB =
new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
.weightInit(WeightInit.XAVIER)

View File

@ -49,7 +49,7 @@ public class ActorCriticFactoryCompGraphStdDense implements ActorCriticFactoryCo
nIn *= i;
}
ComputationGraphConfiguration.GraphBuilder confB =
new NeuralNetConfiguration.Builder().seed(Constants.NEURAL_NET_SEED)
NeuralNetConfiguration.builder().seed(Constants.NEURAL_NET_SEED)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
.weightInit(WeightInit.XAVIER)

View File

@ -24,7 +24,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
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.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
@ -56,7 +56,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
for (int i : numInputs) {
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)
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
.weightInit(WeightInit.XAVIER)
@ -81,7 +81,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
}
confB.setInputType(conf.isUseLSTM() ? InputType.recurrent(nIn) : InputType.feedForward(nIn));
MultiLayerConfiguration mlnconf2 = confB.build();
NeuralNetConfiguration mlnconf2 = confB.build();
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf2);
model.init();
if (conf.getListeners() != null) {
@ -90,7 +90,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
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)
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
.weightInit(WeightInit.XAVIER)
@ -116,7 +116,7 @@ public class ActorCriticFactorySeparateStdDense implements ActorCriticFactorySep
}
confB2.setInputType(conf.isUseLSTM() ? InputType.recurrent(nIn) : InputType.feedForward(nIn));
MultiLayerConfiguration mlnconf = confB2.build();
NeuralNetConfiguration mlnconf = confB2.build();
MultiLayerNetwork model2 = new MultiLayerNetwork(mlnconf);
model2.init();
if (conf.getListeners() != null) {

View File

@ -23,7 +23,7 @@ package org.deeplearning4j.rl4j.network.ac;
import lombok.Getter;
import org.apache.commons.lang3.NotImplementedException;
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.layers.recurrent.RnnOutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
@ -131,7 +131,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
@Override
public void applyGradients(Gradients gradients) {
int batchSize = (int)gradients.getBatchSize();
MultiLayerConfiguration valueConf = valueNet.getLayerWiseConfigurations();
NeuralNetConfiguration valueConf = valueNet.getConfiguration();
int valueIterationCount = valueConf.getIterationCount();
int valueEpochCount = valueConf.getEpochCount();
Gradient valueGradient = gradients.getGradient(CommonGradientNames.ActorCritic.Value);
@ -145,7 +145,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
}
valueConf.setIterationCount(valueIterationCount + 1);
MultiLayerConfiguration policyConf = policyNet.getLayerWiseConfigurations();
NeuralNetConfiguration policyConf = policyNet.getConfiguration();
int policyIterationCount = policyConf.getIterationCount();
int policyEpochCount = policyConf.getEpochCount();
Gradient policyGradient = gradients.getGradient(CommonGradientNames.ActorCritic.Policy);
@ -191,7 +191,7 @@ public class ActorCriticSeparate<NN extends ActorCriticSeparate> implements IAct
@Deprecated
public void applyGradient(Gradient[] gradient, int batchSize) {
MultiLayerConfiguration valueConf = valueNet.getLayerWiseConfigurations();
NeuralNetConfiguration valueConf = valueNet.getConfiguration();
int valueIterationCount = valueConf.getIterationCount();
int valueEpochCount = valueConf.getEpochCount();
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);
MultiLayerConfiguration policyConf = policyNet.getLayerWiseConfigurations();
NeuralNetConfiguration policyConf = policyNet.getConfiguration();
int policyIterationCount = policyConf.getIterationCount();
int policyEpochCount = policyConf.getEpochCount();
policyNet.getUpdater().update(policyNet, gradient[1], policyIterationCount, policyEpochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.rl4j.network.dqn;
import org.apache.commons.lang3.NotImplementedException;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.workspace.LayerWorkspaceMgr;
@ -157,7 +157,7 @@ public class DQN implements IDQN<DQN> {
public void applyGradients(Gradients gradients) {
Gradient qValues = gradients.getGradient(CommonGradientNames.QValues);
MultiLayerConfiguration mlnConf = mln.getLayerWiseConfigurations();
NeuralNetConfiguration mlnConf = mln.getConfiguration();
int iterationCount = mlnConf.getIterationCount();
int epochCount = mlnConf.getEpochCount();
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) {
MultiLayerConfiguration mlnConf = mln.getLayerWiseConfigurations();
NeuralNetConfiguration mlnConf = mln.getConfiguration();
int iterationCount = mlnConf.getIterationCount();
int epochCount = mlnConf.getEpochCount();
mln.getUpdater().update(mln, gradient[0], iterationCount, epochCount, batchSize, LayerWorkspaceMgr.noWorkspaces());

View File

@ -24,7 +24,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
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.inputs.InputType;
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");
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)
.l2(conf.getL2())
.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)
.build());
confB.setInputType(InputType.convolutional(shapeInputs[1], shapeInputs[2], shapeInputs[0]));
MultiLayerConfiguration mlnconf = confB.build();
confB.inputType(InputType.convolutional(shapeInputs[1], shapeInputs[2], shapeInputs[0]));
NeuralNetConfiguration mlnconf = confB.build();
MultiLayerNetwork model = new MultiLayerNetwork(mlnconf);
model.init();
if (conf.getListeners() != null) {

View File

@ -24,7 +24,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
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.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -54,7 +54,7 @@ public class DQNFactoryStdDense implements DQNFactory {
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)
.updater(conf.getUpdater() != null ? conf.getUpdater() : new Adam())
.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);
model.init();
if (conf.getListeners() != null) {

View File

@ -134,7 +134,7 @@ public class NStepRnn {
}
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)
.updater(new Adam())
.weightInit(WeightInit.XAVIER)

View File

@ -188,7 +188,7 @@ public class RobotLakeExample {
}
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)
.updater(new Adam())
.weightInit(WeightInit.XAVIER)

View File

@ -174,7 +174,7 @@ public class TMazeExample {
}
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)
.updater(new Adam())
.weightInit(WeightInit.XAVIER)

View File

@ -21,7 +21,7 @@
package org.deeplearning4j.rl4j.network;
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.layers.recurrent.RnnOutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
@ -52,7 +52,7 @@ public class MultiLayerNetworkHandlerTest {
private MultiLayerNetwork modelMock;
private TrainingListener trainingListenerMock;
private MultiLayerConfiguration configurationMock;
private NeuralNetConfiguration configurationMock;
private MultiLayerNetworkHandler sut;
@ -60,10 +60,10 @@ public class MultiLayerNetworkHandlerTest {
modelMock = mock(MultiLayerNetwork.class);
trainingListenerMock = mock(TrainingListener.class);
configurationMock = mock(MultiLayerConfiguration.class);
configurationMock = mock(NeuralNetConfiguration.class);
when(configurationMock.getIterationCount()).thenReturn(123);
when(configurationMock.getEpochCount()).thenReturn(234);
when(modelMock.getLayerWiseConfigurations()).thenReturn(configurationMock);
when(modelMock.getConfiguration()).thenReturn(configurationMock);
if(setupRecurrent) {
when(modelMock.getOutputLayer()).thenReturn(new RnnOutputLayer(null, null));

View File

@ -166,9 +166,9 @@ public class PolicyTest {
@Test
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());
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());
ACPolicy policy = new ACPolicy(new DummyAC(mln), true, Nd4j.getRandom());

View File

@ -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.
```java
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(seed)
.l2(0.0005)
.weightInit(WeightInit.XAVIER)
.updater(new Adam(1e-3))
.list()
.layer(new ConvolutionLayer.Builder(5, 5)
.stride(1,1)
.nOut(20)
@ -78,7 +78,7 @@ MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.nOut(outputNum)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.convolutionalFlat(28,28,1))
.inputType(InputType.convolutionalFlat(28,28,1))
.build();
```

View File

@ -21,15 +21,21 @@
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 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 okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
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.image.loader.NativeImageLoader;
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.PipelineImageTransform;
import org.datavec.image.transform.ResizeImageTransform;
import org.datavec.image.transform.ScaleImageTransform;
import org.datavec.image.transform.ShowImageTransform;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
import org.deeplearning4j.nn.conf.GradientNormalization;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
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.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.weightnoise.WeightNoise;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.nn.weights.WeightInitXavier;
import org.deeplearning4j.optimize.listeners.PerformanceListener;
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.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.activations.impl.ActivationLReLU;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;
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.learning.config.Adam;
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;
@Slf4j
@ -95,8 +93,8 @@ public class App {
private static JPanel panel;
private static JPanel panel2;
private static Layer[] genLayers() {
return new Layer[] {
private static LayerConfiguration[] genLayers() {
return new LayerConfiguration[] {
new DenseLayer.Builder().nIn(INPUT).nOut(X_DIM*Y_DIM*CHANNELS).weightInit(WeightInit.NORMAL).build(),
new ActivationLayer.Builder(new ActivationLReLU(0.2)).build(),
new DenseLayer.Builder().nIn(X_DIM*Y_DIM*CHANNELS).nOut(X_DIM*Y_DIM).build(),
@ -113,23 +111,26 @@ public class App {
*
* @return config
*/
private static MultiLayerConfiguration generator() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
private static NeuralNetConfiguration generator() {
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(42)
.updater(UPDATER)
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
//.weightInit(WeightInit.XAVIER)
.weightInit(WeightInit.XAVIER)
.activation(Activation.IDENTITY)
.list(genLayers())
.setInputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
.layersFromArray(genLayers())
.inputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
// .inputPreProcessor("CNN1", new FeedForwardToCnnPreProcessor(Y_DIM, X_DIM, CHANNELS))
.build();
((NeuralNetConfiguration) conf).init();
return conf;
}
private static Layer[] disLayers() {
return new Layer[]{
private static LayerConfiguration[] disLayers() {
return new LayerConfiguration[]{
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 DropoutLayer.Builder(1 - 0.5).build(),
@ -146,44 +147,51 @@ public class App {
};
}
private static MultiLayerConfiguration discriminator() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
private static NeuralNetConfiguration discriminator() {
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(42)
.updater(UPDATER)
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
.weightInit(WeightInit.XAVIER)
//.weightInitFn(new WeightInitXavier())
//.activationFn(new ActivationIdentity())
.activation(Activation.IDENTITY)
.list(disLayers())
.setInputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
.layersFromArray(disLayers())
.inputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
.build();
((NeuralNetConfiguration) conf).init();
return conf;
}
private static MultiLayerConfiguration gan() {
Layer[] genLayers = genLayers();
Layer[] disLayers = Arrays.stream(disLayers())
private static NeuralNetConfiguration gan() {
LayerConfiguration[] genLayers = genLayers();
LayerConfiguration[] disLayers = Arrays.stream(disLayers())
.map((layer) -> {
if (layer instanceof DenseLayer || layer instanceof OutputLayer) {
return new FrozenLayerWithBackprop(layer);
} else {
return layer;
}
}).toArray(Layer[]::new);
Layer[] layers = ArrayUtils.addAll(genLayers, disLayers);
}).toArray(LayerConfiguration[]::new);
LayerConfiguration[] layers = ArrayUtils.addAll(genLayers, disLayers);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(42)
.updater(UPDATER)
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold(GRADIENT_THRESHOLD)
.weightInit(WeightInit.XAVIER)
.activation(Activation.IDENTITY)
.list(layers)
.setInputType(InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
.updater( Adam.builder().learningRate(0.0002).beta1(0.5).build() )
.gradientNormalization( GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold( 100 )
//.weightInitFn( new WeightInitXavier() ) //this is internal
.weightNoise(new WeightNoise(new NormalDistribution(0.5, 0.5)))
.weightInit( WeightInit.XAVIER)
//.activationFn( new ActivationIdentity()) //this is internal
.activation( Activation.IDENTITY )
.layersFromArray( layers )
.inputType( InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
.build();
((NeuralNetConfiguration) conf).init();
return conf;
}
@ -194,6 +202,8 @@ public class App {
}
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);
// MnistDataSetIterator trainData = new MnistDataSetIterator(128, true, 45);
@ -219,16 +229,17 @@ public class App {
MultiLayerNetwork gen = new MultiLayerNetwork(generator());
MultiLayerNetwork dis = new MultiLayerNetwork(discriminator());
MultiLayerNetwork gan = new MultiLayerNetwork(gan());
gen.init();
dis.init();
gan.init();
gen.init(); log.debug("Generator network: {}", gen);
dis.init(); log.debug("Discriminator network: {}", dis);
gan.init(); log.debug("Complete GAN network: {}", gan);
copyParams(gen, dis, gan);
//gen.setListeners(new PerformanceListener(10, true));
//dis.setListeners(new PerformanceListener(10, true));
//gan.setListeners(new PerformanceListener(10, true));
gan.setListeners(new ScoreToChartListener("gan"));
gen.addTrainingListeners(new PerformanceListener(10, true));
dis.addTrainingListeners(new PerformanceListener(10, true));
gan.addTrainingListeners(new PerformanceListener(10, true));
gan.addTrainingListeners(new ScoreToChartListener("gan"));
//dis.setListeners(new ScoreToChartListener("dis"));
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;
for (int i = 0; i < gan.getLayers().length; i++) {
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 {
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) {
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) {
int genLayerCount = gen.getLayers().length;
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());
}
}

View File

@ -25,6 +25,7 @@ import org.apache.commons.lang3.ArrayUtils;
import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.*;
import org.deeplearning4j.nn.conf.layers.LayerConfiguration;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.optimize.api.BaseTrainingListener;
import org.nd4j.evaluation.classification.Evaluation;
@ -114,15 +115,15 @@ public class GAN {
public void setGeneratorListeners(BaseTrainingListener[] listeners) {
generator.setListeners(listeners);
generator.addTrainingListeners(listeners);
}
public void setDiscriminatorListeners(BaseTrainingListener[] listeners) {
discriminator.setListeners(listeners);
discriminator.addTrainingListeners(listeners);
}
public void setGanListeners(BaseTrainingListener[] listeners) {
gan.setListeners(listeners);
gan.addTrainingListeners(listeners);
}
public void fit(DataSetIterator realData, int numEpochs) {
@ -199,13 +200,13 @@ public class GAN {
Layer[] disLayers = ganDiscriminator.getLayers();
Layer[] layers = ArrayUtils.addAll(genLayers, disLayers);
MultiLayerConfiguration genConf = generator.getLayerWiseConfigurations();
MultiLayerConfiguration disConf = ganDiscriminator.getLayerWiseConfigurations();
org.deeplearning4j.nn.conf.layers.Layer[] confLayers = new org.deeplearning4j.nn.conf.layers.Layer[layers.length];
NeuralNetConfiguration genConf = generator.getNetConfiguration();
NeuralNetConfiguration disConf = ganDiscriminator.getNetConfiguration();
LayerConfiguration[] confLayers = new LayerConfiguration[layers.length];
Map<Integer, InputPreProcessor> preProcessors = new HashMap<>();
for (int i = 0; i < layers.length; i++) {
confLayers[i] = layers[i].conf().getLayer();
confLayers[i] = layers[i].getLayerConfiguration();
if (i < numGenLayers) {
preProcessors.put(i, genConf.getInputPreProcess(i));
} else {
@ -213,7 +214,7 @@ public class GAN {
}
}
MultiLayerConfiguration ganConf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration ganConf = NeuralNetConfiguration.builder()
.seed(seed)
.updater(updater)
.biasUpdater(biasUpdater)
@ -224,7 +225,7 @@ public class GAN {
.trainingWorkspaceMode(trainingWorkSpaceMode)
.inferenceWorkspaceMode(inferenceWorkspaceMode)
.cacheMode(cacheMode)
.list(confLayers)
.layersFromArray(confLayers)
.inputPreProcessors(preProcessors)
.build();
gan = new MultiLayerNetwork(ganConf);
@ -238,9 +239,9 @@ public class GAN {
int genLayerCount = generator.getLayers().length;
for (int i = 0; i < gan.getLayers().length; i++) {
if (i < genLayerCount) {
generator.getLayer(i).setParams(gan.getLayer(i).params());
generator.getLayer(i).setParams(gan.getLayer(i).getParams());
} 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() {
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() {
int genLayerCount = generator.getLayers().length;
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>
*/
public static class Builder implements Cloneable {

View File

@ -100,7 +100,7 @@ public class MnistDCGANExample {
public static void main(String[] args) throws Exception {
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)
.activation(Activation.LEAKYRELU).weightInit(WeightInit.NORMAL).build())
.layer(1, new Convolution2D.Builder().nIn(128).nOut(128).kernelSize(5, 5)
@ -119,16 +119,16 @@ public class MnistDCGANExample {
.inputPreProcessor(1,
new FeedForwardToCnnPreProcessor(height / 2, width / 2, 128))
.inputPreProcessor(6, new CnnToFeedForwardPreProcessor(height, width, channels))
.setInputType(InputType.feedForward(latentDim))
.inputType(InputType.feedForward(latentDim))
.build());
};
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())
//.gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)
//.gradientNormalizationThreshold(100.0)
.list()
.layer(0, new Convolution2D.Builder().nIn(channels).nOut(64).kernelSize(3, 3)
.activation(Activation.LEAKYRELU).build())
.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())
.inputPreProcessor(0, new FeedForwardToCnnPreProcessor(height, width, channels))
.inputPreProcessor(4, new CnnToFeedForwardPreProcessor(2, 2, 64))
.setInputType(InputType.convolutionalFlat(height, width, channels))
.inputType(InputType.convolutionalFlat(height, width, channels))
.build());
};
@ -155,8 +155,8 @@ public class MnistDCGANExample {
.updater(new RmsProp.Builder().learningRate(0.0008).rmsDecay(1e-8).build())
.build();
gan.getGenerator().setListeners(new PerformanceListener(1, true));
gan.getDiscriminator().setListeners(new PerformanceListener(1, true));
gan.getGenerator().addTrainingListeners(new PerformanceListener(1, true));
gan.getDiscriminator().addTrainingListeners(new PerformanceListener(1, true));
Nd4j.getMemoryManager().setAutoGcWindow(15 * 1000);

View File

@ -23,7 +23,6 @@ package net.brutex.gan;
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
import org.deeplearning4j.nn.conf.GradientNormalization;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.ActivationLayer;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
@ -57,12 +56,12 @@ public class MnistSimpleGAN {
public static MultiLayerNetwork getGenerator() {
MultiLayerConfiguration genConf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration genConf = NeuralNetConfiguration.builder()
.weightInit(WeightInit.XAVIER)
.activation(Activation.IDENTITY)
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold(100)
.list()
.layer(new DenseLayer.Builder().nIn(100).nOut(256).weightInit(WeightInit.NORMAL).build())
.layer(new ActivationLayer.Builder(new ActivationLReLU(0.2)).build())
.layer(new DenseLayer.Builder().nIn(256).nOut(512).build())
@ -76,14 +75,14 @@ public class MnistSimpleGAN {
public static MultiLayerNetwork getDiscriminator(IUpdater updater) {
MultiLayerConfiguration discConf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration discConf = NeuralNetConfiguration.builder()
.seed(42)
.updater(updater)
.weightInit(WeightInit.XAVIER)
.activation(Activation.IDENTITY)
.gradientNormalization(GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold(100)
.list()
.layer(new DenseLayer.Builder().nIn(784).nOut(1024).updater(updater).build())
.layer(new ActivationLayer.Builder(new ActivationLReLU(0.2)).build())
.layer(new DropoutLayer.Builder(1 - 0.5).build())

View File

@ -35,7 +35,6 @@ import org.apache.spark.sql.RowFactory;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.types.DataTypes;
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.StructType;
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.schema.Schema;
import org.datavec.api.Writable;
import org.datavec.spark.transform.Normalization;
import org.datavec.spark.transform.SparkTransformExecutor;
import org.datavec.spark.transform.misc.StringToWritablesFunction;
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator;
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.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -287,15 +284,15 @@ public class BrianTest extends BaseSparkSessionTest {
//Define Network
MultiLayerConfiguration multiLayerConfiguration = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration multiLayerConfiguration = NeuralNetConfiguration.builder()
.seed(123)
.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(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())
.build();

View File

@ -37,7 +37,6 @@ import org.datavec.api.transform.schema.Schema;
import org.datavec.api.Writable;
import org.datavec.spark.transform.SparkTransformExecutor;
import org.datavec.spark.transform.misc.StringToWritablesFunction;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -295,13 +294,13 @@ public class BrianTest2 /*extends BaseDL4JTest*/ {
*/
//Define Network
MultiLayerConfiguration multiLayerConfiguration = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration multiLayerConfiguration = NeuralNetConfiguration.builder()
.seed(123)
.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(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())
.build();

View File

@ -21,7 +21,6 @@
package net.brutex.spark;
import lombok.extern.log4j.Log4j2;
//import net.brutex.ai.performance.storage.PostgresStatsStorage;
import lombok.extern.slf4j.Slf4j;
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.split.FileSplit;
import org.datavec.api.split.ListStringSplit;
import org.deeplearning4j.core.storage.StatsStorage;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
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.OutputLayer;
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
import org.deeplearning4j.nn.conf.preprocessor.RnnToFeedForwardPreProcessor;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.deeplearning4j.ui.api.UIServer;
import org.deeplearning4j.ui.model.stats.StatsListener;
import org.deeplearning4j.ui.model.storage.FileStatsStorage;
import org.junit.jupiter.api.AfterAll;
import org.deeplearning4j.ui.api.UIServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.nd4j.evaluation.classification.Evaluation;
@ -86,16 +80,16 @@ public class TestServer {
int i = 2000;
int numClasses = 10;
int numBatchSize = 100;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(1234)
.weightInit(WeightInit.XAVIER)
.updater(new Nesterovs.Builder().learningRate(0.15).build())
.activation(Activation.RELU)
.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(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(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())

View File

@ -21,7 +21,6 @@
package net.brutex.spark;
import lombok.extern.log4j.Log4j2;
//import net.brutex.ai.performance.storage.PostgresStatsStorage;
import lombok.extern.slf4j.Slf4j;
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.deeplearning4j.core.storage.StatsStorage;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
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.OutputLayer;
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
@ -122,16 +120,16 @@ public class TestServer2 {
int i = 2000;
int numClasses = 10;
int numBatchSize = 100;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(1234)
.weightInit(WeightInit.XAVIER)
.updater(new Nesterovs.Builder().learningRate(0.15).build())
.activation(Activation.RELU)
.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(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(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())
@ -207,7 +205,7 @@ public class TestServer2 {
//PostgresStatsStorage psqlStore = new PostgresStatsStorage();
int listenerFrequency = 2;
//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

View File

@ -21,14 +21,14 @@
package org.deeplearning4j.integration;
import lombok.extern.slf4j.Slf4j;
import net.brutex.ai.dnn.api.IModel;
import org.apache.commons.io.FileUtils;
import org.deeplearning4j.datasets.iterator.MultiDataSetWrapperIterator;
import org.deeplearning4j.integration.testcases.samediff.SameDiffCNNCases;
import org.deeplearning4j.integration.testcases.samediff.SameDiffMLPTestCases;
import org.deeplearning4j.integration.testcases.samediff.SameDiffRNNTestCases;
import org.deeplearning4j.nn.api.Model;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.optimize.listeners.CollectScoresListener;
@ -135,12 +135,12 @@ public class IntegrationTestBaselineGenerator {
MultiLayerNetwork mln = null;
ComputationGraph cg = null;
SameDiff sd = null;
Model m = null;
IModel m = null;
if (tc.getTestType() == TestCase.TestType.RANDOM_INIT) {
Object config = tc.getConfiguration();
String json = null;
if (config instanceof MultiLayerConfiguration) {
MultiLayerConfiguration mlc = (MultiLayerConfiguration) config;
if (config instanceof NeuralNetConfiguration) {
NeuralNetConfiguration mlc = (NeuralNetConfiguration) config;
json = mlc.toJson();
mln = new MultiLayerNetwork(mlc);
mln.init();
@ -284,21 +284,21 @@ public class IntegrationTestBaselineGenerator {
INDArray paramsPostTraining;
if (modelType == ModelType.MLN) {
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);
for (int i : layersToTrain) {
mln.pretrainLayer(i, dsi);
}
paramsPostTraining = mln.params();
paramsPostTraining = mln.getModelParams();
} else if (modelType == ModelType.CG) {
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) {
cg.pretrainLayer(i, iter);
}
paramsPostTraining = cg.params();
paramsPostTraining = cg.getModelParams();
} else {
throw new UnsupportedOperationException("SameDiff not supported for unsupervised training tests");
}
@ -314,7 +314,7 @@ public class IntegrationTestBaselineGenerator {
CollectScoresListener l = new CollectScoresListener(1);
if (modelType != ModelType.SAMEDIFF)
m.setListeners(l);
m.addTrainingListeners(l);
History h = null;
if (modelType == ModelType.MLN) {
@ -349,7 +349,7 @@ public class IntegrationTestBaselineGenerator {
}
} else {
File p = new File(testBaseDir, IntegrationTestRunner.PARAMS_POST_TRAIN_FILENAME);
IntegrationTestRunner.write(m.params(), p);
IntegrationTestRunner.write(m.getModelParams(), p);
}
}
}

View File

@ -25,18 +25,18 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.brutex.ai.dnn.api.IModel;
import org.apache.commons.io.FileUtils;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.common.config.DL4JClassLoading;
import org.deeplearning4j.datasets.iterator.MultiDataSetWrapperIterator;
import org.deeplearning4j.integration.util.CountingMultiDataSetIterator;
import org.deeplearning4j.nn.api.Model;
import org.deeplearning4j.nn.conf.BackpropType;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
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.layers.Layer;
import org.deeplearning4j.nn.conf.layers.LayerConfiguration;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.graph.vertex.GraphVertex;
import org.deeplearning4j.nn.layers.BaseOutputLayer;
@ -177,22 +177,22 @@ public class IntegrationTestRunner {
MultiLayerNetwork mln = null;
ComputationGraph cg = null;
SameDiff sd = null;
Model m = null;
IModel m = null;
if (tc.getTestType() == TestCase.TestType.RANDOM_INIT) {
log.info("Checking RANDOM_INIT test case: saved model vs. initialized model");
//Checking randomly initialized model:
File savedModel = new File(testBaseDir, IntegrationTestRunner.RANDOM_INIT_UNTRAINED_MODEL_FILENAME);
Object config = tc.getConfiguration();
if (config instanceof MultiLayerConfiguration) {
MultiLayerConfiguration mlc = (MultiLayerConfiguration) config;
if (config instanceof NeuralNetConfiguration) {
NeuralNetConfiguration mlc = (NeuralNetConfiguration) config;
mln = new MultiLayerNetwork(mlc);
mln.init();
m = mln;
MultiLayerNetwork loaded = MultiLayerNetwork.load(savedModel, true);
assertEquals(loaded.getLayerWiseConfigurations(), mln.getLayerWiseConfigurations(), "Configs not equal");
assertEquals( loaded.params(), mln.params(), "Params not equal");
assertEquals( loaded.paramTable(), mln.paramTable(), "Param table not equal");
assertEquals(loaded.getNetConfiguration(), mln.getNetConfiguration(), "Configs not equal");
assertEquals( loaded.getModelParams(), mln.getModelParams(), "Params not equal");
assertEquals( loaded.getParamTable(), mln.getParamTable(), "Param table not equal");
} else if(config instanceof ComputationGraphConfiguration ){
ComputationGraphConfiguration cgc = (ComputationGraphConfiguration) config;
cg = new ComputationGraph(cgc);
@ -200,9 +200,9 @@ public class IntegrationTestRunner {
m = cg;
ComputationGraph loaded = ComputationGraph.load(savedModel, true);
assertEquals(loaded.getConfiguration(), cg.getConfiguration(), "Configs not equal" );
assertEquals( loaded.params(), cg.params(), "Params not equal");
assertEquals(loaded.paramTable(), cg.paramTable(), "Param table not equal");
assertEquals(loaded.getComputationGraphConfiguration(), cg.getComputationGraphConfiguration(), "Configs not equal" );
assertEquals( loaded.getModelParams(), cg.getModelParams(), "Params not equal");
assertEquals(loaded.getParamTable(), cg.getParamTable(), "Param table not equal");
} else if(config instanceof SameDiff){
sd = (SameDiff)config;
SameDiff loaded = SameDiff.load(savedModel, true);
@ -383,22 +383,22 @@ public class IntegrationTestRunner {
org.deeplearning4j.nn.api.Layer[] layers;
if(modelType == ModelType.MLN){
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);
for( int i : layersToTrain){
mln.pretrainLayer(i, dsi);
}
paramsPostTraining = mln.params();
paramsPostTraining = mln.getModelParams();
layers = mln.getLayers();
} else if(modelType == ModelType.CG) {
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){
cg.pretrainLayer(i, iter);
}
paramsPostTraining = cg.params();
paramsPostTraining = cg.getModelParams();
layers = cg.getLayers();
} else {
throw new UnsupportedOperationException("Unsupported layerwise pretraining not supported for SameDiff models");
@ -426,11 +426,11 @@ public class IntegrationTestRunner {
boolean isTbptt;
int tbpttLength;
if(modelType == ModelType.MLN){
isTbptt = mln.getLayerWiseConfigurations().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = mln.getLayerWiseConfigurations().getTbpttFwdLength();
isTbptt = mln.getNetConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = mln.getNetConfiguration().getTbpttFwdLength();
} else if(modelType == ModelType.CG) {
isTbptt = cg.getConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = cg.getConfiguration().getTbpttFwdLength();
isTbptt = cg.getComputationGraphConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = cg.getComputationGraphConfiguration().getTbpttFwdLength();
} else {
isTbptt = false;
tbpttLength = 0;
@ -439,7 +439,7 @@ public class IntegrationTestRunner {
CountingMultiDataSetIterator countingIter = new CountingMultiDataSetIterator(trainData, isTbptt, tbpttLength);
CollectScoresListener l = new CollectScoresListener(1);
if(modelType != ModelType.SAMEDIFF) {
m.setListeners(l);
m.addTrainingListeners(l);
}
int iterBefore;
@ -458,11 +458,11 @@ public class IntegrationTestRunner {
epochAfter = mln.getEpochCount();
layers = mln.getLayers();
} else if(modelType == ModelType.CG){
iterBefore = cg.getConfiguration().getIterationCount();
epochBefore = cg.getConfiguration().getEpochCount();
iterBefore = cg.getComputationGraphConfiguration().getIterationCount();
epochBefore = cg.getComputationGraphConfiguration().getEpochCount();
cg.fit(countingIter);
iterAfter = cg.getConfiguration().getIterationCount();
epochAfter = cg.getConfiguration().getEpochCount();
iterAfter = cg.getComputationGraphConfiguration().getIterationCount();
epochAfter = cg.getComputationGraphConfiguration().getEpochCount();
layers = cg.getLayers();
} else {
iterBefore = sd.getTrainingConfig().getIterationCount();
@ -519,10 +519,10 @@ public class IntegrationTestRunner {
if(modelType != ModelType.SAMEDIFF) {
File p = new File(testBaseDir, IntegrationTestRunner.PARAMS_POST_TRAIN_FILENAME);
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();
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");
} else {
@ -606,13 +606,13 @@ public class IntegrationTestRunner {
if (modelType == ModelType.MLN) {
ModelSerializer.writeModel(m, f, true);
MultiLayerNetwork restored = MultiLayerNetwork.load(f, true);
assertEquals(mln.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
assertEquals(mln.params(), restored.params());
assertEquals(mln.getNetConfiguration(), restored.getNetConfiguration());
assertEquals(mln.getModelParams(), restored.getModelParams());
} else if(modelType == ModelType.CG){
ModelSerializer.writeModel(m, f, true);
ComputationGraph restored = ComputationGraph.load(f, true);
assertEquals(cg.getConfiguration(), restored.getConfiguration());
assertEquals(cg.params(), restored.params());
assertEquals(cg.getComputationGraphConfiguration(), restored.getComputationGraphConfiguration());
assertEquals(cg.getModelParams(), restored.getModelParams());
} else {
sd.save(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
private static void collectCoverageInformation(Model m){
private static void collectCoverageInformation(IModel m){
boolean isMLN = (m instanceof MultiLayerNetwork);
MultiLayerNetwork mln = (isMLN ? (MultiLayerNetwork)m : null);
ComputationGraph cg = (!isMLN ? (ComputationGraph)m : null);
@ -735,17 +735,17 @@ public class IntegrationTestRunner {
layers = cg.getLayers();
}
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);
}
//Collect preprocessor coverage information:
Collection<InputPreProcessor> preProcessors;
if (isMLN) {
preProcessors = mln.getLayerWiseConfigurations().getInputPreProcessors().values();
preProcessors = mln.getNetConfiguration().getInputPreProcessors().values();
} else {
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) {
InputPreProcessor pp = ((LayerVertex) gv).getPreProcessor();
if (pp != null) {
@ -760,14 +760,14 @@ public class IntegrationTestRunner {
//Collect vertex coverage information
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);
}
}
}
private static void checkLayerClearance(Model m) {
private static void checkLayerClearance(IModel m) {
//Check that the input fields for all layers have been cleared
org.deeplearning4j.nn.api.Layer[] layers;
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
org.deeplearning4j.nn.api.Layer[] layers;
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<>();
org.deeplearning4j.nn.api.Layer[] layers;
if (m instanceof MultiLayerNetwork) {
@ -832,9 +832,9 @@ public class IntegrationTestRunner {
if(m instanceof MultiLayerNetwork){
paramPrefix = l.getIndex() + "_";
} 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()){
out.put(paramPrefix + e.getKey(), e.getValue().dup());
}
@ -854,7 +854,7 @@ public class IntegrationTestRunner {
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()){
INDArray actual = m.getParam(e.getKey());
assertEquals(e.getValue(), actual, e.getKey());
@ -872,14 +872,14 @@ public class IntegrationTestRunner {
log.info("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
log.info("Layer coverage - classes seen:");
log.info("ILayer coverage - classes seen:");
for (Class<?> c : layerClasses) {
if (layerConfClassesSeen.containsKey(c)) {
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) {
if (!layerConfClassesSeen.containsKey(c)) {
log.info("Class NOT seen in any tests: {}", c.getName());
@ -939,7 +939,7 @@ public class IntegrationTestRunner {
}
private static boolean isLayerConfig(Class<?> c) {
return Layer.class.isAssignableFrom(c);
return LayerConfiguration.class.isAssignableFrom(c);
}
private static boolean isPreprocessorConfig(Class<?> c) {
@ -1088,7 +1088,7 @@ public class IntegrationTestRunner {
if(pSoFar + n < i){
pSoFar += n;
} else {
for(Map.Entry<String,INDArray> e : l.paramTable().entrySet()){
for(Map.Entry<String,INDArray> e : l.getParamTable().entrySet()){
pSoFar += e.getValue().length();
if(pSoFar >= i){
pName = e.getKey();

View File

@ -21,7 +21,7 @@
package org.deeplearning4j.integration;
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.evaluation.IEvaluation;
import org.nd4j.linalg.api.ndarray.INDArray;
@ -89,7 +89,7 @@ public abstract class TestCase {
/**
* 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");
}

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.integration;
import org.apache.commons.compress.utils.IOUtils;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.util.ModelSerializer;
@ -48,15 +48,15 @@ public class TestUtils {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
assertEquals(net.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
assertEquals(net.params(), restored.params());
assertEquals(net.getNetConfiguration(), restored.getNetConfiguration());
assertEquals(net.getModelParams(), restored.getModelParams());
} catch (IOException e){
//Should never happen
throw new RuntimeException(e);
}
//Also check the MultiLayerConfiguration is serializable (required by Spark etc)
MultiLayerConfiguration conf = net.getLayerWiseConfigurations();
//Also check the NeuralNetConfiguration is serializable (required by Spark etc)
NeuralNetConfiguration conf = net.getNetConfiguration();
serializeDeserializeJava(conf);
return restored;
@ -73,15 +73,15 @@ public class TestUtils {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
restored = ModelSerializer.restoreComputationGraph(bais, true);
assertEquals(net.getConfiguration(), restored.getConfiguration());
assertEquals(net.params(), restored.params());
assertEquals(net.getComputationGraphConfiguration(), restored.getComputationGraphConfiguration());
assertEquals(net.getModelParams(), restored.getModelParams());
} catch (IOException e){
//Should never happen
throw new RuntimeException(e);
}
//Also check the ComputationGraphConfiguration is serializable (required by Spark etc)
ComputationGraphConfiguration conf = net.getConfiguration();
ComputationGraphConfiguration conf = net.getComputationGraphConfiguration();
serializeDeserializeJava(conf);
return restored;

View File

@ -80,12 +80,12 @@ public class CNN1DTestCases {
CharacterIterator iter = CharacterIterator.getShakespeareIterator(miniBatchSize,exampleLength);
int nOut = iter.totalOutcomes();
return new NeuralNetConfiguration.Builder()
return ((NeuralNetConfiguration.NeuralNetConfigurationBuilder)NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.weightInit(WeightInit.XAVIER)
.updater(new Adam(0.01))
.convolutionMode(ConvolutionMode.Same)
.convolutionMode(ConvolutionMode.Same))
.graphBuilder()
.addInputs("in")
.layer("0", new Convolution1DLayer.Builder().nOut(32).activation(Activation.TANH).kernelSize(3).stride(1).build(), "in")

View File

@ -32,7 +32,7 @@ import org.deeplearning4j.datasets.fetchers.DataSetType;
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
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.conf.*;
import org.deeplearning4j.nn.conf.inputs.InputType;
@ -98,13 +98,13 @@ public class CNN2DTestCases {
int outputNum = 10; // The number of possible outcomes
int seed = 123;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(seed)
.l2(0.0005)
.weightInit(WeightInit.XAVIER)
.updater(new Nesterovs(0.01, 0.9))
.list()
.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(nChannels)
@ -132,7 +132,7 @@ public class CNN2DTestCases {
.nOut(outputNum)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
.inputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
.build();
return conf;
@ -207,7 +207,7 @@ public class CNN2DTestCases {
}
@Override
public Model getPretrainedModel() throws Exception {
public IModel getPretrainedModel() throws Exception {
VGG16 vgg16 = VGG16.builder()
.seed(12345)
.build();
@ -294,7 +294,7 @@ public class CNN2DTestCases {
}
@Override
public Model getPretrainedModel() throws Exception {
public IModel getPretrainedModel() throws Exception {
int nClasses = 10;
int nBoxes = 5;
double lambdaNoObj = 0.5;
@ -403,20 +403,20 @@ public class CNN2DTestCases {
}
@Override
public Model getPretrainedModel() throws Exception {
public IModel getPretrainedModel() throws Exception {
Map<Integer, Double> lrSchedule = new HashMap<>();
lrSchedule.put(0, 0.01);
lrSchedule.put(1000, 0.005);
lrSchedule.put(3000, 0.001);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.l2(0.0005)
.weightInit(WeightInit.XAVIER)
.updater(new Nesterovs(0.01, 0.9))
.list()
.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(1)
@ -446,7 +446,7 @@ public class CNN2DTestCases {
.nOut(10)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
.inputType(InputType.convolutionalFlat(28, 28, 1)) //See note below
.build();

View File

@ -24,7 +24,6 @@ import org.deeplearning4j.datasets.iterator.impl.SingletonMultiDataSetIterator;
import org.deeplearning4j.integration.ModelType;
import org.deeplearning4j.integration.TestCase;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.Convolution3D;
@ -76,13 +75,13 @@ public class CNN3DTestCases {
int outputNum = 10; // The number of possible outcomes
int seed = 123;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(seed)
.l2(0.0005)
.weightInit(WeightInit.XAVIER)
.updater(new Nesterovs(0.01, 0.9))
.convolutionMode(ConvolutionMode.Same)
.list()
.layer(new Convolution3D.Builder(3,3,3)
.dataFormat(Convolution3D.DataFormat.NCDHW)
.nIn(nChannels)
@ -98,7 +97,7 @@ public class CNN3DTestCases {
.nOut(outputNum)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.convolutional3D(8,8,8,nChannels))
.inputType(InputType.convolutional3D(8,8,8,nChannels))
.build();
return conf;

View File

@ -28,7 +28,6 @@ import org.datavec.api.split.FileSplit;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
@ -93,7 +92,7 @@ public class MLPTestCases {
@Override
public Object getConfiguration() {
return new NeuralNetConfiguration.Builder()
return NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.updater(new Adam(new MapSchedule.Builder(ScheduleType.ITERATION)
@ -104,13 +103,13 @@ public class MLPTestCases {
.add(14, 1e-2)
.build()))
.l1(1e-3).l2(1e-3)
.list()
.layer(new DenseLayer.Builder().activation(Activation.TANH).nOut(64).build())
.layer(new OutputLayer.Builder().nOut(10)
.lossFunction(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.convolutionalFlat(28,28,1))
.inputType(InputType.convolutionalFlat(28,28,1))
.build();
}
@ -198,11 +197,11 @@ public class MLPTestCases {
int numHiddenNodes = 20;
//log.info("Build model....");
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(seed)
.updater(new Nesterovs(learningRate, 0.9))
.list()
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes)
.weightInit(WeightInit.XAVIER)
.activation(Activation.RELU)

View File

@ -112,20 +112,20 @@ public class RNNTestCases {
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
return new NeuralNetConfiguration.Builder()
return NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.l2(0.001)
.weightInit(WeightInit.XAVIER)
.updater(new Adam(1e-3))
.list()
.layer(0, new LSTM.Builder().nIn(iter.inputColumns()).nOut(lstmLayerSize)
.activation(Activation.TANH).build())
.layer(1, new LSTM.Builder().nIn(lstmLayerSize).nOut(lstmLayerSize)
.activation(Activation.TANH).build())
.layer(2, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation(Activation.SOFTMAX) //MCXENT + softmax for classification
.nIn(lstmLayerSize).nOut(nOut).build())
.backpropType(BackpropType.TruncatedBPTT).tBPTTForwardLength(tbpttLength).tBPTTBackwardLength(tbpttLength)
.backpropType(BackpropType.TruncatedBPTT).tbpttFwdLength(tbpttLength).tbpttBackLength(tbpttLength)
.build();
}
@ -195,19 +195,19 @@ public class RNNTestCases {
@Override
public Object getConfiguration() throws Exception {
return new NeuralNetConfiguration.Builder()
return NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.updater(new Adam(5e-2))
.l1(1e-3).l2(1e-3)
.list()
.layer(0, new LSTM.Builder().activation(Activation.TANH).nOut(10).build())
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
.layer(new OutputLayer.Builder().nOut(6)
.lossFunction(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.recurrent(1))
.inputType(InputType.recurrent(1))
.build();
}
@ -316,19 +316,19 @@ public class RNNTestCases {
@Override
public Object getConfiguration() throws Exception {
return new NeuralNetConfiguration.Builder()
return NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.updater(new Adam(5e-2))
.l1(1e-3).l2(1e-3)
.list()
.layer(0, new Bidirectional(new LSTM.Builder().activation(Activation.TANH).nOut(10).build()))
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
.layer(new OutputLayer.Builder().nOut(6)
.lossFunction(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.recurrent(1))
.inputType(InputType.recurrent(1))
.build();
}

View File

@ -72,13 +72,13 @@ public class UnsupervisedTestCases {
@Override
public Object getConfiguration() {
return new NeuralNetConfiguration.Builder()
return NeuralNetConfiguration.builder()
.dataType(DataType.FLOAT)
.seed(12345)
.updater(new Adam(1e-3))
.weightInit(WeightInit.XAVIER)
.l2(1e-4)
.list()
.layer(0, new VariationalAutoencoder.Builder()
.activation(Activation.TANH)
.encoderLayerSizes(256, 256) //2 encoder layers, each of size 256

View File

@ -44,6 +44,7 @@ ext {
scalaVersion = "2.12"
logger.quiet("Scala main version is set to {}", scalaVersion)
logger.quiet("Running java {}", JavaVersion.current())
}
configurations.all {
@ -64,10 +65,10 @@ allprojects { Project proj ->
plugins.withType(JavaPlugin) {
sourceCompatibility = 11
targetCompatibility = 1.8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
tasks.withType(JavaCompile) {
options.release = 8
options.release = 11
}
dependencies {
@ -85,7 +86,6 @@ allprojects { Project proj ->
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
implementation "org.slf4j:slf4j-api"
implementation "org.slf4j:slf4j-simple"
@ -107,17 +107,20 @@ allprojects { Project proj ->
}
plugins.withType(MavenPublishPlugin) {
publishing {
publications {
if(! proj.name.contains("cavis-full")) {
mavenJava(MavenPublication) {
/* Need to verify the property exists, as some
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
}
}
}
}
repositories {
maven {

View File

@ -26,7 +26,7 @@ import org.nd4j.common.primitives.Pair;
import org.nd4j.linalg.activations.BaseActivationFunction;
import org.nd4j.linalg.api.ndarray.INDArray;
/**
/** The ActivationIdentity activation function, just returns the input as is.
* f(x) = x
*/
@EqualsAndHashCode(callSuper = false)

View File

@ -195,7 +195,7 @@ public abstract class BaseWorkspaceMgr<T extends Enum<T>> implements WorkspaceMg
}
@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);
if(scopeOutOfWs.contains(arrayType)){

View File

@ -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.
* 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
*/
@ -120,7 +120,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
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
* @param arrayType Array type to check
* @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;
/**
* 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
* @param arrayType Array type to check
* @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).
* 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 dataType Data type of the created array
* @param shape Shape
@ -231,7 +231,7 @@ public interface WorkspaceMgr<T extends Enum<T>> {
/**
* 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 = true && toCast.dataType() == dataType: duplicate the array into the specified workspace<br>
* @param arrayType Array type

View File

@ -19,6 +19,7 @@ dependencies {
testImplementation projects.cavisNative.cavisNativeCommon
testImplementation projects.cavisNd4j.cavisNd4jCommonTests
testImplementation projects.cavisDnn.cavisDnnCommonTests
testImplementation projects.cavisDnn.cavisDnnNn
implementation "org.apache.commons:commons-lang3"

View File

@ -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;
}
}

View File

@ -23,8 +23,8 @@ package org.deeplearning4j.core.listener;
import lombok.NonNull;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import net.brutex.ai.dnn.api.IModel;
import org.apache.commons.io.FileUtils;
import org.deeplearning4j.nn.api.Model;
import org.deeplearning4j.optimize.api.TrainingListener;
import org.nd4j.linalg.api.ndarray.INDArray;
import oshi.json.SystemInfo;
@ -56,12 +56,12 @@ public class SystemInfoFilePrintListener implements TrainingListener {
}
@Override
public void iterationDone(Model model, int iteration, int epoch) {
public void iterationDone(IModel model, int iteration, int epoch) {
}
@Override
public void onEpochStart(Model model) {
public void onEpochStart(IModel model) {
if(!printOnEpochStart || printFileTarget == null)
return;
@ -70,7 +70,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
}
@Override
public void onEpochEnd(Model model) {
public void onEpochEnd(IModel model) {
if(!printOnEpochEnd || printFileTarget == null)
return;
@ -79,7 +79,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
}
@Override
public void onForwardPass(Model model, List<INDArray> activations) {
public void onForwardPass(IModel model, List<INDArray> activations) {
if(!printOnBackwardPass || printFileTarget == null)
return;
@ -88,7 +88,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
}
@Override
public void onForwardPass(Model model, Map<String, INDArray> activations) {
public void onForwardPass(IModel model, Map<String, INDArray> activations) {
if(!printOnForwardPass || printFileTarget == null)
return;
@ -97,7 +97,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
}
@Override
public void onGradientCalculation(Model model) {
public void onGradientCalculation(IModel model) {
if(!printOnGradientCalculation || printFileTarget == null)
return;
@ -107,7 +107,7 @@ public class SystemInfoFilePrintListener implements TrainingListener {
}
@Override
public void onBackwardPass(Model model) {
public void onBackwardPass(IModel model) {
if(!printOnBackwardPass || printFileTarget == null)
return;

View File

@ -22,7 +22,7 @@ package org.deeplearning4j.core.listener;
import lombok.Builder;
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.nd4j.linalg.api.ndarray.INDArray;
import oshi.json.SystemInfo;
@ -49,12 +49,12 @@ public class SystemInfoPrintListener implements TrainingListener {
private static final String SYSTEM_INFO = "System info on epoch end: ";
@Override
public void iterationDone(Model model, int iteration, int epoch) {
public void iterationDone(IModel model, int iteration, int epoch) {
}
@Override
public void onEpochStart(Model model) {
public void onEpochStart(IModel model) {
if(!printOnEpochStart)
return;
@ -64,7 +64,7 @@ public class SystemInfoPrintListener implements TrainingListener {
}
@Override
public void onEpochEnd(Model model) {
public void onEpochEnd(IModel model) {
if(!printOnEpochEnd)
return;
@ -74,7 +74,7 @@ public class SystemInfoPrintListener implements TrainingListener {
}
@Override
public void onForwardPass(Model model, List<INDArray> activations) {
public void onForwardPass(IModel model, List<INDArray> activations) {
if(!printOnBackwardPass)
return;
@ -84,7 +84,7 @@ public class SystemInfoPrintListener implements TrainingListener {
}
@Override
public void onForwardPass(Model model, Map<String, INDArray> activations) {
public void onForwardPass(IModel model, Map<String, INDArray> activations) {
if(!printOnForwardPass)
return;
@ -94,7 +94,7 @@ public class SystemInfoPrintListener implements TrainingListener {
}
@Override
public void onGradientCalculation(Model model) {
public void onGradientCalculation(IModel model) {
if(!printOnGradientCalculation)
return;
@ -104,7 +104,7 @@ public class SystemInfoPrintListener implements TrainingListener {
}
@Override
public void onBackwardPass(Model model) {
public void onBackwardPass(IModel model) {
if(!printOnBackwardPass)
return;
SystemInfo systemInfo = new SystemInfo();

View File

@ -21,13 +21,13 @@
package org.deeplearning4j.core.util;
import lombok.extern.slf4j.Slf4j;
import net.brutex.ai.dnn.api.IModel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.deeplearning4j.common.util.DL4JFileUtils;
import org.deeplearning4j.common.config.DL4JSystemProperties;
import org.deeplearning4j.nn.api.Model;
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.util.ModelSerializer;
import org.nd4j.linalg.dataset.api.preprocessor.Normalizer;
@ -80,7 +80,7 @@ public class ModelGuesser {
//note here that we load json BEFORE YAML. YAML
//turns out to load just fine *accidentally*
try {
return MultiLayerConfiguration.fromJson(input);
return NeuralNetConfiguration.fromJson(input);
} catch (Exception e) {
log.warn("Tried multi layer config from json", e);
try {
@ -96,7 +96,7 @@ public class ModelGuesser {
} catch (Exception e3) {
log.warn("Tried computation graph from json");
try {
return MultiLayerConfiguration.fromYaml(input);
return NeuralNetConfiguration.fromYaml(input);
} catch (Exception e4) {
log.warn("Tried multi layer configuration from yaml");
try {
@ -142,7 +142,7 @@ public class ModelGuesser {
* @return the loaded model
* @throws Exception
*/
public static Model loadModelGuess(String path) throws Exception {
public static IModel loadModelGuess(String path) throws Exception {
try {
return ModelSerializer.restoreMultiLayerNetwork(new File(path), true);
} catch (Exception e) {
@ -185,7 +185,7 @@ public class ModelGuesser {
* @return the loaded model
* @throws Exception
*/
public static Model loadModelGuess(InputStream stream) throws Exception {
public static IModel loadModelGuess(InputStream stream) throws Exception {
return loadModelGuess(stream, null);
}
@ -194,7 +194,7 @@ public class ModelGuesser {
* @param stream Stream of the model file
* @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
//Simplest solution here: write to a temporary file
File f;

View File

@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.common.config.DL4JClassLoading;
import org.deeplearning4j.nn.api.Layer;
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.multilayer.MultiLayerNetwork;
import org.deeplearning4j.optimize.listeners.CollectScoresListener;
@ -99,7 +100,7 @@ public class LayerHelperValidationUtil {
//Don't allow fallback:
for(Layer l : netOrig.getLayers()){
org.deeplearning4j.nn.conf.layers.Layer lConf = l.conf().getLayer();
LayerConfiguration lConf = l.getLayerConfiguration();
if(lConf instanceof ConvolutionLayer){
((ConvolutionLayer) lConf).setCudnnAllowFallback(false);
} 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();
log.info("Removing all layer helpers from network copy 1");
removeHelpers(net1NoHelper.getLayers(), null);
MultiLayerNetwork net2With = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
MultiLayerNetwork net2With = new MultiLayerNetwork(netOrig.getNetConfiguration().clone());
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());
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
@ -123,7 +124,7 @@ public class LayerHelperValidationUtil {
Preconditions.checkNotNull(t.getFeatures(), "Features are not set (null)");
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: ");
List<INDArray> ff1;
try {
@ -133,7 +134,7 @@ public class LayerHelperValidationUtil {
enableCppHelpers();
}
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);
for (String p : paramKeys) {
INDArray p1 = net1NoHelper.getParam(p);
@ -179,7 +180,7 @@ public class LayerHelperValidationUtil {
double maxRE = relError.maxNumber().doubleValue();
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);
}
}
@ -224,7 +225,7 @@ public class LayerHelperValidationUtil {
}
net2With.computeGradientAndScore();
List<String> paramKeys = new ArrayList<>(net1NoHelper.paramTable().keySet());
List<String> paramKeys = new ArrayList<>(net1NoHelper.getParamTable().keySet());
Collections.sort(paramKeys);
for(String p : paramKeys){
INDArray g1 = net1NoHelper.gradient().gradientForVariable().get(p);
@ -252,26 +253,26 @@ public class LayerHelperValidationUtil {
Preconditions.checkNotNull(t.getData(), "DataSetIterator is not set (null)");
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.params().assign(netOrig.params());
net2With.getModelParams().assign(netOrig.getModelParams());
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
CollectScoresListener listener = new CollectScoresListener(1);
net2With.setListeners(listener);
net2With.addTrainingListeners(listener);
net2With.fit(t.getData());
for( int i=0; i<2; i++ ) {
net2With = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
net2With = new MultiLayerNetwork(netOrig.getNetConfiguration().clone());
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());
removeHelpers(net2With.getLayers(), t.getAllowHelpersForClasses());
CollectScoresListener listener2 = new CollectScoresListener(1);
net2With.setListeners(listener2);
net2With.addTrainingListeners(listener2);
net2With.fit(t.getData());
DoubleArrayList listOrig = listener.getListScore();

View File

@ -23,19 +23,15 @@ package org.deeplearning4j;
import org.deeplearning4j.datasets.iterator.EarlyTerminationDataSetIterator;
import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.junit.jupiter.api.Test;
import org.nd4j.common.resources.Resources;
import org.nd4j.linalg.activations.Activation;
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.lossfunctions.LossFunctions;
import java.nio.file.Files;
import java.util.concurrent.CountDownLatch;
//@Ignore
@ -44,8 +40,8 @@ public class RandomTests extends BaseDL4JTest {
@Test
public void testReproduce() throws Exception {
final MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new RmsProp())
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
final NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new RmsProp())
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.layer(0, new org.deeplearning4j.nn.conf.layers.DenseLayer.Builder().nIn(28 * 28).nOut(10)
.activation(Activation.TANH).build())
.layer(1, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder(

View File

@ -23,9 +23,9 @@ package org.deeplearning4j;
import org.apache.commons.compress.utils.IOUtils;
import org.deeplearning4j.nn.api.Layer;
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.layers.BaseLayer;
import org.deeplearning4j.nn.conf.layers.BaseLayerConfiguration;
import org.deeplearning4j.nn.conf.layers.samediff.AbstractSameDiffLayer;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.layers.convolution.ConvolutionLayer;
@ -66,15 +66,15 @@ public class TestUtils {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
assertEquals(net.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
assertEquals(net.params(), restored.params());
assertEquals(net.getNetConfiguration(), restored.getNetConfiguration());
assertEquals(net.getModelParams(), restored.getModelParams());
} catch (IOException e){
//Should never happen
throw new RuntimeException(e);
}
//Also check the MultiLayerConfiguration is serializable (required by Spark etc)
MultiLayerConfiguration conf = net.getLayerWiseConfigurations();
//Also check the NeuralNetConfiguration is serializable (required by Spark etc)
NeuralNetConfiguration conf = net.getNetConfiguration();
serializeDeserializeJava(conf);
return restored;
@ -90,15 +90,15 @@ public class TestUtils {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
restored = ModelSerializer.restoreComputationGraph(bais, true);
assertEquals(net.getConfiguration(), restored.getConfiguration());
assertEquals(net.params(), restored.params());
assertEquals(net.getComputationGraphConfiguration(), restored.getComputationGraphConfiguration());
assertEquals(net.getModelParams(), restored.getModelParams());
} catch (IOException e){
//Should never happen
throw new RuntimeException(e);
}
//Also check the ComputationGraphConfiguration is serializable (required by Spark etc)
ComputationGraphConfiguration conf = net.getConfiguration();
ComputationGraphConfiguration conf = net.getComputationGraphConfiguration();
serializeDeserializeJava(conf);
return restored;
@ -205,8 +205,8 @@ public class TestUtils {
return null;
}
public static L2Regularization getL2Reg(BaseLayer baseLayer){
return getL2Reg(baseLayer.getRegularization());
public static L2Regularization getL2Reg(BaseLayerConfiguration baseLayerConfiguration){
return getL2Reg(baseLayerConfiguration.getRegularization());
}
public static L2Regularization getL2Reg(List<Regularization> l){
@ -218,7 +218,7 @@ public class TestUtils {
return null;
}
public static WeightDecay getWeightDecayReg(BaseLayer bl){
public static WeightDecay getWeightDecayReg(BaseLayerConfiguration bl){
return getWeightDecayReg(bl.getRegularization());
}
@ -231,7 +231,7 @@ public class TestUtils {
return null;
}
public static double getL1(BaseLayer layer) {
public static double getL1(BaseLayerConfiguration layer) {
List<Regularization> l = layer.getRegularization();
return getL1(l);
}
@ -246,7 +246,7 @@ public class TestUtils {
return l1Reg.getL1().valueAt(0,0);
}
public static double getL2(BaseLayer layer) {
public static double getL2(BaseLayerConfiguration layer) {
List<Regularization> l = layer.getRegularization();
return getL2(l);
}
@ -269,7 +269,7 @@ public class TestUtils {
return getL2(layer.getRegularization());
}
public static double getWeightDecay(BaseLayer layer) {
public static double getWeightDecay(BaseLayerConfiguration layer) {
return getWeightDecayReg(layer.getRegularization()).getCoeff().valueAt(0,0);
}
@ -317,14 +317,14 @@ public class TestUtils {
for(Layer l : layers){
//Don't use instanceof here - there are sub conv subclasses
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 {
for(Layer l : layers){
Preconditions.checkState(l.getHelper() == null, l.conf().getLayer().getLayerName());
Preconditions.checkState(l.getHelper() == null, l.getLayerConfiguration().getLayerName());
}
}
}

View File

@ -31,7 +31,6 @@ import org.deeplearning4j.datasets.iterator.impl.*;
import org.deeplearning4j.eval.Evaluation;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.GradientNormalization;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
@ -168,9 +167,9 @@ public class DataSetIteratorTest extends BaseDL4JTest {
LFWDataSetIterator lfw = new LFWDataSetIterator(batchSize, numSamples,
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)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.layer(0, new ConvolutionLayer.Builder(5, 5).nIn(numChannels).nOut(6)
.weightInit(WeightInit.XAVIER).activation(Activation.RELU).build())
.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)
.nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
.build())
.setInputType(InputType.convolutionalFlat(numRows, numColumns, numChannels))
;
.inputType(InputType.convolutionalFlat(numRows, numColumns, numChannels));
MultiLayerNetwork model = new MultiLayerNetwork(builder.build());
model.init();
model.setListeners(new ScoreIterationListener(listenerFreq));
model.addTrainingListeners(new ScoreIterationListener(listenerFreq));
model.fit(lfw.next());
@ -229,9 +227,9 @@ public class DataSetIteratorTest extends BaseDL4JTest {
Cifar10DataSetIterator cifar = new Cifar10DataSetIterator(batchSize);
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(seed)
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().seed(seed)
.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)
.activation(Activation.RELU).build())
.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)
.build())
.setInputType(InputType.convolutionalFlat(height, width, channels));
.inputType(InputType.convolutionalFlat(height, width, channels));
MultiLayerNetwork model = new MultiLayerNetwork(builder.build());
model.init();
@ -248,7 +246,7 @@ public class DataSetIteratorTest extends BaseDL4JTest {
//model.setListeners(Arrays.asList((TrainingListener) new ScoreIterationListener(listenerFreq)));
CollectScoresIterationListener listener = new CollectScoresIterationListener(listenerFreq);
model.setListeners(listener);
model.addTrainingListeners(listener);
model.fit(cifar);

View File

@ -38,10 +38,9 @@ import org.deeplearning4j.earlystopping.scorecalc.*;
import org.deeplearning4j.earlystopping.termination.*;
import org.deeplearning4j.earlystopping.trainer.EarlyStoppingTrainer;
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.conf.GradientNormalization;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.*;
import org.deeplearning4j.nn.conf.layers.variational.BernoulliReconstructionDistribution;
@ -133,9 +132,9 @@ public class TestEarlyStopping extends BaseDL4JTest {
String msg = i + " - " + sc.getClass().getSimpleName();
log.info("Starting test - {}", msg);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.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 OutputLayer.Builder().nIn(4).nOut(3)
.activation(Activation.SOFTMAX)
@ -219,15 +218,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
@Test
public void testEarlyStoppingEveryNEpoch() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.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)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
@ -248,15 +247,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
@Test
public void testEarlyStoppingIrisMultiEpoch() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.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)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
MultipleEpochsIterator mIter = new MultipleEpochsIterator(10, irisIter);
@ -297,15 +296,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
//Test poor tuning (high LR): should terminate on MaxScoreIterationTerminationCondition
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(5.0)) //Intentionally huge LR
.weightInit(WeightInit.XAVIER).list()
.weightInit(WeightInit.XAVIER)
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
@ -336,15 +335,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
//test termination after max time
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(1e-6)).weightInit(WeightInit.XAVIER).list()
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER)
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
@ -379,15 +378,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
//Simulate this by setting LR = 0.0
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.0)).weightInit(WeightInit.XAVIER).list()
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER)
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
@ -419,9 +418,9 @@ public class TestEarlyStopping extends BaseDL4JTest {
//Simulate this by setting LR = 0.0
Random rng = new Random(123);
Nd4j.getRandom().setSeed(12345);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
.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)
.weightInit(WeightInit.XAVIER).activation(
Activation.TANH)
@ -431,7 +430,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
.build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
int nSamples = 100;
//Generate the training data
INDArray x = Nd4j.linspace(-10, 10, nSamples).reshape(nSamples, 1);
@ -466,15 +465,15 @@ public class TestEarlyStopping extends BaseDL4JTest {
@Test
public void testEarlyStoppingGetBestModel() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.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)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
MultipleEpochsIterator mIter = new MultipleEpochsIterator(10, irisIter);
@ -496,23 +495,23 @@ public class TestEarlyStopping extends BaseDL4JTest {
MultiLayerNetwork mln = result.getBestModel();
assertEquals(net.getnLayers(), mln.getnLayers());
assertEquals(net.conf().getOptimizationAlgo(), mln.conf().getOptimizationAlgo());
BaseLayer bl = (BaseLayer) net.conf().getLayer();
assertEquals(bl.getActivationFn().toString(), ((BaseLayer) mln.conf().getLayer()).getActivationFn().toString());
assertEquals(bl.getIUpdater(), ((BaseLayer) mln.conf().getLayer()).getIUpdater());
assertEquals(net.getNetConfiguration().getOptimizationAlgo(), mln.getNetConfiguration().getOptimizationAlgo());
BaseLayerConfiguration bl = (BaseLayerConfiguration) net.getLayerConfiguration();
assertEquals(bl.getActivationFn().toString(), ((BaseLayerConfiguration) mln.getLayerConfiguration()).getActivationFn().toString());
assertEquals(bl.getIUpdater(), ((BaseLayerConfiguration) mln.getLayerConfiguration()).getIUpdater());
}
@Test
public void testListeners() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.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)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
@ -569,8 +568,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
Metric.MAE}) {
log.info("Metric: " + metric);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.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())
.build();
@ -612,8 +611,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
Metric.MAE}) {
log.info("Metric: " + metric);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.layer(new AutoEncoder.Builder().nIn(784).nOut(32).build())
.build();
@ -655,8 +654,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
Metric.MAE}) {
log.info("Metric: " + metric);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.layer(new VariationalAutoencoder.Builder()
.nIn(784).nOut(32)
.encoderLayerSizes(64)
@ -700,8 +699,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
for(boolean logProb : new boolean[]{false, true}) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.layer(new VariationalAutoencoder.Builder()
.nIn(784).nOut(32)
.encoderLayerSizes(64)
@ -747,8 +746,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
for(Evaluation.Metric metric : Evaluation.Metric.values()) {
log.info("Metric: " + metric);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.layer(new DenseLayer.Builder().nIn(784).nOut(32).build())
.layer(new OutputLayer.Builder().nIn(32).nOut(10).activation(Activation.SOFTMAX).build())
.build();
@ -784,8 +783,8 @@ public class TestEarlyStopping extends BaseDL4JTest {
@Test
public void testEarlyStoppingListeners() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
.layer(0, new OutputLayer.Builder().nIn(4).nOut(3)
.activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
@ -793,7 +792,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
MultiLayerNetwork net = new MultiLayerNetwork(conf);
TestListener tl = new TestListener();
net.setListeners(tl);
net.addTrainingListeners(tl);
DataSetIterator irisIter = new IrisDataSetIterator(50, 150);
EarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();
@ -827,19 +826,19 @@ public class TestEarlyStopping extends BaseDL4JTest {
private int maxEpochEnd = -1;
@Override
public void onEpochStart(Model model){
public void onEpochStart(IModel model){
countEpochStart++;
maxEpochStart = Math.max(maxEpochStart, BaseOptimizer.getEpochCount(model));
}
@Override
public void onEpochEnd(Model model){
public void onEpochEnd(IModel model){
countEpochEnd++;
maxEpochEnd = Math.max(maxEpochEnd, BaseOptimizer.getEpochCount(model));
}
@Override
public void iterationDone(Model model, int iteration, int epoch){
public void iterationDone(IModel model, int iteration, int epoch){
iterCount++;
}
@ -859,7 +858,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
DataSetIterator test = new SingletonDataSetIterator(ds);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.seed(123)
.weightInit(WeightInit.XAVIER)
.updater(new Adam(0.1))
@ -868,7 +867,7 @@ public class TestEarlyStopping extends BaseDL4JTest {
.gradientNormalization(GradientNormalization
.ClipElementWiseAbsoluteValue)
.gradientNormalizationThreshold(1.0)
.list()
.layer(0, new LSTM.Builder()
.nIn(10)
.nOut(10)

View File

@ -76,7 +76,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
@Test
public void testEarlyStoppingIris() {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
@ -84,7 +84,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
.setOutputs("0").build();
ComputationGraph net = new ComputationGraph(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
@ -120,7 +120,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
//Test poor tuning (high LR): should terminate on MaxScoreIterationTerminationCondition
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(5.0)) //Intentionally huge LR
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
@ -128,7 +128,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
.setOutputs("0").build();
ComputationGraph net = new ComputationGraph(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
@ -156,7 +156,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
//test termination after max time
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(1e-6)).weightInit(WeightInit.XAVIER).graphBuilder()
.addInputs("in")
@ -165,7 +165,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
.setOutputs("0").build();
ComputationGraph net = new ComputationGraph(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
@ -198,7 +198,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
//Simulate this by setting LR = 0.0
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(0.0)).weightInit(WeightInit.XAVIER).graphBuilder()
.addInputs("in")
@ -207,7 +207,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
.setOutputs("0").build();
ComputationGraph net = new ComputationGraph(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
@ -233,7 +233,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
@Test
public void testListeners() {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
.addLayer("0", new OutputLayer.Builder().nIn(4).nOut(3)
@ -241,7 +241,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
.lossFunction(LossFunctions.LossFunction.MCXENT).build(), "in")
.setOutputs("0").build();
ComputationGraph net = new ComputationGraph(conf);
net.setListeners(new ScoreIterationListener(1));
net.addTrainingListeners(new ScoreIterationListener(1));
DataSetIterator irisIter = new IrisDataSetIterator(150, 150);
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();
@ -297,7 +297,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
Metric.MAE}) {
log.info("Metric: " + metric);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("in")
.layer("0", new DenseLayer.Builder().nIn(784).nOut(32).build(), "in")
@ -343,7 +343,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
Metric.MAE}) {
log.info("Metric: " + metric);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("in")
.layer("0", new AutoEncoder.Builder().nIn(784).nOut(32).build(), "in")
@ -388,7 +388,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
Metric.MAE}) {
log.info("Metric: " + metric);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("in")
.layer("0", new VariationalAutoencoder.Builder()
@ -435,7 +435,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
for(boolean logProb : new boolean[]{false, true}) {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.updater(new Adam(1e-5))
.graphBuilder()
.addInputs("in")
@ -486,7 +486,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
for(Evaluation.Metric metric : Evaluation.Metric.values()) {
log.info("Metric: " + metric);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("in")
.layer("0", new DenseLayer.Builder().nIn(784).nOut(32).build(), "in")
@ -526,7 +526,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
@Test
public void testEarlyStoppingListenersCG() {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.updater(new Sgd(0.001)).weightInit(WeightInit.XAVIER)
.graphBuilder()
.addInputs("in")
@ -538,7 +538,7 @@ public class TestEarlyStoppingCompGraph extends BaseDL4JTest {
ComputationGraph net = new ComputationGraph(conf);
TestEarlyStopping.TestListener tl = new TestEarlyStopping.TestListener();
net.setListeners(tl);
net.addTrainingListeners(tl);
DataSetIterator irisIter = new IrisDataSetIterator(50, 150);
EarlyStoppingModelSaver<ComputationGraph> saver = new InMemoryModelSaver<>();

View File

@ -69,7 +69,7 @@ public class EvalTest extends BaseDL4JTest {
public void testIris() {
// Network config
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).seed(42)
.updater(new Sgd(1e-6)).list()
@ -84,7 +84,7 @@ public class EvalTest extends BaseDL4JTest {
// Instantiate model
MultiLayerNetwork model = new MultiLayerNetwork(conf);
model.init();
model.addListeners(new ScoreIterationListener(1));
model.addTrainingListeners(new ScoreIterationListener(1));
// Train-test split
DataSetIterator iter = new IrisDataSetIterator(150, 150);
@ -177,7 +177,7 @@ public class EvalTest extends BaseDL4JTest {
rrdsi.reset();
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))
.list()
.layer(0, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
@ -295,7 +295,7 @@ public class EvalTest extends BaseDL4JTest {
int tbpttLength = 10;
int tsLength = 5 * tbpttLength + tbpttLength / 2;
MultiLayerConfiguration conf1 = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf1 = NeuralNetConfiguration.builder()
.seed(12345)
.trainingWorkspaceMode(ws)
.inferenceWorkspaceMode(ws)
@ -306,7 +306,7 @@ public class EvalTest extends BaseDL4JTest {
.build())
.build();
MultiLayerConfiguration conf2 = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf2 = NeuralNetConfiguration.builder()
.seed(12345)
.trainingWorkspaceMode(ws)
.inferenceWorkspaceMode(ws)
@ -314,7 +314,7 @@ public class EvalTest extends BaseDL4JTest {
.layer(new LSTM.Builder().nIn(nIn).nOut(layerSize).build())
.layer(new RnnOutputLayer.Builder().nIn(layerSize).nOut(nOut)
.activation(Activation.SOFTMAX).build())
.tBPTTLength(10)
.tbpttFwdLength(10).tbpttBackLength(10)
.backpropType(BackpropType.TruncatedBPTT)
.build();
@ -324,7 +324,7 @@ public class EvalTest extends BaseDL4JTest {
MultiLayerNetwork net2 = new MultiLayerNetwork(conf2);
net2.init();
net2.setParams(net1.params());
net2.setParams(net1.getModelParams());
for(boolean useMask : new boolean[]{false, true}) {
@ -371,7 +371,7 @@ public class EvalTest extends BaseDL4JTest {
int tbpttLength = 10;
int tsLength = 5 * tbpttLength + tbpttLength / 2;
ComputationGraphConfiguration conf1 = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf1 = NeuralNetConfiguration.builder()
.seed(12345)
.trainingWorkspaceMode(ws)
.inferenceWorkspaceMode(ws)
@ -384,7 +384,7 @@ public class EvalTest extends BaseDL4JTest {
.setOutputs("1")
.build();
ComputationGraphConfiguration conf2 = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf2 = NeuralNetConfiguration.builder()
.seed(12345)
.trainingWorkspaceMode(ws)
.inferenceWorkspaceMode(ws)
@ -405,7 +405,7 @@ public class EvalTest extends BaseDL4JTest {
ComputationGraph net2 = new ComputationGraph(conf2);
net2.init();
net2.setParams(net1.params());
net2.setParams(net1.getModelParams());
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,
SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(123)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(123)
.list()
.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)
.nIn(3).nOut(1).build())
.backpropType(BackpropType.TruncatedBPTT).tBPTTForwardLength(10).tBPTTBackwardLength(10)
.backpropType(BackpropType.TruncatedBPTT).tbpttFwdLength(10).tbpttBackLength(10)
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -473,7 +473,7 @@ public class EvalTest extends BaseDL4JTest {
//Sanity check: https://github.com/eclipse/deeplearning4j/issues/5351
// Network config
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT).seed(42)
.updater(new Sgd(1e-6)).list()
@ -492,7 +492,7 @@ public class EvalTest extends BaseDL4JTest {
DataSetIterator iter = 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++ ){
net.fit(iter);
@ -503,7 +503,7 @@ public class EvalTest extends BaseDL4JTest {
public void testMultiOutputEvalSimple(){
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.seed(12345)
.graphBuilder()
.addInputs("in")
@ -538,7 +538,7 @@ public class EvalTest extends BaseDL4JTest {
public void testMultiOutputEvalCG(){
//Simple sanity check on evaluation
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.graphBuilder()
.addInputs("in")
.layer("0", new EmbeddingSequenceLayer.Builder().nIn(10).nOut(10).build(), "in")
@ -566,7 +566,7 @@ public class EvalTest extends BaseDL4JTest {
@Test
public void testInvalidEvaluation(){
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.list()
.layer(new DenseLayer.Builder().nIn(4).nOut(10).build())
@ -622,11 +622,11 @@ public class EvalTest extends BaseDL4JTest {
//Disable validation, and check same thing:
net.getLayerWiseConfigurations().setValidateOutputLayerConfig(false);
net.getNetConfiguration().setValidateOutputLayerConfig(false);
net.evaluate(iter);
net.evaluateROCMultiClass(iter, 0);
cg.getConfiguration().setValidateOutputLayerConfig(false);
cg.getComputationGraphConfiguration().setValidateOutputLayerConfig(false);
cg.evaluate(iter);
cg.evaluateROCMultiClass(iter, 0);
}

View File

@ -23,7 +23,6 @@ package org.deeplearning4j.eval;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
import org.deeplearning4j.core.evaluation.EvaluationTools;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -48,7 +47,7 @@ public class EvaluationToolsTests extends BaseDL4JTest {
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,
new OutputLayer.Builder().nIn(4).nOut(2).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
@ -82,7 +81,7 @@ public class EvaluationToolsTests extends BaseDL4JTest {
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 {
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,
new OutputLayer.Builder().nIn(4).nOut(3).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())

View File

@ -22,23 +22,19 @@ package org.deeplearning4j.eval;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.junit.jupiter.api.Test;
import org.nd4j.evaluation.curves.PrecisionRecallCurve;
import org.nd4j.evaluation.curves.RocCurve;
import org.nd4j.linalg.activations.Activation;
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.iterator.DataSetIterator;
import org.nd4j.linalg.dataset.api.preprocessor.NormalizerStandardize;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.indexing.NDArrayIndex;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import java.util.*;
@ -86,7 +82,7 @@ public class ROCTest extends BaseDL4JTest {
DataSetIterator iter = new IrisDataSetIterator(150, 150);
Nd4j.getRandom().setSeed(12345);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.XAVIER).seed(12345)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().weightInit(WeightInit.XAVIER).seed(12345)
.list()
.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)

View File

@ -23,7 +23,6 @@ package org.deeplearning4j.eval;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.datasets.iterator.ExistingDataSetIterator;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
import org.deeplearning4j.nn.graph.ComputationGraph;
@ -49,7 +48,7 @@ public class RegressionEvalTest extends BaseDL4JTest {
public void testRegressionEvalMethods() {
//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)
.lossFunction(LossFunctions.LossFunction.MSE).nIn(10).nOut(5).build())
.build();
@ -71,7 +70,7 @@ public class RegressionEvalTest extends BaseDL4JTest {
ComputationGraphConfiguration graphConf =
new NeuralNetConfiguration.Builder().weightInit(WeightInit.ZERO).graphBuilder()
NeuralNetConfiguration.builder().weightInit(WeightInit.ZERO).graphBuilder()
.addInputs("in").addLayer("0", new OutputLayer.Builder()
.lossFunction(LossFunctions.LossFunction.MSE)
.activation(Activation.TANH).nIn(10).nOut(5).build(), "in")

View File

@ -24,7 +24,6 @@ import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.exception.DL4JException;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.*;
@ -41,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.fail;
public class TestInvalidConfigurations extends BaseDL4JTest {
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(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) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new GravesLSTM.Builder().nIn(nIn).nOut(10).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) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new ConvolutionLayer.Builder().nIn(depthIn).nOut(5).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);
net.init();
@ -90,7 +89,7 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
@Test
public void testDenseNout0() {
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new DenseLayer.Builder().nIn(10).nOut(0).build())
.layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build()).build();
@ -147,7 +146,7 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
@Test
public void testLSTMNOut0() {
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new GravesLSTM.Builder().nIn(10).nOut(0).build())
.layer(1, new RnnOutputLayer.Builder().nIn(10).nOut(10).build()).build();
@ -178,10 +177,10 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
@Test
public void testConvolutionalNOut0() {
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new ConvolutionLayer.Builder().nIn(5).nOut(0).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);
net.init();
@ -207,12 +206,12 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
//(10-3+2*0)/2+1 = 7/2 + 1
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict)
.list()
.layer(0, new ConvolutionLayer.Builder().kernelSize(3, 2).stride(2, 2).padding(0, 0).nOut(5)
.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);
net.init();
@ -234,11 +233,11 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
int hIn = 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)
.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);
net.init();
@ -265,8 +264,8 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
//Invalid: (10-3+0)/2+1 = 4.5
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict).list()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict).list()
.layer(0, new ConvolutionLayer.Builder().kernelSize(3, 3).stride(2, 2)
.padding(0, 0).nIn(depthIn).nOut(5).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
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)
.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) {
fail("Did not expect exception with default (truncate)");
}
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict)
.list()
.layer(0, new ConvolutionLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0).nOut(5)
.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);
net.init();
@ -338,12 +337,12 @@ public class TestInvalidConfigurations extends BaseDL4JTest {
//(10-3+2*0)/2+1 = 7/2 + 1
try {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().convolutionMode(ConvolutionMode.Strict)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().convolutionMode(ConvolutionMode.Strict)
.list()
.layer(0, new SubsamplingLayer.Builder().kernelSize(2, 3).stride(2, 2).padding(0, 0)
.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);
net.init();

View File

@ -23,7 +23,6 @@ package org.deeplearning4j.exceptions;
import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.exception.DL4JException;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.*;
@ -43,7 +42,7 @@ public class TestInvalidInput extends BaseDL4JTest {
@Test
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(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
@ -64,7 +63,7 @@ public class TestInvalidInput extends BaseDL4JTest {
@Test
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(1, new OutputLayer.Builder().nIn(10).nOut(10).activation(Activation.SOFTMAX).build()).build();
@ -85,7 +84,7 @@ public class TestInvalidInput extends BaseDL4JTest {
@Test
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(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 d = 3;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).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);
net.init();
@ -139,10 +138,10 @@ public class TestInvalidInput extends BaseDL4JTest {
int w = 16;
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(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);
net.init();
@ -165,10 +164,10 @@ public class TestInvalidInput extends BaseDL4JTest {
int w = 16;
int d = 3;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(0, new SubsamplingLayer.Builder().kernelSize(2, 2).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);
net.init();
@ -188,7 +187,7 @@ public class TestInvalidInput extends BaseDL4JTest {
@Test
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(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
@ -209,7 +208,7 @@ public class TestInvalidInput extends BaseDL4JTest {
@Test
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(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();
@ -231,7 +230,7 @@ public class TestInvalidInput extends BaseDL4JTest {
@Test
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(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"}) {
Layer l;
LayerConfiguration l;
switch (layerType){
case "simple":
l = new SimpleRnn.Builder().nIn(5).nOut(5).build();
@ -272,7 +271,7 @@ public class TestInvalidInput extends BaseDL4JTest {
throw new RuntimeException();
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().list()
.layer(l)
.layer(new RnnOutputLayer.Builder().nIn(5).nOut(5).activation(Activation.SOFTMAX).build()).build();

View File

@ -23,7 +23,6 @@ package org.deeplearning4j.gradientcheck;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.TestUtils;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.graph.AttentionVertex;
import org.deeplearning4j.nn.conf.inputs.InputType;
@ -84,7 +83,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
System.out.println("Starting test: " + name);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.TANH)
.updater(new NoOp())
@ -98,7 +97,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.setInputType(InputType.recurrent(nIn))
.inputType(InputType.recurrent(nIn))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -145,7 +144,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
System.out.println("Starting test: " + name);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.TANH)
.updater(new NoOp())
@ -159,7 +158,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.setInputType(InputType.recurrent(nIn))
.inputType(InputType.recurrent(nIn))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -185,7 +184,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
for (boolean inputMask : new boolean[]{false, true}) {
for (boolean projectInput : new boolean[]{false, true}) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.TANH)
.updater(new NoOp())
@ -199,7 +198,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.MAX).build())
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.setInputType(InputType.recurrent(nIn))
.inputType(InputType.recurrent(nIn))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -240,7 +239,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
int nOut = 5;
int layerSize = 8;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.IDENTITY)
.updater(new NoOp())
@ -251,7 +250,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.setInputType(InputType.recurrent(nIn))
.inputType(InputType.recurrent(nIn))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -303,7 +302,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
System.out.println("Starting test: " + name);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.IDENTITY)
.updater(new NoOp())
@ -314,7 +313,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
.layer(new OutputLayer.Builder().nOut(nOut).activation(Activation.SOFTMAX)
.lossFunction(LossFunctions.LossFunction.MCXENT).build())
.setInputType(InputType.recurrent(nIn))
.inputType(InputType.recurrent(nIn))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -361,7 +360,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
System.out.println("Starting test: " + name);
ComputationGraphConfiguration graph = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration graph = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.TANH)
.updater(new NoOp())
@ -425,7 +424,7 @@ public class AttentionLayerTest extends BaseDL4JTest {
System.out.println("Starting test: " + name);
ComputationGraphConfiguration graph = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration graph = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.activation(Activation.TANH)
.updater(new NoOp())

View File

@ -25,7 +25,6 @@ import org.deeplearning4j.TestUtils;
import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
@ -74,8 +73,8 @@ public class BNGradientCheckTest extends BaseDL4JTest {
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)
.seed(12345L)
.dist(new NormalDistribution(0, 1)).list()
@ -90,7 +89,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
mln.init();
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
@ -119,7 +118,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
}
for (boolean useLogStd : new boolean[]{true, false}) {
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp()).seed(12345L)
.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(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(nOut).build())
.setInputType(InputType.convolutional(hw, hw, depth));
.inputType(InputType.convolutional(hw, hw, depth));
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
mln.init();
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
@ -188,7 +187,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
LossFunctions.LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.l2(l2vals[j])
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
@ -203,9 +202,9 @@ public class BNGradientCheckTest extends BaseDL4JTest {
.layer(4, new ActivationLayer.Builder().activation(afn).build())
.layer(5, new OutputLayer.Builder(lf).activation(outputActivation).nOut(nOut)
.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);
mln.init();
@ -219,11 +218,11 @@ public class BNGradientCheckTest extends BaseDL4JTest {
mln.setInput(ds.getFeatures());
mln.setLabels(ds.getLabels());
mln.computeGradientAndScore();
double scoreBefore = mln.score();
double scoreBefore = mln.getScore();
for (int k = 0; k < 20; k++)
mln.fit(ds);
mln.computeGradientAndScore();
double scoreAfter = mln.score();
double scoreAfter = mln.getScore();
//Can't test in 'characteristic mode of operation' if not learning
String msg = name
+ " - score did not (sufficiently) decrease during learning - activationFn="
@ -237,7 +236,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
@ -294,8 +293,8 @@ public class BNGradientCheckTest extends BaseDL4JTest {
LossFunctions.LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
MultiLayerConfiguration.Builder builder =
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.l2(l2vals[j])
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
@ -310,7 +309,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
.activation(outputActivation).nOut(nOut)
.build());
MultiLayerConfiguration conf = builder.build();
NeuralNetConfiguration conf = builder.build();
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
mln.init();
@ -323,11 +322,11 @@ public class BNGradientCheckTest extends BaseDL4JTest {
mln.setInput(ds.getFeatures());
mln.setLabels(ds.getLabels());
mln.computeGradientAndScore();
double scoreBefore = mln.score();
double scoreBefore = mln.getScore();
for (int k = 0; k < 10; k++)
mln.fit(ds);
mln.computeGradientAndScore();
double scoreAfter = mln.score();
double scoreAfter = mln.getScore();
//Can't test in 'characteristic mode of operation' if not learning
String msg = name
+ " - score did not (sufficiently) decrease during learning - activationFn="
@ -341,7 +340,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
@ -370,7 +369,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
INDArray labels = ds.getLabels();
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)
.seed(12345L)
.dist(new NormalDistribution(0, 1)).list()
@ -385,7 +384,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
mln.init();
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
@ -414,7 +413,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
}
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)
.seed(12345L)
.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(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(nOut).build())
.setInputType(InputType.convolutional(hw, hw, depth));
.inputType(InputType.convolutional(hw, hw, depth));
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
mln.init();
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean
@ -457,7 +456,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
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)
.weightInit(WeightInit.XAVIER).graphBuilder().addInputs("in")
.setInputTypes(InputType.convolutional(height, width, channels))
@ -526,7 +525,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
LossFunctions.LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT)
.updater(new NoOp())
@ -554,11 +553,11 @@ public class BNGradientCheckTest extends BaseDL4JTest {
net.setInput(0, ds.getFeatures());
net.setLabels(ds.getLabels());
net.computeGradientAndScore();
double scoreBefore = net.score();
double scoreBefore = net.getScore();
for (int k = 0; k < 20; k++)
net.fit(ds);
net.computeGradientAndScore();
double scoreAfter = net.score();
double scoreAfter = net.getScore();
//Can't test in 'characteristic mode of operation' if not learning
String msg = name
+ " - score did not (sufficiently) decrease during learning - activationFn="
@ -572,7 +571,7 @@ public class BNGradientCheckTest extends BaseDL4JTest {
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
+ doLearningFirst + ", l1=" + l1vals[j] + ", l2=" + l2vals[j]);
// 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
//i.e., runningMean = decay * runningMean + (1-decay) * batchMean

View File

@ -24,17 +24,14 @@ import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.TestUtils;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.RNNFormat;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.*;
import org.deeplearning4j.nn.conf.layers.convolutional.Cropping1D;
import org.deeplearning4j.nn.modelimport.keras.KerasModelImport;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.util.Convolution1DUtils;
import org.deeplearning4j.util.ConvolutionUtils;
import org.junit.jupiter.api.Test;
import org.nd4j.linalg.activations.Activation;
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.lossfunctions.LossFunctions;
import java.io.File;
import static org.junit.jupiter.api.Assertions.assertEquals;
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)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
@ -103,10 +98,10 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
.build())
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
.setInputType(InputType.recurrent(convNIn, length)).build();
.inputType(InputType.recurrent(convNIn, length)).build();
String json = conf.toJson();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -118,7 +113,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -170,7 +165,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
}
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1)).convolutionMode(ConvolutionMode.Same).list()
@ -183,10 +178,10 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
.build())
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -198,7 +193,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -251,7 +246,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
}
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.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())
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -282,7 +277,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -330,7 +325,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
}
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.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())
.layer(3, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -359,7 +354,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -393,7 +388,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
log.info("Starting test: " + s);
Nd4j.getRandom().setSeed(12345);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.activation(Activation.TANH)
@ -413,7 +408,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
.layer(new GlobalPoolingLayer(PoolingType.AVG))
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
.setInputType(InputType.recurrent(convNIn, length)).build();
.inputType(InputType.recurrent(convNIn, length)).build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -481,7 +476,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
log.info("Starting test: " + s);
Nd4j.getRandom().setSeed(12345);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.activation(Activation.TANH)
@ -501,7 +496,7 @@ public class CNN1DGradientCheckTest extends BaseDL4JTest {
.build())
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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);
net.init();

View File

@ -24,7 +24,6 @@ import lombok.extern.java.Log;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.TestUtils;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
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.junit.jupiter.api.Test;
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.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
@ -112,7 +110,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
.dist(new NormalDistribution(0, 1))
@ -131,10 +129,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
.inputPreProcessor(2,
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
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();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -149,7 +147,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
log.info(msg);
// 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);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
.dist(new NormalDistribution(0, 1))
@ -235,10 +233,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
.inputPreProcessor(3,
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
convNOut2, true))
.setInputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
.inputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
String json = conf.toJson();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -252,7 +250,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
log.info(msg);
// 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);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.weightInit(WeightInit.XAVIER)
@ -327,10 +325,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
.activation(Activation.SOFTMAX).nOut(finalNOut).build())
.inputPreProcessor(2,
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();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -397,7 +395,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
labels.putScalar(new int[]{i, i % finalNOut}, 1.0);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
.dist(new NormalDistribution(0, 1))
@ -414,10 +412,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
.inputPreProcessor(2,
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
convNOut, true))
.setInputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
.inputType(InputType.convolutional3D(df, depth, height, width, convNIn)).build();
String json = conf.toJson();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -431,7 +429,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
log.info(msg);
// 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);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp()).weightInit(WeightInit.LECUN_NORMAL)
.dist(new NormalDistribution(0, 1))
@ -513,10 +511,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
.inputPreProcessor(3,
new Cnn3DToFeedForwardPreProcessor(outDepth, outHeight, outWidth,
convNOut2, true))
.setInputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
.inputType(InputType.convolutional3D(depth, height, width, convNIn)).build();
String json = conf.toJson();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -530,7 +528,7 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
log.info(msg);
// 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);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.weightInit(new NormalDistribution(0, 0.1))
@ -607,10 +605,10 @@ public class CNN3DGradientCheckTest extends BaseDL4JTest {
.build())
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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();
MultiLayerConfiguration c2 = MultiLayerConfiguration.fromJson(json);
NeuralNetConfiguration c2 = NeuralNetConfiguration.fromJson(json);
assertEquals(conf, c2);
MultiLayerNetwork net = new MultiLayerNetwork(conf);

View File

@ -26,7 +26,6 @@ import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.CNN2DFormat;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.inputs.InputType;
@ -100,15 +99,15 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
LossFunctions.LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).updater(new NoOp())
.weightInit(WeightInit.XAVIER).seed(12345L).list()
.layer(0, new ConvolutionLayer.Builder(1, 1).nOut(6).activation(afn).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);
mln.init();
@ -120,11 +119,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
mln.setInput(ds.getFeatures());
mln.setLabels(ds.getLabels());
mln.computeGradientAndScore();
double scoreBefore = mln.score();
double scoreBefore = mln.getScore();
for (int j = 0; j < 10; j++)
mln.fit(ds);
mln.computeGradientAndScore();
double scoreAfter = mln.score();
double scoreAfter = mln.getScore();
//Can't test in 'characteristic mode of operation' if not learning
String msg = name + " - score did not (sufficiently) decrease during learning - activationFn="
+ afn + ", lossFn=" + lf + ", outputActivation=" + outputActivation
@ -137,7 +136,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
System.out.println(name + " - activationFn=" + afn + ", lossFn=" + lf + ", outputActivation="
+ outputActivation + ", doLearningFirst=" + doLearningFirst);
// 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,
@ -186,7 +185,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
double l2 = l2vals[i];
double l1 = l1vals[i];
MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.l2(l2).l1(l1).l2Bias(biasL2[i]).l1Bias(biasL1[i])
.optimizationAlgo(
@ -198,9 +197,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(1, new OutputLayer.Builder(lf).activation(outputActivation).nOut(3)
.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);
mln.init();
@ -212,11 +211,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
mln.setInput(ds.getFeatures());
mln.setLabels(ds.getLabels());
mln.computeGradientAndScore();
double scoreBefore = mln.score();
double scoreBefore = mln.getScore();
for (int j = 0; j < 10; j++)
mln.fit(ds);
mln.computeGradientAndScore();
double scoreAfter = mln.score();
double scoreAfter = mln.getScore();
//Can't test in 'characteristic mode of operation' if not learning
String msg = testName
+ "- score did not (sufficiently) decrease during learning - activationFn="
@ -231,7 +230,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
+ ", outputActivation=" + outputActivation + ", doLearningFirst="
+ doLearningFirst);
// 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,
@ -269,8 +268,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
labels.putScalar(new int[]{i, i % nOut}, 1.0);
}
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1))
@ -281,7 +280,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(2 * 2 * 4)
.nOut(nOut).build())
.setInputType(InputType.convolutionalFlat(height, width, inputDepth))
.inputType(InputType.convolutionalFlat(height, width, inputDepth))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -293,7 +292,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
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);
}
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp()).weightInit(new NormalDistribution(0, 1))
.list()
@ -349,7 +348,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX)
.nOut(nOut).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -361,7 +360,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
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 labels = TestUtils.randomOneHot(minibatchSize, nOut);
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1))
@ -416,7 +415,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(8 * 8 * 3)
.nOut(4).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -427,7 +426,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -472,8 +471,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
labels.putScalar(new int[]{i, i % nOut}, 1.0);
}
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().updater(new NoOp())
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 1))
.list().layer(0,
@ -488,7 +487,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(3 * 3 * 3)
.nOut(4).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -500,7 +499,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -546,8 +545,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
labels.putScalar(new int[]{i, i % nOut}, 1.0);
}
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().updater(new NoOp())
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 1))
.list().layer(0,
@ -562,7 +561,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2)
.nOut(4).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -606,7 +605,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
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)
.activation(afn)
.list()
@ -623,10 +622,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2).nOut(nOut)
.build())
.setInputType(InputType.convolutional(height, width, inputDepth, format)).build();
.inputType(InputType.convolutional(height, width, inputDepth, format)).build();
assertEquals(ConvolutionMode.Truncate,
((ConvolutionLayer) conf.getConf(0).getLayer()).getConvolutionMode());
assertEquals(ConvolutionMode.Truncate, conf.getConvolutionMode());
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -673,7 +671,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
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)
.activation(afn)
.list()
@ -689,10 +687,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(2 * 2 * 2).nOut(nOut)
.build())
.setInputType(InputType.convolutional(height, width, inputDepth, format)).build();
.inputType(InputType.convolutional(height, width, inputDepth, format)).build();
assertEquals(ConvolutionMode.Truncate,
((ConvolutionLayer) conf.getConf(0).getLayer()).getConvolutionMode());
assertEquals(ConvolutionMode.Truncate,conf.getConvolutionMode());
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -744,7 +741,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.activation(Activation.SIGMOID).convolutionMode(Same).list()
@ -760,7 +757,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.stride(1, 1).padding(0, 0).build())
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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);
net.init();
@ -810,14 +807,14 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
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();
Layer poolLayer = new SubsamplingLayer.Builder()
LayerConfiguration poolLayer = new SubsamplingLayer.Builder()
.poolingType(SubsamplingLayer.PoolingType.MAX).kernelSize(k, k).dataFormat(format)
.stride(stride, stride).padding(0, 0).build();
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.activation(Activation.TANH).convolutionMode(Same).list()
@ -825,7 +822,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.layer(1, convFirst ? poolLayer : convLayer)
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(nOut).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -883,8 +880,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().updater(new NoOp())
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 1)).list()
.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
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(4).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -920,7 +917,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println(msg);
// 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,
@ -971,7 +968,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
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)
.updater(new NoOp())
.activation(act)
@ -981,11 +978,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.stride(s, s).dataFormat(format)
.dilation(d, d)
.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())
.setInputType(InputType.convolutional(h, w, inputDepth, format)).build();
.inputType(InputType.convolutional(h, w, inputDepth, format)).build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -1043,7 +1040,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
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)
.updater(new NoOp())
.activation(Activation.TANH)
@ -1054,11 +1051,11 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.stride(s, s)
.dilation(d, d)
.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())
.setInputType(InputType.convolutional(h, w, inputDepth, format)).build();
.inputType(InputType.convolutional(h, w, inputDepth, format)).build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -1116,7 +1113,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
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)
.updater(new NoOp())
.activation(Activation.TANH).convolutionMode(cm).list()
@ -1140,9 +1137,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.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())
.setInputType(InputType.convolutional(h, w, inputDepth, format)).build();
.inputType(InputType.convolutional(h, w, inputDepth, format)).build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -1190,8 +1187,8 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
INDArray input = Nd4j.rand(DataType.DOUBLE, inShape);
INDArray labels = TestUtils.randomOneHot(minibatchSize, nOut);
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.convolutionMode(ConvolutionMode.Same)
@ -1208,7 +1205,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.build())
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nOut(nOut).build())
.setInputType(InputType.convolutional(height, width, inputDepth, format))
.inputType(InputType.convolutional(height, width, inputDepth, format))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -1277,7 +1274,7 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
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)
.updater(new NoOp())
.activation(Activation.TANH)
@ -1293,9 +1290,9 @@ public class CNNGradientCheckTest extends BaseDL4JTest {
.depthMultiplier(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())
.setInputType(InputType.convolutional(height, width, nIn, format)).build();
.inputType(InputType.convolutional(height, width, nIn, format)).build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();

View File

@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.TestUtils;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
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.lossfunctions.impl.LossNegativeLogLikelihood;
import java.util.Random;
////@Ignore
public class CapsnetGradientCheckTest extends BaseDL4JTest {
@ -80,12 +77,11 @@ public class CapsnetGradientCheckTest extends BaseDL4JTest {
labels.putScalar(new int[]{i, i % capsule}, 1.0);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.seed(123)
.updater(new NoOp())
.weightInit(new WeightInitDistribution(new UniformDistribution(-6, 6)))
.list()
.dist(new UniformDistribution(-6, 6))
.layer(new PrimaryCapsules.Builder(primaryCapsDim, primarpCapsChannel)
.kernelSize(3, 3)
.stride(2, 2)
@ -94,7 +90,7 @@ public class CapsnetGradientCheckTest extends BaseDL4JTest {
.layer(new CapsuleStrengthLayer.Builder().build())
.layer(new ActivationLayer.Builder(new ActivationSoftmax()).build())
.layer(new LossLayer.Builder(new LossNegativeLogLikelihood()).build())
.setInputType(InputType.convolutional(height, width, inputDepth))
.inputType(InputType.convolutional(height, width, inputDepth))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);

View File

@ -25,7 +25,6 @@ import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.TestUtils;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.dropout.*;
@ -92,7 +91,7 @@ public class DropoutGradientCheck extends BaseDL4JTest {
continue;
}
NeuralNetConfiguration.ListBuilder builder = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0,1))
.convolutionMode(ConvolutionMode.Same)
@ -104,18 +103,18 @@ public class DropoutGradientCheck extends BaseDL4JTest {
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.setInputType(InputType.convolutional(6,6,2));
builder.inputType(InputType.convolutional(6,6,2));
} else {
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());
MultiLayerConfiguration conf = builder.build();
NeuralNetConfiguration conf = builder.build();
//Remove spatial dropout from output layer - can't be used for 2d input
if(i == 4){
conf.getConf(2).getLayer().setIDropout(null);
conf.getFlattenedLayerConfigurations().get(2).setIDropout(null);
}
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
@ -149,7 +148,7 @@ public class DropoutGradientCheck extends BaseDL4JTest {
Nd4j.getRandom().setSeed(12345);
int mb = 3;
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0,1))
.convolutionMode(ConvolutionMode.Same)

View File

@ -24,7 +24,6 @@ import org.deeplearning4j.BaseDL4JTest;
import org.deeplearning4j.TestUtils;
import org.deeplearning4j.nn.conf.CNN2DFormat;
import org.deeplearning4j.nn.conf.ConvolutionMode;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.inputs.InputType;
@ -72,7 +71,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
for (int miniBatchSize : minibatchSizes) {
for (PoolingType pt : poolingTypes) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
@ -95,7 +94,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
System.out.println("testLSTMGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = "
+ miniBatchSize);
// 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,
@ -127,7 +126,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
for (int miniBatchSize : minibatchSizes) {
for (PoolingType pt : poolingTypes) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.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(2, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.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);
mln.init();
@ -156,7 +155,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println("testCnnGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = " + miniBatchSize + " - " + (nchw ? "NCHW" : "NHWC"));
// 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,
@ -185,7 +184,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
for (PoolingType pt : poolingTypes) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
@ -216,7 +215,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
if (PRINT_RESULTS) {
System.out.println("testLSTMGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = " + miniBatchSize);
// 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)
@ -259,7 +258,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
stride = new int[] {inputH, 1};
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.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)
.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);
mln.init();
@ -299,7 +298,7 @@ public class GlobalPoolingGradientCheckTests extends BaseDL4JTest {
System.out.println("testCnnGlobalPoolingBasicMultiLayer() - " + pt + ", minibatch = "
+ miniBatchSize);
// 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)

Some files were not shown because too many files have changed in this diff Show More