增加模版内图片大小设置错误的抛错处理

pull/1/head
lidapeng 5 years ago
parent b131db500c
commit 149aabd801

@ -260,6 +260,10 @@
randomForest.study();
//插入特征数据,森林对该数据的最终分类结果进行判断
randomForest.forest(Object objcet);
###常见抛错
* error:Wrong size setting of image in templateConfig
* 原因是模版配置类图片宽高设置相差太大
> templeConfig.init(StudyPattern.Accuracy_Pattern, true, width, height, 1);
#### 最终说明
* TempleConfig()配置模版类一定要静态在内存中长期持有检测的时候不要每次都NEW
一直就使用一个配置类就可以了。

@ -89,37 +89,41 @@ public abstract class Nerve {
}
protected Matrix dynamicNerve(Matrix matrix, long eventId, boolean isStudy) throws Exception {//动态矩阵处理
Matrix powerMatrix = null;
if (isStudy) {
if (!matrixMap.containsKey(eventId)) {
matrixMap.put(eventId, new Matrix(3, 3));
}
powerMatrix = matrixMap.get(eventId);
}
int xn = matrix.getX();
int yn = matrix.getY();
int x = xn / 3;//线性变换后矩阵的行数
int y = yn / 3;//线性变换后矩阵的列数
int nub = x * y;//个数
Matrix myMatrix = new Matrix(x, y);//线性变化后的矩阵
for (int i = 0; i < xn - 3; i += 3) {
for (int j = 0; j < yn - 3; j += 3) {
//取出矩阵分块 并相加
if (isStudy) {
powerMatrix = MatrixOperation.add(powerMatrix, matrix.getSonOfMatrix(i, j, 3, 3));
if (xn > 3 && yn > 3) {
Matrix powerMatrix = null;
if (isStudy) {
if (!matrixMap.containsKey(eventId)) {
matrixMap.put(eventId, new Matrix(3, 3));
}
double dm = MatrixOperation.convolution(matrix, nerveMatrix, i, j);
//dm = ArithUtil.sub(ArithUtil.div(dm, 9), threshold);//减偏置项
dm = dm / 9 - threshold;
//设置输出矩阵 经过激活函数
myMatrix.setNub(i / 3, j / 3, activeFunction.function(dm));
powerMatrix = matrixMap.get(eventId);
}
int x = xn / 3;//线性变换后矩阵的行数
int y = yn / 3;//线性变换后矩阵的列数
int nub = x * y;//个数
Matrix myMatrix = new Matrix(x, y);//线性变化后的矩阵
for (int i = 0; i < xn - 3; i += 3) {
for (int j = 0; j < yn - 3; j += 3) {
//取出矩阵分块 并相加
if (isStudy) {
powerMatrix = MatrixOperation.add(powerMatrix, matrix.getSonOfMatrix(i, j, 3, 3));
}
double dm = MatrixOperation.convolution(matrix, nerveMatrix, i, j);
//dm = ArithUtil.sub(ArithUtil.div(dm, 9), threshold);//减偏置项
dm = dm / 9 - threshold;
//设置输出矩阵 经过激活函数
myMatrix.setNub(i / 3, j / 3, activeFunction.function(dm));
}
}
//取平均值
if (isStudy) {
MatrixOperation.mathMul(powerMatrix, ArithUtil.div(1, nub));
}
return myMatrix;
} else {
throw new Exception("Wrong size setting of image in templateConfig");
}
//取平均值
if (isStudy) {
MatrixOperation.mathMul(powerMatrix, ArithUtil.div(1, nub));
}
return myMatrix;
}
public void sendMatrix(long eventId, Matrix parameter, boolean isStudy,

@ -61,8 +61,12 @@ public class OutNerve extends Nerve {
Matrix myMatrix = dynamicNerve(matrix, eventId, isKernelStudy);
if (isKernelStudy) {//回传
Matrix matrix1 = matrixMapE.get(E);
double g = getGradient(myMatrix, matrix1);
backMatrix(g, eventId);
if (matrix1.getX() <= myMatrix.getX() && matrix1.getY() <= myMatrix.getY()) {
double g = getGradient(myMatrix, matrix1);
backMatrix(g, eventId);
} else {
throw new Exception("Wrong size setting of image in templateConfig");
}
} else {//卷积层输出
if (outBack != null) {
outBack.getBackMatrix(myMatrix, eventId);

@ -22,9 +22,7 @@ import java.util.Map;
*/
public class HelloWorld {
public static void main(String[] args) throws Exception {
int a = ModelData.DATA2.length();
System.out.println(a);
//test();
test();
//testPic();
//testModel();
}
@ -33,18 +31,19 @@ public class HelloWorld {
public static void test() throws Exception {
Picture picture = new Picture();
TempleConfig templeConfig = new TempleConfig();
templeConfig.setHavePosition(true);
// templeConfig.setHavePosition(true);
// Frame frame = new Frame();
// frame.setWidth(3024);
// frame.setHeight(4032);
// frame.setLengthHeight(100);
// frame.setLengthWidth(100);
// templeConfig.setFrame(frame);
ModelParameter modelParameter = JSONObject.parseObject(ModelData.DATA2, ModelParameter.class);
//ModelParameter modelParameter1 = JSONObject.parseObject(ModelData.DATA, ModelParameter.class);
templeConfig.init(StudyPattern.Accuracy_Pattern, true, 3204, 4032, 1);
templeConfig.insertModel(modelParameter);
templeConfig.init(StudyPattern.Accuracy_Pattern, true, 1076, 1436, 1);
Operation operation = new Operation(templeConfig);
Matrix right = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/s1.jpeg");
operation.learning(right, 1, false);
// for (int i = 1; i < 120; i++) {//faster rcnn神经网络学习
// System.out.println("study==" + i);
// //读取本地URL地址图片,并转化成矩阵
@ -57,13 +56,13 @@ public class HelloWorld {
// }
// templeConfig.boxStudy();//边框聚类
// //精准模式在全部学习结束的时候一定要使用此方法,速度模式不要调用此方法
templeConfig.startLvq();//原型向量量化
templeConfig.boxStudy();//边框回归
for (int j = 1; j < 2; j++) {
Matrix right = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/c/c" + j + ".png");
Map<Integer, List<FrameBody>> map = operation.lookWithPosition(right, j);
System.out.println("j===" + j);
}
// templeConfig.startLvq();//原型向量量化
// templeConfig.boxStudy();//边框回归
// for (int j = 1; j < 2; j++) {
// Matrix right = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/c/c" + j + ".png");
// Map<Integer, List<FrameBody>> map = operation.lookWithPosition(right, j);
// System.out.println("j===" + j);
// }
//测试集图片,进行识别测试
// for (int j = 121; j < 140; j++) {
// Matrix right = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/c/c" + j + ".png");

Loading…
Cancel
Save