Search in sources :

Example 6 with DL4JException

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

the class TestInvalidInput method testInputNinMismatchBidirectionalLSTM.

@Test
public void testInputNinMismatchBidirectionalLSTM() {
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new GravesBidirectionalLSTM.Builder().nIn(5).nOut(5).build()).layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).build()).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    try {
        net.fit(Nd4j.create(1, 10, 5), Nd4j.create(1, 5, 5));
        fail("Expected DL4JException");
    } catch (DL4JException e) {
        System.out.println("testInputNinMismatchBidirectionalLSTM(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected DL4JException");
    }
}
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 7 with DL4JException

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

the class TestInvalidInput method testInputNinMismatchConvolutional.

@Test
public void testInputNinMismatchConvolutional() {
    //Rank 4 input, but input depth does not match nIn depth
    int h = 16;
    int w = 16;
    int d = 3;
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).build()).layer(1, new OutputLayer.Builder().nOut(10).build()).setInputType(InputType.convolutional(h, w, d)).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    try {
        net.feedForward(Nd4j.create(1, 5, h, w));
        fail("Expected DL4JException");
    } catch (DL4JException e) {
        System.out.println("testInputNinMismatchConvolutional(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected DL4JException");
    }
}
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 8 with DL4JException

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

the class TestInvalidInput method testInvalidRnnTimeStep.

@Test
public void testInvalidRnnTimeStep() {
    //Idea: Using rnnTimeStep with a different number of examples between calls
    //(i.e., not calling reset between time steps)
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new GravesLSTM.Builder().nIn(5).nOut(5).build()).layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).build()).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    net.rnnTimeStep(Nd4j.create(3, 5, 10));
    try {
        net.rnnTimeStep(Nd4j.create(5, 5, 10));
        fail("Expected DL4JException");
    } catch (DL4JException e) {
        System.out.println("testInvalidRnnTimeStep(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected DL4JException");
    }
}
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 9 with DL4JException

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

the class TestInvalidInput method testInputNinRank2Convolutional.

@Test
public void testInputNinRank2Convolutional() {
    //Rank 2 input, instead of rank 4 input. For example, forgetting the
    int h = 16;
    int w = 16;
    int d = 3;
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new ConvolutionLayer.Builder().nIn(d).nOut(5).build()).layer(1, new OutputLayer.Builder().nOut(10).build()).setInputType(InputType.convolutional(h, w, d)).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    try {
        net.feedForward(Nd4j.create(1, 5 * h * w));
        fail("Expected DL4JException");
    } catch (DL4JException e) {
        System.out.println("testInputNinRank2Convolutional(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected DL4JException");
    }
}
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 10 with DL4JException

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

the class TestInvalidInput method testLabelsNOutMismatchRnnOutputLayer.

@Test
public void testLabelsNOutMismatchRnnOutputLayer() {
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().list().layer(0, new GravesLSTM.Builder().nIn(5).nOut(5).build()).layer(1, new RnnOutputLayer.Builder().nIn(5).nOut(5).build()).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    try {
        net.fit(Nd4j.create(1, 5, 8), Nd4j.create(1, 10, 8));
        fail("Expected DL4JException");
    } catch (DL4JException e) {
        System.out.println("testLabelsNOutMismatchRnnOutputLayer(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected DL4JException");
    }
}
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