prob running saved network....

ucicelos
2008-11-04
2013-04-16
  • ucicelos
    ucicelos
    2008-11-04

    Hi guys,

    I have saved a network (saved it inside netValidated) , but when i am trying to load and run it I am getting following error...

    Exception in thread "Thread-1" java.lang.NullPointerException
            at org.joone.engine.Layer.fireFwdGet(Layer.java:237)
            at org.joone.engine.Layer.fwdRun(Layer.java:1351)
            at org.joone.net.NeuralNet.stepForward(NeuralNet.java:1161)
            at org.joone.net.NeuralNet.fastRun(NeuralNet.java:1113)
            at org.joone.net.NeuralNet.fastRun(NeuralNet.java:1075)
            at org.joone.net.NeuralNet$1.run(NeuralNet.java:1011)
            at java.lang.Thread.run(Thread.java:619)

    following is the code for my function, which is pretty much straight out of the example in the guide...any pointers towards what I might be doing wrong??

    public double[] useMyNetwork( double[][] inputArray, String filename){
               double [] results;
              
              
         //NeuralNetLoader loader  = new NeuralNetLoader(filename);
         //NeuralNet net = loader.getNeuralNet();
           NeuralNet net = this.restoreNeuralNet(filename);
        
           if(net!=null){
                  Layer output = net.getOutputLayer();
                   Layer input = net.getInputLayer();
      

                     input.removeAllInputs();
                      MemoryInputSynapse meminp = new MemoryInputSynapse();
                     meminp.setFirstRow(1);
      
      
     
                   NormalizerPlugIn normIT = new NormalizerPlugIn();
                   normIT.setAdvancedSerieSelector("1-6");
                   normIT.setMin(0.05);
                   normIT.setMax(0.95);
                   meminp.setInputArray(inputArray);
                   meminp.setAdvancedColumnSelector("1-6");
                   meminp.addPlugIn(normIT)   ; 
                     input.addInputSynapse(meminp);
       
      
                   output.removeAllInputs();
                   MemoryOutputSynapse memout = new MemoryOutputSynapse();
                   output.addOutputSynapse(memout);
      
                   net.getMonitor().setTotCicles(1);
                   net.getMonitor().setTrainingPatterns(1);
                   net.getMonitor().setLearning(false);
                   net.go();
      
                   results = memout.getNextPattern();
                   net.stop();
               }
            results = new double[]{0,0};
               return results;
       }
      

        private NeuralNet restoreNeuralNet(String fileName) {
            NeuralNet nnet = null;
            try {
                FileInputStream stream = new FileInputStream(fileName);
                ObjectInput input = new ObjectInputStream(stream);
                nnet = (NeuralNet)input.readObject();
            } catch (Exception e) {
               System.out.print( "Exception was thrown. Message is : " + e.getMessage() );
            }
            return nnet;
        }

     
    • UeliHofstetter
      UeliHofstetter
      2008-11-07

      are you sure the inputArray is initialized? from the stack trace and the source code, the nullpointer exception is most likely caused by the fact that there aren't any inputlisteners of this layer. as far as i can remember the memorysynapse is only added as patternlistener if it is full.

      just guessing ... otherwhise you have to debug it.
      sorry

      kind regards

      u