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