Du_
Du_

Reputation: 965

Encog input layer size limit

I'm using Encog framework with Java to do an image recognition system. Nevertheless, when I set the Downsample width and height above 100, I'm getting a

 java.lang.NegativeArraySizeException

while trying to create the network.

Is there a limit for the number of neurons in the input layer ?

    public class PlateNetwork {

    protected final List<RawImage> imageList;
    protected ImageMLDataSet imageMLDataSet;
    protected Downsample downsample;
    protected Size downsampleSize;
    protected int outputLayerSize;
    protected BasicNetwork network;

    public PlateNetwork () {
        imageList = new ArrayList<>();
        outputLayerSize = Neuron.getTotalNeurons();
        downsample = new SimpleIntensityDownsample();
        downsampleSize = new Size(200, 150);
        imageMLDataSet = new ImageMLDataSet(downsample, false, 1, -1);
    }

    public void processNN() {
        inputImages();
        createNetwork();
        initTraining();
    }

    private void inputImages() {
        RawImage rawImage;
        File[] inputImages = Global.inputFolder.listFiles();
        int inputLength = inputImages.length;

        for (int i = 0; i < inputLength; i++) {
            rawImage = new RawImage(inputImages[i], Neuron.BOL_PLATE);
            imageList.add(rawImage);
            imageMLDataSet.add(rawImage.getImageMLData(), rawImage.getIdeal());
        }
    }


    private void createNetwork() {
        final int inputLayerSize = downsampleSize.getArea();
        final int hiddenLayerSize = (inputLayerSize + outputLayerSize) * 2/3;
        final int hiddenLayer1Neurons = hiddenLayerSize;
        final int hiddenLayer2Neurons = hiddenLayerSize;

        imageMLDataSet.downsample(downsampleSize.getHeight(), downsampleSize.getWidth());
        network = EncogUtility.simpleFeedForward( imageMLDataSet.getInputSize(),
                                                  hiddenLayer1Neurons,
                                                  hiddenLayer2Neurons,
                                                  imageMLDataSet.getIdealSize(),
                                                  true);
    }

    private void initTraining() {
        final int trainingMinutes = 1;
        final double strategyError = 0.25;
        final int strategyCycles = 50;

        final ResilientPropagation train = new ResilientPropagation(network, imageMLDataSet);
        train.addStrategy(new ResetStrategy(strategyError, strategyCycles));

        EncogUtility.trainConsole(train, network, imageMLDataSet, trainingMinutes);
        System.out.println("Training Stopped...");
    }

}

Upvotes: 1

Views: 330

Answers (1)

JeffHeaton
JeffHeaton

Reputation: 3278

There is no limit on how many neurons you can place in the input layer of an Encog neural network, until you run out of memory.

The above error typically occurs when you ask the "downsampler" to downsample an image to a size larger than the source image. Which would be an "upsample" I guess. I believe that you are hitting that error because your smallest image is less than 100 pixels. The downsampler currently only allows images bigger than what you wish to downsample to.

I just added an Encog error message for that, the next version of Encog will throw:

org.encog.EncogError: Can't upsample. You can't downsample a 10x10 to 200x200 at org.encog.util.downsample.RGBDownsample.validate(RGBDownsample.java:403) at org.encog.util.downsample.SimpleIntensityDownsample.downSample(SimpleIntensityDownsample.java:55) ...

Upvotes: 1

Related Questions