我的网络:33 * 61(2013)输入节点。 1个隐藏层中的2000个节点。 45(对于45个字符)输出节点。
BasicNetwork basicNetwork = EncogUtility.simpleFeedForward(trainSet.getInputSize(), 2000, 0, trainSet.getIdealSize(), false);
构建训练集代码(它在循环内运行):
NormalizedField c = new NormalizedField(NormalizationAction.Normalize,"color", 255,0,1,0);
BufferedImage image = ImageIO.read(file);
BasicMLData data = new BasicMLData(width*height);
for(int i = 0;i<width;i++){
for(int j = 0;j<height;j++){
Color color = new Color(image.getRGB(i,j));
double value = c.normalize(color.getBlue());
data.add(i*height+j,value);
}
}
final MLData ideal = new BasicMLData(charList.length());
for (int i = 0; i < charList.length(); i++) {
if (i == charList.indexOf(e)) {
ideal.setData(i, 1);
} else {
ideal.setData(i, 0);
}
}
training.add(data,ideal);
培训代码:
int i = 0;
final ResilientPropagation rp = new ResilientPropagation(network,trainSet);
do {
rp.iteration();
i++;
System.out.println("Error rate: " + rp.getError());
if(i > 10){
i = 0;
EncogDirectoryPersistence.saveObject(new File("myneural.eg"),network);
}
} while (rp.getError() >= 0.01 ) ;
我训练了45个字符,每个字符有300张图片(图像是单色的,因此r / b / g值相同),错误率为~0.02。 但是当训练完成时,它甚至无法计算/分类训练数据。 我的测试代码:
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
System.out.println("Width: " + width + " Height: " + height);
BasicMLData data = new BasicMLData(width*height);
NormalizedField c = new NormalizedField(NormalizationAction.Normalize,"color", 255,0,1,0);
for(int i = 0;i<width;i++){
for(int j = 0;j<height;j++){
Color color = new Color(image.getRGB(i,j));
double value = c.normalize(color.getBlue());
data.add(i*height+j,value);
}
}
MLData compute = basicNetwork.compute(data);
但是当我尝试分类时,正确的char仍然具有非常低的价值。我已经使用各种字符(在训练集中)进行了测试,但Encog总是将错误的字符分类。
答案 0 :(得分:0)
也许你应该从替换这一行开始:
data.add(i*height+j,value);
用这个:
data.add(i+ (j*width),value);