简体   繁体   中英

StackOverFlowError when trying to train neural network with Neuroph framework

I am trying to train a neural network using Neuroph library but I get this error:

44 [NeurophLearningThread] INFO org.neuroph.core.learning.LearningRule - Learning Started
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
    at java.lang.reflect.Method.invoke(Method.java:498)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    at org.neuroph.util.NeurophArrayList.writeObject(NeurophArrayList.java:710)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

The thing is, I used the same code to train a neural network in another project which has the same imported jars and it worked properly. Here is the code I used to create and train the NN:

public void TrainNeuralNetwork(double[] inputs, double[] outputs){


    DataSet set = new DataSet(inputs.length,outputs.length);
    set.addRow(inputs,outputs);

    System.out.println("Training...");
    MultiLayerPerceptron loadSnakeNN = new MultiLayerPerceptron(TransferFunctionType.LINEAR, inputs.length, 500, outputs.length);

    if( loadSnakeNN.getLearningRule() instanceof MomentumBackpropagation )
        ((MomentumBackpropagation)loadSnakeNN.getLearningRule()).setBatchMode(true);


    MomentumBackpropagation learningRule = (MomentumBackpropagation)loadSnakeNN.getLearningRule();// Set learningRule

    learningRule.setMaxError(0.01);
    loadSnakeNN.learn(set);
    loadSnakeNN.save("SnakeNN.nnet");
    System.out.println("Neural Network Trained!");
}

I found where the problem is. When I use more than 90 inputs I get the above error. So my new question is, how to train this neural network with more than 90 inputs?

You can increase the stack size available to your program by using JVM parameter -Xss .

`java -Xss2048m ...`

means that you get a stack of 2048Mb . If you're running this from your IDE you can search to find out how to pass JVM parameters for your specific IDE.

I'm assuming that there is no bug either in your code or the library, otherwise increasing the stack will probably not be enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM