Encog输入图层大小限制

时间:2014-12-06 22:53:06

标签: java machine-learning image-recognition encog

我使用带有Java的Encog框架来创建图像识别系统。然而,当我将Downsample的宽度和高度设置为100以上时,我得到了

 java.lang.NegativeArraySizeException

尝试创建网络时。

输入层中的神经元数量是否有限制?

    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...");
    }

}

1 个答案:

答案 0 :(得分:1)

在您的内存耗尽之前,您可以在Encog神经网络的输入层中放置多少个神经元没有限制。

当您要求“下采样器”将图像下采样到大于源图像的大小时,通常会发生上述错误。我想这将是一个“上传”。我相信你会遇到这个错误,因为你的最小图像小于100像素。下采样器目前只允许大于您希望缩减采样的图像。

我刚刚为此添加了一条Encog错误消息,下一版本的Encog将抛出:

org.encog.EncogError:无法上传。您不能下采样10x10到​​200x200     at org.encog.util.downsample.RGBDownsample.validate(RGBDownsample.java:403)     at org.encog.util.downsample.SimpleIntensityDownsample.downSample(SimpleIntensityDownsample.java:55) ...