Search in sources :

Example 16 with DL4JException

use of org.deeplearning4j.exception.DL4JException in project deeplearning4j by deeplearning4j.

the class TestInvalidConfigurations method testDenseNout0.

@Test
public void testDenseNout0() {
    try {
        MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new DenseLayer.Builder().nIn(10).nOut(0).build()).layer(1, new OutputLayer.Builder().nIn(10).nOut(10).build()).build();
        MultiLayerNetwork net = new MultiLayerNetwork(conf);
        net.init();
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testDenseNout0(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) DL4JException(org.deeplearning4j.exception.DL4JException) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) DL4JException(org.deeplearning4j.exception.DL4JException) Test(org.junit.Test)

Example 17 with DL4JException

use of org.deeplearning4j.exception.DL4JException in project deeplearning4j by deeplearning4j.

the class TestInvalidConfigurations method testCnnInvalidConfigOrInput_SmallerDataThanKernel.

@Test
public void testCnnInvalidConfigOrInput_SmallerDataThanKernel() {
    //Idea: same as testCnnInvalidConfigPaddingStridesHeight() but network is fed incorrect sized data
    // or equivalently, network is set up without using InputType functionality (hence missing validation there)
    int depthIn = 3;
    int hIn = 10;
    int wIn = 10;
    MultiLayerConfiguration conf = new 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).build()).setInputType(InputType.convolutional(hIn, wIn, depthIn)).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    try {
        net.feedForward(Nd4j.create(3, depthIn, 5, 5));
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testCnnInvalidConfigOrInput_SmallerDataThanKernel(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) DL4JException(org.deeplearning4j.exception.DL4JException) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) DL4JException(org.deeplearning4j.exception.DL4JException) Test(org.junit.Test)

Example 18 with DL4JException

use of org.deeplearning4j.exception.DL4JException in project deeplearning4j by deeplearning4j.

the class TestInvalidConfigurations method testCnnInvalidConfigOrInput_BadStrides.

@Test
public void testCnnInvalidConfigOrInput_BadStrides() {
    //Idea: same as testCnnInvalidConfigPaddingStridesHeight() but network is fed incorrect sized data
    // or equivalently, network is set up without using InputType functionality (hence missing validation there)
    int depthIn = 3;
    int hIn = 10;
    int wIn = 10;
    //Invalid: (10-3+0)/2+1 = 4.5
    MultiLayerConfiguration conf = new 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).build()).inputPreProcessor(1, new CnnToFeedForwardPreProcessor()).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    try {
        net.feedForward(Nd4j.create(3, depthIn, hIn, wIn));
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testCnnInvalidConfigOrInput_BadStrides(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) CnnToFeedForwardPreProcessor(org.deeplearning4j.nn.conf.preprocessor.CnnToFeedForwardPreProcessor) DL4JException(org.deeplearning4j.exception.DL4JException) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) DL4JException(org.deeplearning4j.exception.DL4JException) Test(org.junit.Test)

Example 19 with DL4JException

use of org.deeplearning4j.exception.DL4JException in project deeplearning4j by deeplearning4j.

the class TestInvalidConfigurations method testCnnInvalidConfigPaddingStridesHeight.

@Test
public void testCnnInvalidConfigPaddingStridesHeight() {
    //Idea: some combination of padding/strides are invalid.
    int depthIn = 3;
    int hIn = 10;
    int wIn = 10;
    try {
        MultiLayerConfiguration conf = new 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();
        MultiLayerNetwork net = new MultiLayerNetwork(conf);
        net.init();
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testCnnInvalidConfigPaddingStridesHeight(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) DL4JException(org.deeplearning4j.exception.DL4JException) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) DL4JException(org.deeplearning4j.exception.DL4JException) Test(org.junit.Test)

Example 20 with DL4JException

use of org.deeplearning4j.exception.DL4JException in project deeplearning4j by deeplearning4j.

the class TestInvalidConfigurations method testLSTMNOut0.

@Test
public void testLSTMNOut0() {
    try {
        MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new GravesLSTM.Builder().nIn(10).nOut(0).build()).layer(1, new RnnOutputLayer.Builder().nIn(10).nOut(10).build()).build();
        MultiLayerNetwork net = new MultiLayerNetwork(conf);
        net.init();
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testLSTMNOut0(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) DL4JException(org.deeplearning4j.exception.DL4JException) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) DL4JException(org.deeplearning4j.exception.DL4JException) Test(org.junit.Test)

Aggregations

DL4JException (org.deeplearning4j.exception.DL4JException)25 Test (org.junit.Test)25 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)20 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)20 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)8 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 DoubleWritable (org.datavec.api.writable.DoubleWritable)3 IntWritable (org.datavec.api.writable.IntWritable)3 RecordReaderDataSetIterator (org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator)3 SequenceRecordReaderDataSetIterator (org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator)3 ConvolutionLayer (org.deeplearning4j.nn.conf.layers.ConvolutionLayer)3 INDArray (org.nd4j.linalg.api.ndarray.INDArray)3 DataSet (org.nd4j.linalg.dataset.api.DataSet)3 CollectionSequenceRecordReader (org.datavec.api.records.reader.impl.collection.CollectionSequenceRecordReader)2 Writable (org.datavec.api.writable.Writable)2 ConvolutionMode (org.deeplearning4j.nn.conf.ConvolutionMode)2 DataSetIterator (org.nd4j.linalg.dataset.api.iterator.DataSetIterator)2 CollectionRecordReader (org.datavec.api.records.reader.impl.collection.CollectionRecordReader)1 ComputationGraphConfiguration (org.deeplearning4j.nn.conf.ComputationGraphConfiguration)1