Playing with some new code 2

Signed-off-by: brian <brian@brutex.de>
master
Brian Rosenberger 2023-04-07 14:28:47 +02:00
parent 9af4f9f23a
commit 3edb90dbd1
614 changed files with 12080 additions and 11594 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();
@ -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")

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

@ -46,13 +46,12 @@ import org.datavec.image.transform.ResizeImageTransform;
import org.datavec.image.transform.ShowImageTransform;
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
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.ActivationLayer;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.DropoutLayer;
import org.deeplearning4j.nn.conf.layers.Layer;
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.multilayer.MultiLayerNetwork;
@ -61,7 +60,6 @@ import org.deeplearning4j.nn.weights.WeightInitXavier;
import org.deeplearning4j.optimize.listeners.ScoreToChartListener;
import org.junit.jupiter.api.Test;
import org.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.activations.impl.ActivationIdentity;
import org.nd4j.linalg.activations.impl.ActivationLReLU;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;
@ -92,8 +90,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(),
@ -103,33 +101,33 @@ public class App {
new DenseLayer.Builder().nIn(X_DIM*Y_DIM).nOut(X_DIM*Y_DIM*CHANNELS).activation(Activation.TANH)
.build()
};
}
}
/**
* Returns a network config that takes in a 10x10 random number and produces a 28x28 grayscale image.
*
* @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)
.weightInitFn(new WeightInitXavier())
.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,45 +144,50 @@ public class App {
};
}
private static MultiLayerConfiguration discriminator() {
private static NeuralNetConfiguration discriminator() {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
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);
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( Adam.builder().learningRate(0.0002).beta1(0.5).build() )
.gradientNormalization( GradientNormalization.RenormalizeL2PerLayer)
.gradientNormalizationThreshold( 100 )
.weightInit( new WeightInitXavier() )
.activation( new ActivationIdentity())
.list( layers )
.setInputType( InputType.convolutional(X_DIM, Y_DIM, CHANNELS))
//.weightInitFn( new WeightInitXavier() ) //this is internal
.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;
}
@ -195,6 +198,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);
@ -220,9 +225,10 @@ 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);

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;
@ -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.getConfiguration();
NeuralNetConfiguration disConf = ganDiscriminator.getConfiguration();
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);
@ -267,7 +268,7 @@ public class GAN {
}
/**
* 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());
};

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,10 +284,10 @@ 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)

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,10 +294,10 @@ 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 DenseLayerConfiguration.Builder().nIn(9).nOut(9).weightInit(WeightInit.XAVIER).activation(Activation.RELU).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,13 +80,13 @@ 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 DenseLayerConfiguration.Builder().nIn(10).nOut(64).activation(Activation.RELU).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,13 +120,13 @@ 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 DenseLayerConfiguration.Builder().nIn(10).nOut(64).activation(Activation.RELU).build())

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();

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.getConfiguration(), mln.getConfiguration(), "Configs not equal");
assertEquals( loaded.params(), mln.params(), "Params not equal");
assertEquals( loaded.paramTable(), mln.paramTable(), "Param table not equal");
assertEquals( loaded.getParamTable(), mln.getParamTable(), "Param table not equal");
} else if(config instanceof ComputationGraphConfiguration ){
ComputationGraphConfiguration cgc = (ComputationGraphConfiguration) config;
cg = new ComputationGraph(cgc);
@ -426,8 +426,8 @@ public class IntegrationTestRunner {
boolean isTbptt;
int tbpttLength;
if(modelType == ModelType.MLN){
isTbptt = mln.getLayerWiseConfigurations().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = mln.getLayerWiseConfigurations().getTbpttFwdLength();
isTbptt = mln.getConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = mln.getConfiguration().getTbpttFwdLength();
} else if(modelType == ModelType.CG) {
isTbptt = cg.getComputationGraphConfiguration().getBackpropType() == BackpropType.TruncatedBPTT;
tbpttLength = cg.getComputationGraphConfiguration().getTbpttFwdLength();
@ -606,7 +606,7 @@ 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.getConfiguration(), restored.getConfiguration());
assertEquals(mln.params(), restored.params());
} else if(modelType == ModelType.CG){
ModelSerializer.writeModel(m, 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,14 +735,14 @@ 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.getConfiguration().getInputPreProcessors().values();
} else {
preProcessors = new ArrayList<>();
for (org.deeplearning4j.nn.conf.graph.GraphVertex gv : cg.getComputationGraphConfiguration().getVertices().values()) {
@ -767,7 +767,7 @@ public class IntegrationTestRunner {
}
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,7 +832,7 @@ 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();
for(Map.Entry<String,INDArray> e : paramTable.entrySet()){
@ -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());
@ -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) {

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.getConfiguration(), restored.getConfiguration());
assertEquals(net.params(), restored.params());
} 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.getConfiguration();
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

@ -66,9 +66,9 @@ allprojects { Project proj ->
plugins.withType(JavaPlugin) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_11
tasks.withType(JavaCompile) {
options.release = 8
options.release = 11
}
dependencies {
@ -86,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"

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,12 +109,12 @@ public class LayerHelperValidationUtil {
}
MultiLayerNetwork net1NoHelper = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
MultiLayerNetwork net1NoHelper = new MultiLayerNetwork(netOrig.getConfiguration().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.getConfiguration().clone());
net2With.init();
net2With.params().assign(netOrig.params());
log.info("Removing all except for specified helpers from network copy 2: " + t.getAllowHelpersForClasses());
@ -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);
@ -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,7 +253,7 @@ 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.getConfiguration().clone());
net2With.init();
net2With.params().assign(netOrig.params());
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());
@ -264,7 +265,7 @@ public class LayerHelperValidationUtil {
for( int i=0; i<2; i++ ) {
net2With = new MultiLayerNetwork(netOrig.getLayerWiseConfigurations().clone());
net2With = new MultiLayerNetwork(netOrig.getConfiguration().clone());
net2With.init();
net2With.params().assign(netOrig.params());
log.info("Removing all except for specified layer helpers from network copy 2: " + t.getAllowHelpersForClasses());

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,7 +23,7 @@ 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.samediff.AbstractSameDiffLayer;
@ -66,15 +66,15 @@ public class TestUtils {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
restored = ModelSerializer.restoreMultiLayerNetwork(bais, true);
assertEquals(net.getLayerWiseConfigurations(), restored.getLayerWiseConfigurations());
assertEquals(net.getConfiguration(), restored.getConfiguration());
assertEquals(net.params(), restored.params());
} 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.getConfiguration();
serializeDeserializeJava(conf);
return restored;
@ -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,8 +31,8 @@ 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.NeuralNetConfiguration.NeuralNetConfigurationBuilder;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
@ -168,9 +168,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,8 +178,7 @@ 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();
@ -229,9 +228,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 +239,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();

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,9 +218,9 @@ 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())
@ -248,9 +247,9 @@ 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())
@ -297,10 +296,10 @@ 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();
@ -336,9 +335,9 @@ 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())
@ -379,9 +378,9 @@ 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())
@ -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)
@ -466,9 +465,9 @@ 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())
@ -496,17 +495,17 @@ 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());
BaseLayer bl = (BaseLayer) net.getLayerConfiguration();
assertEquals(bl.getActivationFn().toString(), ((BaseLayer) mln.getLayerConfiguration()).getActivationFn().toString());
assertEquals(bl.getIUpdater(), ((BaseLayer) 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())
@ -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())
@ -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)
@ -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")
@ -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")
@ -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")
@ -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)
@ -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")

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()
@ -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();
@ -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)
@ -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()
@ -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,7 +622,7 @@ public class EvalTest extends BaseDL4JTest {
//Disable validation, and check same thing:
net.getLayerWiseConfigurations().setValidateOutputLayerConfig(false);
net.getConfiguration().setValidateOutputLayerConfig(false);
net.evaluate(iter);
net.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())
@ -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,8 +25,8 @@ 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.NeuralNetConfiguration.NeuralNetConfigurationBuilder;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.distribution.UniformDistribution;
import org.deeplearning4j.nn.conf.inputs.InputType;
@ -74,17 +74,17 @@ public class BNGradientCheckTest extends BaseDL4JTest {
for (boolean useLogStd : new boolean[]{true, false}) {
MultiLayerConfiguration.Builder builder =
new NeuralNetConfiguration.Builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.seed(12345L)
.dist(new NormalDistribution(0, 1)).list()
.layer(0, new DenseLayer.Builder().nIn(4).nOut(3)
.activation(Activation.IDENTITY).build())
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).nOut(3).build())
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(3).nOut(3).build());
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder =
NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.seed(12345L)
.dist(new NormalDistribution(0, 1)).list()
.layer(0, new DenseLayer.Builder().nIn(4).nOut(3)
.activation(Activation.IDENTITY).build())
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).nOut(3).build())
.layer(2, new ActivationLayer.Builder().activation(Activation.TANH).build())
.layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(3).nOut(3).build());
MultiLayerNetwork mln = new MultiLayerNetwork(builder.build());
mln.init();
@ -119,7 +119,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,7 +129,7 @@ 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();
@ -188,7 +188,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 +203,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();
@ -294,23 +294,23 @@ public class BNGradientCheckTest extends BaseDL4JTest {
LossFunctions.LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
MultiLayerConfiguration.Builder builder =
new NeuralNetConfiguration.Builder()
.dataType(DataType.DOUBLE)
.l2(l2vals[j])
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
.updater(new NoOp())
.dist(new UniformDistribution(-2, 2)).seed(12345L).list()
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(4)
.activation(afn).build())
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).build())
.layer(2, new DenseLayer.Builder().nIn(4).nOut(4).build())
.layer(3, new BatchNormalization.Builder().useLogStd(useLogStd).build())
.layer(4, new OutputLayer.Builder(lf)
.activation(outputActivation).nOut(nOut)
.build());
NeuralNetConfiguration.NeuralNetConfigurationBuilder builder =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.l2(l2vals[j])
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
.updater(new NoOp())
.dist(new UniformDistribution(-2, 2)).seed(12345L).list()
.layer(0, new DenseLayer.Builder().nIn(nIn).nOut(4)
.activation(afn).build())
.layer(1, new BatchNormalization.Builder().useLogStd(useLogStd).build())
.layer(2, new DenseLayer.Builder().nIn(4).nOut(4).build())
.layer(3, new BatchNormalization.Builder().useLogStd(useLogStd).build())
.layer(4, new OutputLayer.Builder(lf)
.activation(outputActivation).nOut(nOut)
.build());
MultiLayerConfiguration conf = builder.build();
NeuralNetConfiguration conf = builder.build();
MultiLayerNetwork mln = new MultiLayerNetwork(conf);
mln.init();
@ -370,7 +370,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()
@ -414,7 +414,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,7 +424,7 @@ 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();
@ -457,7 +457,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 +526,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())

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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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,8 +26,8 @@ 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.NeuralNetConfiguration.NeuralNetConfigurationBuilder;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.*;
@ -100,15 +100,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();
@ -186,7 +186,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 +198,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();
@ -269,8 +269,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 +281,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);
@ -334,8 +334,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 +349,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);
@ -403,8 +403,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 +416,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);
@ -472,8 +472,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 +488,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);
@ -546,8 +546,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 +562,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 +606,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 +623,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 +672,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 +688,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 +742,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 +758,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 +808,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 +823,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 +881,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 +892,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);
@ -971,7 +969,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 +979,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 +1041,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 +1052,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 +1114,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 +1138,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 +1188,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 +1206,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 +1275,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 +1291,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()
@ -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();
@ -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()
@ -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();

View File

@ -26,7 +26,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.RNNFormat;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
@ -74,7 +73,7 @@ public class GradientCheckTests extends BaseDL4JTest {
public void testMinibatchApplication() {
IrisDataSetIterator iter = new IrisDataSetIterator(30, 150);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().miniBatch(false)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().miniBatch(false)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).updater(new NoOp())
.list()
@ -164,7 +163,7 @@ public class GradientCheckTests extends BaseDL4JTest {
LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).updater(new NoOp())
.seed(12345L)
@ -253,8 +252,8 @@ public class GradientCheckTests extends BaseDL4JTest {
double l2 = l2vals[k];
double l1 = l1vals[k];
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().l2(l2).l1(l1)
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().l2(l2).l1(l1)
.dataType(DataType.DOUBLE)
.l2Bias(biasL2[k]).l1Bias(biasL1[k])
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)
@ -325,7 +324,7 @@ public class GradientCheckTests extends BaseDL4JTest {
labels.putScalar(new int[] {i, r.nextInt(3)}, 1.0);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().l2(0.2).l1(0.1)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().l2(0.2).l1(0.1)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).seed(12345L)
.list().layer(new EmbeddingLayer.Builder().nIn(4).nOut(3).weightInit(WeightInit.XAVIER)
@ -363,7 +362,7 @@ public class GradientCheckTests extends BaseDL4JTest {
labels.putScalar(new int[] {i, r.nextInt(3)}, 1.0);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().l2(0.2).l1(0.1)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().l2(0.2).l1(0.1)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).seed(12345L)
.list().layer(0,
@ -429,8 +428,8 @@ public class GradientCheckTests extends BaseDL4JTest {
double l1 = l1vals[k];
Nd4j.getRandom().setSeed(12345);
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.l2(l2).l1(l1)
@ -491,7 +490,7 @@ public class GradientCheckTests extends BaseDL4JTest {
for(Activation a : new Activation[]{Activation.IDENTITY, Activation.TANH}) {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).updater(new NoOp())
.seed(12345L)
@ -561,7 +560,7 @@ public class GradientCheckTests extends BaseDL4JTest {
for (boolean maskArray : new boolean[]{false, true}) {
for (int inputRank : new int[]{2, 3}) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.seed(12345)
.updater(new NoOp())
@ -672,8 +671,8 @@ public class GradientCheckTests extends BaseDL4JTest {
double l2 = l2vals[k];
double l1 = l1vals[k];
MultiLayerConfiguration conf =
new NeuralNetConfiguration.Builder().l2(l2).l1(l1)
NeuralNetConfiguration conf =
NeuralNetConfiguration.builder().l2(l2).l1(l1)
.dataType(DataType.DOUBLE)
.l2Bias(biasL2[k]).l1Bias(biasL1[k])
.weightDecay(wdVals[k]).weightDecayBias(wdBias[k])
@ -736,7 +735,7 @@ public class GradientCheckTests extends BaseDL4JTest {
LossFunction lf = lossFunctions[i];
Activation outputActivation = outputActivations[i];
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).updater(new NoOp())
.seed(12345L)

View File

@ -36,9 +36,6 @@ import org.deeplearning4j.nn.conf.graph.rnn.ReverseTimeSeriesVertex;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.*;
import org.deeplearning4j.nn.conf.layers.recurrent.SimpleRnn;
import org.deeplearning4j.nn.conf.preprocessor.CnnToFeedForwardPreProcessor;
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;
import org.deeplearning4j.nn.conf.preprocessor.RnnToFeedForwardPreProcessor;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
@ -52,7 +49,6 @@ import org.nd4j.linalg.indexing.NDArrayIndex;
import org.nd4j.linalg.learning.config.NoOp;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;
@ -74,7 +70,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
@Test
public void testBasicIris() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1)).updater(new NoOp())
@ -120,7 +116,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
@Test
public void testBasicIrisWithMerging() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1)).updater(new NoOp())
@ -177,7 +173,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
for (ElementWiseVertex.Op op : ops) {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -235,7 +231,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
for (ElementWiseVertex.Op op : ops) {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -295,7 +291,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
for(boolean firstSmaller : new boolean[]{false, true}) {
for (ElementWiseVertex.Op op : ops) {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.updater(new NoOp())
.dataType(DataType.DOUBLE)
.activation(Activation.TANH)
@ -343,7 +339,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
String msg = "testCnnDepthMerge - " + format;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 0.1))
@ -398,7 +394,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int outSize = 3;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf =
new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new UniformDistribution(0.2, 0.6))
@ -457,7 +453,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int batchSize = 2;
int timeSeriesLength = 4;
int inLength = 3;
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(1234)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(1234)
.dataType(DataType.DOUBLE)
.weightInit(new NormalDistribution(0, 1))
.updater(new NoOp()).graphBuilder().addInputs("input").setOutputs("out")
@ -493,7 +489,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
public void testLSTMWithLastTimeStepVertex() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -545,7 +541,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int timeSeriesLength = 4;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf =
new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -595,7 +591,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int timeSeriesLength = 4;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf =
new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -654,7 +650,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
public void testMultipleInputsLayer() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -697,7 +693,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
@Test
public void testMultipleOutputsLayer() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -737,7 +733,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
@Test
public void testMultipleOutputsMergeVertex() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -786,7 +782,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int inW = 7;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -836,7 +832,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
public void testBasicIrisTripletStackingL2Loss() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf =
new NeuralNetConfiguration.Builder().seed(12345)
NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -910,7 +906,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
for (boolean train : trainFirst) {
for (double lambda : new double[] {0.0, 0.5, 2.0}) {
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new GaussianDistribution(0, 1))
@ -975,7 +971,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
for (boolean train : trainFirst) {
for (double lambda : new double[] {0.0, 0.5, 2.0}) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
@ -986,7 +982,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
.alpha(1.0).lambda(lambda).gradientCheck(true)
.activation(Activation.SOFTMAX).build())
.setInputType(InputType.convolutional(inputH, inputW, inputDepth)).build();
.inputType(InputType.convolutional(inputH, inputW, inputDepth)).build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
@ -1029,7 +1025,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
@Test
public void testBasicL2() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -1081,7 +1077,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int layerSizes = 2;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -1136,7 +1132,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
public void testBasicStackUnstackDebug() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -1196,7 +1192,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int layerSizes = 2;
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -1259,7 +1255,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
public void testBasicTwoOutputs() {
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -1320,7 +1316,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int[][] definitions = {null,new int[]{1}};
for(int[] definition : definitions) {
log.info("Testing definition {}",definition);
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.activation(Activation.TANH).updater(new NoOp()).graphBuilder()
@ -1368,7 +1364,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
int w = 4;
int dIn = 2;
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().seed(12345)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.dist(new NormalDistribution(0, 1))
@ -1420,7 +1416,7 @@ public class GradientCheckTestsComputationGraph extends BaseDL4JTest {
labels.putScalar(new int[] {i, r.nextInt(3)}, 1.0);
}
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().l2(0.2).l1(0.1)
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder().l2(0.2).l1(0.1)
.dataType(DataType.DOUBLE)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).seed(12345L)
.updater(new NoOp()).graphBuilder().addInputs("in")

View File

@ -24,7 +24,6 @@ import lombok.val;
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.RNNFormat;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
@ -117,7 +116,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
maskArr.putScalar(new int[] {0, j}, mask[i][j] ? 1.0 : 0.0);
}
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345L)
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().seed(12345L)
.dataType(DataType.DOUBLE)
.updater(new NoOp())
.list()
@ -158,7 +157,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
int testNum = 0;
for (INDArray mask : masks) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 1.0)).seed(12345L).list()
@ -238,7 +237,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
Activation a = act[i];
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new NoOp())
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 1)).seed(12345)
.list()
@ -332,7 +331,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
Activation a = act[i];
Nd4j.getRandom().setSeed(12345);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().updater(new NoOp())
NeuralNetConfiguration conf = NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 1)).seed(12345)
.list()
@ -341,7 +340,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
.layer(1, new RnnOutputLayer.Builder().nIn(layerSize).nOut(nOut).lossFunction(lf)
.activation(a).build())
.validateOutputLayerConfig(false)
.setInputType(InputType.recurrent(nIn,tsLength, RNNFormat.NCW))
.inputType(InputType.recurrent(nIn,tsLength, RNNFormat.NCW))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -365,7 +364,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
//Check the equivalent compgraph:
Nd4j.getRandom().setSeed(12345);
ComputationGraphConfiguration cg = new NeuralNetConfiguration.Builder().updater(new NoOp())
ComputationGraphConfiguration cg = NeuralNetConfiguration.builder().updater(new NoOp())
.dataType(DataType.DOUBLE)
.dist(new NormalDistribution(0, 2)).seed(12345)
.graphBuilder().addInputs("in")
@ -397,7 +396,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
int mb = 4;
int tsLength = 5;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
NeuralNetConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.weightInit(new NormalDistribution(0,2))
.updater(new NoOp())
@ -405,7 +404,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
.layer(new LSTM.Builder().nIn(3).nOut(3).build())
.layer(new GlobalPoolingLayer.Builder().poolingType(PoolingType.AVG).build())
.layer(new OutputLayer.Builder().nIn(3).nOut(3).activation(Activation.SOFTMAX).build())
.setInputType(InputType.recurrent(3))
.inputType(InputType.recurrent(3))
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
@ -452,7 +451,7 @@ public class GradientCheckTestsMasking extends BaseDL4JTest {
int mb = 10;
int tsLength = 5;
ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
ComputationGraphConfiguration conf = NeuralNetConfiguration.builder()
.dataType(DataType.DOUBLE)
.weightInit(new NormalDistribution(0,2))
.updater(new NoOp())

View File

@ -22,8 +22,8 @@ package org.deeplearning4j.gradientcheck;
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.NeuralNetConfiguration.NeuralNetConfigurationBuilder;
import org.deeplearning4j.nn.conf.distribution.NormalDistribution;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
@ -68,7 +68,7 @@ public class LRNGradientCheckTests extends BaseDL4JTest {
labels.putScalar(i, r.nextInt(nOut), 1.0);
}
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()
@ -77,7 +77,7 @@ public class LRNGradientCheckTests extends BaseDL4JTest {
.layer(1, new LocalResponseNormalization.Builder().build())
.layer(2, 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();

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