1

我正在使用带有 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...");
    }

}
4

1 回答 1

1

在 Encog 神经网络的输入层中可以放置多少个神经元是没有限制的,直到内存用完为止。

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

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

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

于 2014-12-08T12:59:26.977 回答