2

I´m following the instructions given in the book 'Use Encog c#' where I´ve had to redesign some of the code to fit my needs.

I´m working with image Datasets, I load one 'category' into the network at a time, train it, save it and proceed with the next 'category' in a console program.

This is how I create my neural network:

  public BasicNetwork CreateNetwork(ImageMLDataSet training)
    {
        var network = EncogUtility.SimpleFeedForward(training.InputSize, 100, 0, training.IdealSize, true);

        return network;
    }

and my trainingset: The imageDict is a Dictionary variable

 public ImageMLDataSet CreateTraining()
    {
        var downsample = new RGBDownsample();
        var training = new ImageMLDataSet(downsample, false, -1, 1);

        foreach (var item in imageDict)
        {
            ImageMLData data = new ImageMLData(item.Value);
            training.Add(data);
        }
        Console.WriteLine("Training set created");

        return training;
    }

after this I assign ID's to my images using 'ImagePair' (in my case as a dictionary instead of a class) And process it to ImageMLData.

The Error Occurs within this method, when the 'EncogUtility.TrainConsole(train, network, training, minutes);' is called.

public void TrainNetwork(BasicNetwork network, IMLDataSet training)
    {
        float minutes = 1;
        double strategyError = 0.25;
        int strategyCycles = 50;

        Console.WriteLine("Training initiated...");
        var train = new ResilientPropagation(network, training);

        try
        {                
            train.AddStrategy(new ResetStrategy(strategyError, strategyCycles));

            EncogUtility.TrainConsole(train, network, training, minutes);
        }
        catch(Exception e)
        {
            Console.WriteLine("Error at: " + e);
        }

        Console.WriteLine("Training stopped");

    }

When I run this I catch the exception:

Error at: Encog.EncogError: Nested Exception ---> System.NullReferenceException: Object reference is not set to an instance of an object at Encog.MathUtil.Error.ErrorCalculation.UpdateError(Double[] actual, IMLData ideal, Double significance) ved Encog.Neural.Networks.Training.Propagation.GradientWorker.Process(IMLDataPair pair) at Encog.Neural.Networks.Training.Propagation.GradientWorker.Run() --- Slut på staksporing af indre undtagelser --- at Encog.Neural.Networks.Training.Propagation.Propagation.Iteration()
at Encog.Util.Simple.EncogUtility.TrainConsole(IMLTrain train, BasicNetwork network, IMLDataSet trainingSet, Double seconds) at TreeSorting.NeuralNetwork.TrainNetwork(BasicNetwork network, IMLDataSet training) in C:\Dokumenter\Monosoft\Monosoft Project\ConsoleApp1\NeuralNetwork.cs:line 180

Thanks in advance :)

  • hi, I´m new to asking here and I was not aware that a picture was not wanted, but rather the text. I´ll fix that now, thanks :) – Tanya Dørr Holst Oct 03 '18 at 10:42
  • Before I can comment further, the error seems to be outside the function above, I would expect it somewhere before where you are initializing the network before calling TrainNetwork(network, training). – Gunnar Sigfusson Oct 03 '18 at 10:58
  • I tried to give a description and the process with some code in the original post (in the beginning) :) – Tanya Dørr Holst Oct 03 '18 at 11:09
  • OK, start with changing the line in the NetworkCreation-function to: BasicNetwork network = EncogUtility.SimpleFeedForward(training.InputSize, 100, 0, training.IdealSize, true). Then maybe same with the other code. It is better not to use variants ("var") I think but it is a long time since I programmed in C# and even longer time since I dealt with neuronal networks – Gunnar Sigfusson Oct 05 '18 at 10:35
  • I´ll be damned.... it's training the network now... xD Thankyou very much!!! – Tanya Dørr Holst Oct 05 '18 at 11:06

1 Answers1

2

For others searching for solutions to this type of problem:

I solved this by changeing the 'var' when I declared new variables and that seemed to solve my issue. thanks to GunnarSigfusson for the answer that fixed it c: