gpt4 book ai didi

java - Encog 输入层大小限制

转载 作者:行者123 更新时间:2023-11-30 09:12:50 26 4
gpt4 key购买 nike

我正在使用 Encog 框架和 Java 来做一个图像识别系统。然而,当我将下采样宽度和高度设置为高于 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...");
}

}

最佳答案

在 Encog 神经网络的输入层中放置的神经元数量没有限制,直到内存耗尽为止。

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

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

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

关于java - Encog 输入层大小限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27337506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com