添加边框回归

pull/1/head
lidapeng 6 years ago
parent 4be832f0d5
commit 320c1dffc9

@ -3,6 +3,13 @@ package org.wlld.imageRecognition;
import org.wlld.MatrixTools.Matrix;
import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.config.Kernel;
import org.wlld.imageRecognition.border.Border;
import org.wlld.imageRecognition.border.Frame;
import org.wlld.imageRecognition.border.FrameBody;
import org.wlld.tools.ArithUtil;
import java.util.ArrayList;
import java.util.List;
/**
* @author lidapeng
@ -10,35 +17,90 @@ import org.wlld.config.Kernel;
* @date 9:23 2020/1/2
*/
public class Convolution {
public Matrix getFeatures(Matrix matrix, int maxNub, boolean isBorder) throws Exception {
protected Matrix getFeatures(Matrix matrix, int maxNub, TempleConfig templeConfig
, int id) throws Exception {
boolean isFirst = true;
Border border = null;
if (id > -1 && templeConfig.isHavePosition()) {
border = new Border(templeConfig, matrix.getY() - 2, matrix.getX() - 2);
}
do {
matrix = convolution(matrix, Kernel.ALL_Two, isBorder);
matrix = convolution(matrix, Kernel.ALL_Two, isFirst, border, false);
isFirst = false;
}
while (matrix.getX() > maxNub && matrix.getY() > maxNub);
normalization(matrix);//矩阵做归一化处理
if (id > -1 && templeConfig.isHavePosition()) {
border.end(matrix, id);
}
while (matrix.getX() > maxNub && matrix.getY() > maxNub && !isBorder);
//已经不可以再缩小了,最后做一层卷积,然后提取最大值
return matrix;
}
private Matrix convolution(Matrix matrix, Matrix kernel, boolean isBorder) throws Exception {
private void normalization(Matrix matrix) throws Exception {
for (int i = 0; i < matrix.getX(); i++) {
for (int j = 0; j < matrix.getY(); j++) {
matrix.setNub(i, j, ArithUtil.div(matrix.getNumber(i, j), 10000000));
}
}
}
protected Border borderOnce(Matrix matrix, TempleConfig templeConfig) throws Exception {
Border border = new Border(templeConfig, matrix.getY() - 2, matrix.getX() - 2);
convolution(matrix, Kernel.ALL_Two, true, border, true);
return border;
}
protected List<FrameBody> getRegion(Matrix matrix, Frame frame) {
int xFrame = frame.getHeight();
int yFrame = frame.getWidth();
int x = matrix.getX();
int y = matrix.getY();
List<FrameBody> frameBodies = new ArrayList<>();
double xNub = frame.getLengthHeight();
double yNub = frame.getLengthWidth();
for (int i = 0; i < x - xFrame; i += xNub) {
for (int j = 0; j < y - yFrame; j += yNub) {
FrameBody frameBody = new FrameBody();
Matrix myMatrix = matrix.getSonOfMatrix(i, j, xFrame, yFrame);
frameBody.setMatrix(myMatrix);
frameBody.setX(i);
frameBody.setY(j);
frameBodies.add(frameBody);
}
}
return frameBodies;
}
private Matrix convolution(Matrix matrix, Matrix kernel, boolean isFirst
, Border border, boolean isOnce) throws Exception {
int x = matrix.getX() - 2;//求导后矩阵的行数
int y = matrix.getY() - 2;//求导后矩阵的列数
Matrix myMatrix = new Matrix(x, y);//最终合成矩阵
Matrix myMatrix = null;
if (!isOnce) {
myMatrix = new Matrix(x, y);//最终合成矩阵
}
for (int i = 0; i < x; i++) {//遍历行
for (int j = 0; j < y; j++) {//遍历每行的列
double dm = MatrixOperation.convolution(matrix, kernel, i, j);
if (dm > 0) {//存在边缘
myMatrix.setNub(i, j, dm);
if (isFirst && border != null) {
border.setPosition(i, j);
}
if (!isOnce) {
myMatrix.setNub(i, j, dm);
}
}
}
}
if (isBorder) {
return myMatrix;
if (isOnce) {
return null;
} else {
return late(myMatrix);
}
}
public Matrix late(Matrix matrix) throws Exception {//迟化处理
private Matrix late(Matrix matrix) throws Exception {//迟化处理
int xn = matrix.getX();
int yn = matrix.getY();
int x = xn / 2;//求导后矩阵的行数

@ -0,0 +1,23 @@
package org.wlld.imageRecognition;
import org.wlld.i.OutBack;
import org.wlld.imageRecognition.border.FrameBody;
/**
* @author lidapeng
* @description
* @date 3:44 2020/1/26
*/
public class ImageBack implements OutBack {
private FrameBody frameBody;
public void setFrameBody(FrameBody frameBody) {
this.frameBody = frameBody;
}
@Override
public void getBack(double out, int id, long eventId) {
frameBody.setPointAndId(out, id);
}
}

@ -2,8 +2,12 @@ package org.wlld.imageRecognition;
import org.wlld.MatrixTools.Matrix;
import org.wlld.config.Kernel;
import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.config.StudyPattern;
import org.wlld.imageRecognition.border.Border;
import org.wlld.imageRecognition.border.BorderBody;
import org.wlld.imageRecognition.border.Frame;
import org.wlld.imageRecognition.border.FrameBody;
import org.wlld.nerveEntity.SensoryNerve;
import org.wlld.tools.ArithUtil;
@ -19,7 +23,7 @@ public class Operation {//进行计算
this.templeConfig = templeConfig;
}
public List<Double> convolution(Matrix matrix, boolean isBorder) throws Exception {
public List<Double> convolution(Matrix matrix, Map<Integer, Double> tagging) throws Exception {
//进行卷积
int maxNub = 0;
if (templeConfig.getRow() >= templeConfig.getColumn()) {
@ -27,14 +31,23 @@ public class Operation {//进行计算
} else {
maxNub = templeConfig.getColumn();
}
Matrix matrix1 = convolution.getFeatures(matrix, maxNub, isBorder);
int id = -1;
if (tagging != null && templeConfig.isHavePosition()) {
for (Map.Entry<Integer, Double> entry : tagging.entrySet()) {
if (entry.getValue() == 1) {
id = entry.getKey();
break;
}
}
}
Matrix matrix1 = convolution.getFeatures(matrix, maxNub, templeConfig, id);
return sub(matrix1);
}
//模板学习
public void study(Matrix matrix, Map<Integer, Double> tagging) throws Exception {
if (templeConfig.getStudyPattern() == StudyPattern.Speed_Pattern) {
List<Double> list = convolution(matrix, templeConfig.isHavePosition());
List<Double> list = convolution(matrix, tagging);
intoNerve(1, list, templeConfig.getSensoryNerves(), true, tagging);
} else {
throw new Exception("pattern is wrong");
@ -44,12 +57,16 @@ public class Operation {//进行计算
//卷积核学习
public void learning(Matrix matrix, Map<Integer, Double> tagging, boolean isNerveStudy) throws Exception {
if (templeConfig.getStudyPattern() == StudyPattern.Accuracy_Pattern) {
Border border = null;
if (templeConfig.isHavePosition() && isNerveStudy) {
border = convolution.borderOnce(matrix, templeConfig);
}
boolean isKernelStudy = true;
if (isNerveStudy) {
isKernelStudy = false;
}
intoNerve2(1, matrix, templeConfig.getConvolutionNerveManager().getSensoryNerves(),
isKernelStudy, isNerveStudy, tagging);
isKernelStudy, isNerveStudy, tagging, border);
} else {
throw new Exception("pattern is wrong");
}
@ -58,21 +75,86 @@ public class Operation {//进行计算
//图像视觉 speed 模式
public void look(Matrix matrix, long eventId) throws Exception {
if (templeConfig.getStudyPattern() == StudyPattern.Speed_Pattern) {
long a = System.currentTimeMillis();
List<Double> list = convolution(matrix, templeConfig.isHavePosition());
List<Double> list = convolution(matrix, null);
intoNerve(eventId, list, templeConfig.getSensoryNerves(), false, null);
long b = System.currentTimeMillis();
System.out.println("耗时:" + (b - a));
} else if (templeConfig.getStudyPattern() == StudyPattern.Accuracy_Pattern) {
see(matrix, eventId);
}
}
//边框检测+识别分类
public void lookWithPosition(Matrix matrix, long eventId) throws Exception {
Frame frame = templeConfig.getFrame();
if (templeConfig.isHavePosition() && frame != null && frame.isReady()) {
List<FrameBody> frameBodies = convolution.getRegion(matrix, frame);
if (templeConfig.getStudyPattern() == StudyPattern.Speed_Pattern) {
int maxNub = 0;
if (templeConfig.getRow() >= templeConfig.getColumn()) {
maxNub = templeConfig.getRow();
} else {
maxNub = templeConfig.getColumn();
}
ImageBack imageBack = templeConfig.getImageBack();
for (FrameBody frameBody : frameBodies) {
//Speed 模式下的最后卷积结果
Matrix matrix1 = convolution.getFeatures(frameBody.getMatrix(), maxNub, templeConfig, -1);
frameBody.setEndMatrix(matrix1);
List<Double> list = sub(matrix1);
imageBack.setFrameBody(frameBody);
//进入神经网络判断
intoNerve(eventId, list, templeConfig.getSensoryNerves(), false, null);
}
toPositon(frameBodies, frame.getWidth(), frame.getHeight());
} else if (templeConfig.getStudyPattern() == StudyPattern.Accuracy_Pattern) {
}
} else {
throw new Exception("position not study or frame is not ready");
}
}
private void toPositon(List<FrameBody> frameBodies, int width, int height) throws Exception {//把分类都拿出来
for (FrameBody frameBody : frameBodies) {
if (frameBody.getPoint() > templeConfig.getTh()) {//存在一个识别分类
getBox(frameBody, width, height);
}
}
}
//获得预测边框
private void getBox(FrameBody frameBody, int width, int height) throws Exception {
if (templeConfig.isBoxReady()) {
Matrix matrix = frameBody.getEndMatrix();
int id = frameBody.getId();
int x = frameBody.getX();
int y = frameBody.getY();
Map<Integer, BorderBody> borderBodyMap = templeConfig.getBorderBodyMap();
BorderBody borderBody = borderBodyMap.get(id);
//都是列向量将参数转化为行向量最后再加1
Matrix xw = borderBody.getxW();
Matrix yw = borderBody.getyW();
Matrix hw = borderBody.gethW();
Matrix ww = borderBody.getwW();
matrix = MatrixOperation.matrixToVector(matrix, true);
//将参数矩阵的末尾填1
matrix = MatrixOperation.push(matrix, 1, true);
//锚点坐标及长宽预测值
double tx = MatrixOperation.mulMatrix(matrix, xw).getNumber(0, 0);
double ty = MatrixOperation.mulMatrix(matrix, yw).getNumber(0, 0);
double th = MatrixOperation.mulMatrix(matrix, hw).getNumber(0, 0);
double tw = MatrixOperation.mulMatrix(matrix, ww).getNumber(0, 0);
//修正相对位置
double realX = ArithUtil.add(ArithUtil.mul(tx, height), x);
} else {
throw new Exception("box is not study");
}
}
//图像视觉 Accuracy 模式
private void see(Matrix matrix, long eventId) throws Exception {
if (templeConfig.getStudyPattern() == StudyPattern.Accuracy_Pattern) {
intoNerve2(eventId, matrix, templeConfig.getConvolutionNerveManager().getSensoryNerves(),
false, false, null);
false, false, null, null);
} else {
throw new Exception("pattern is wrong");
}
@ -87,9 +169,7 @@ public class Operation {//进行计算
if (i > x || j > y) {
list.add(0.0);
} else {
//归一化处理
double nub = ArithUtil.div(matrix.getNumber(i, j), 10000000);
list.add(nub);
list.add(matrix.getNumber(i, j));
}
}
}
@ -104,9 +184,10 @@ public class Operation {//进行计算
}
private void intoNerve2(long eventId, Matrix featur, List<SensoryNerve> sensoryNerveList
, boolean isKernelStudy, boolean isNerveStudy, Map<Integer, Double> E) throws Exception {
, boolean isKernelStudy, boolean isNerveStudy
, Map<Integer, Double> E, Border border) throws Exception {
for (int i = 0; i < sensoryNerveList.size(); i++) {
sensoryNerveList.get(i).postMatrixMessage(eventId, featur, isKernelStudy, isNerveStudy, E);
sensoryNerveList.get(i).postMatrixMessage(eventId, featur, isKernelStudy, isNerveStudy, E, border);
}
}
}

@ -1,11 +1,13 @@
package org.wlld.imageRecognition;
import org.wlld.MatrixTools.Matrix;
import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.config.StudyPattern;
import org.wlld.function.ReLu;
import org.wlld.function.Sigmod;
import org.wlld.i.OutBack;
import org.wlld.imageRecognition.border.BorderBody;
import org.wlld.imageRecognition.border.Frame;
import org.wlld.nerveCenter.NerveManager;
import org.wlld.nerveEntity.ModelParameter;
import org.wlld.nerveEntity.SensoryNerve;
@ -27,12 +29,64 @@ public class TempleConfig {
private int studyPattern;//学习模式
private OutBack outBack;
private boolean isHavePosition = false;//是否需要锁定物体位置
private Map<Integer, BorderBody> borderBodyMap = new HashMap<>();
private Map<Integer, BorderBody> borderBodyMap = new HashMap<>();//border特征集合
private Frame frame;//先验边框
private ImageBack imageBack = new ImageBack();//边框图像回调
private double th = 0.6;//标准阈值
private boolean boxReady = false;//边框已经学习完毕
public boolean isBoxReady() {
return boxReady;
}
public double getTh() {
return th;
}
public void setTh(double th) {
this.th = th;
}
public ImageBack getImageBack() {
return imageBack;
}
public Frame getFrame() {
return frame;
}
public void setFrame(Frame frame) {
this.frame = frame;
}
public Map<Integer, BorderBody> getBorderBodyMap() {
return borderBodyMap;
}
private void border(BorderBody borderBody) throws Exception {
Matrix parameter = borderBody.getX();//参数矩阵
Matrix tx = borderBody.getTx();
Matrix ty = borderBody.getTy();
Matrix th = borderBody.getTh();
Matrix tw = borderBody.getTw();
borderBody.setxW(MatrixOperation.getLinearRegression(parameter, tx));
borderBody.setyW(MatrixOperation.getLinearRegression(parameter, ty));
borderBody.setwW(MatrixOperation.getLinearRegression(parameter, tw));
borderBody.sethW(MatrixOperation.getLinearRegression(parameter, th));
boxReady = true;
}
public void borderStudy() throws Exception {//边框回归
if (borderBodyMap.size() > 0) {
for (Map.Entry<Integer, BorderBody> entry : borderBodyMap.entrySet()) {
border(entry.getValue());
}
} else {
throw new Exception("boder not study");
}
}
public void setBorderBodyMap(Map<Integer, BorderBody> borderBodyMap) {
this.borderBodyMap = borderBodyMap;
}
@ -50,6 +104,7 @@ public class TempleConfig {
}
public void setHavePosition(boolean havePosition) {
nerveManager.setOutBack(imageBack);
isHavePosition = havePosition;
}
@ -93,7 +148,7 @@ public class TempleConfig {
, int deep) throws Exception {
nerveManager = new NerveManager(sensoryNerveNub, 6,
classificationNub, deep, new Sigmod(), false);
nerveManager.init(initPower, false, null);
nerveManager.init(initPower, false, false, null);
nerveManager.setOutBack(outBack);
}
@ -122,7 +177,7 @@ public class TempleConfig {
1, deep - 1, new ReLu(), true);
initNerveManager(initPower, width * height, 2);
convolutionNerveManager.setMatrixMap(matrixMap);//给卷积网络管理器注入期望矩阵
convolutionNerveManager.init(initPower, true, nerveManager);
convolutionNerveManager.init(initPower, true, isHavePosition, nerveManager);
}
public ModelParameter getModel() throws Exception {//获取模型参数

@ -5,6 +5,8 @@ import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.imageRecognition.TempleConfig;
import org.wlld.tools.ArithUtil;
import java.util.Map;
/**
* @author lidapeng
* @description
@ -21,7 +23,7 @@ public class Border {
private double modelWidth;//标准宽度
private TempleConfig templeConfig;
Border(TempleConfig templeConfig, int imageWidth, int imageHeight) {
public Border(TempleConfig templeConfig, int imageWidth, int imageHeight) {
modelWidth = imageWidth;
modelHeight = imageHeight;
this.templeConfig = templeConfig;
@ -46,9 +48,11 @@ public class Border {
public void end(Matrix matrix, int id) throws Exception {//长宽
height = maxX - minX;
width = maxY - minY;
BorderBody borderBody = templeConfig.getBorderBodyMap().get(id);
Map<Integer, BorderBody> borderBodyMap = templeConfig.getBorderBodyMap();
BorderBody borderBody = borderBodyMap.get(id);
if (borderBody == null) {
borderBody = new BorderBody();
borderBodyMap.put(id, borderBody);
}
//拿到参数矩阵
Matrix matrixX = borderBody.getX();
@ -82,7 +86,11 @@ public class Border {
matrixTw = MatrixOperation.push(matrixTw, tw, false);
matrixTh = MatrixOperation.push(matrixTh, th, false);
}
borderBody.setX(matrixX);
borderBody.setTh(matrixTh);
borderBody.setTw(matrixTw);
borderBody.setTx(matrixTx);
borderBody.setTy(matrixTy);
}
}

@ -0,0 +1,53 @@
package org.wlld.imageRecognition.border;
/**
* @author lidapeng
* @description
* @date 11:16 2020/1/26
*/
public class Frame {
private int width;//检测边框的宽
private int height;//检测边框的高
private int lengthWidth;//宽一次走多长
private int lengthHeight;//高一次走多长
public boolean isReady() {
if (width > 0 && height > 0 && lengthWidth > 0 && lengthHeight > 0) {
return true;
} else {
return false;
}
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getLengthWidth() {
return lengthWidth;
}
public void setLengthWidth(int lengthWidth) {
this.lengthWidth = lengthWidth;
}
public int getLengthHeight() {
return lengthHeight;
}
public void setLengthHeight(int lengthHeight) {
this.lengthHeight = lengthHeight;
}
}

@ -0,0 +1,64 @@
package org.wlld.imageRecognition.border;
import org.wlld.MatrixTools.Matrix;
/**
* @author lidapeng
* @description
* @date 11:49 2020/1/26
*/
public class FrameBody {
private Matrix matrix;//图像区块矩阵
private Matrix endMatrix;//卷积结束的矩阵
private int id;//当前分类的ID
private double point;//当前分类的概率
private int x;//锚点X坐标
private int y;//锚点Y坐标
public Matrix getEndMatrix() {
return endMatrix;
}
public int getId() {
return id;
}
public double getPoint() {
return point;
}
public void setPointAndId(double point, int id) {
if (point > this.point) {
this.point = point;
this.id = id;
}
}
public void setEndMatrix(Matrix endMatrix) {
this.endMatrix = endMatrix;
}
public Matrix getMatrix() {
return matrix;
}
public void setMatrix(Matrix matrix) {
this.matrix = matrix;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

@ -4,7 +4,6 @@ import org.wlld.MatrixTools.Matrix;
import org.wlld.i.ActiveFunction;
import org.wlld.i.OutBack;
import org.wlld.nerveEntity.*;
import org.wlld.tools.ArithUtil;
import java.util.ArrayList;
import java.util.HashMap;
@ -253,7 +252,8 @@ public class NerveManager {
return sensoryNerves;
}
public void init(boolean initPower, boolean isMatrix, NerveManager nerveManager) throws Exception {//进行神经网络的初始化构建
public void init(boolean initPower, boolean isMatrix,
boolean isBorder, NerveManager nerveManager) throws Exception {//进行神经网络的初始化构建
this.initPower = initPower;
initDepthNerve(isMatrix);//初始化深度隐层神经元
List<Nerve> nerveList = depthNerves.get(0);//第一层隐层神经元
@ -262,9 +262,10 @@ public class NerveManager {
//初始化输出神经元
for (int i = 1; i < outNerveNub + 1; i++) {
OutNerve outNerve = new OutNerve(i, hiddenNerverNub, 0, studyPoint, initPower, activeFunction, isMatrix);
if (isMatrix) {
if (isMatrix) {//是卷积层神经网络
outNerve.setNerveManager(nerveManager);
outNerve.setMatrixMap(matrixMap);
outNerve.setBorder(isBorder);
}
//输出层神经元连接最后一层隐层神经元
outNerve.connectFathor(lastNeveList);

@ -2,6 +2,7 @@ package org.wlld.nerveEntity;
import org.wlld.MatrixTools.Matrix;
import org.wlld.i.ActiveFunction;
import org.wlld.imageRecognition.border.Border;
import java.util.List;
import java.util.Map;
@ -38,8 +39,8 @@ public class HiddenNerve extends Nerve {
@Override
protected void inputMartix(long eventId, Matrix matrix, boolean isStudy
, boolean isNerveStudy, Map<Integer, Double> E) throws Exception {
, boolean isNerveStudy, Map<Integer, Double> E, Border border) throws Exception {
Matrix myMatrix = dynamicNerve(matrix, eventId, isStudy);//处理过的矩阵
sendMatrix(eventId, myMatrix, isStudy, isNerveStudy, E);
sendMatrix(eventId, myMatrix, isStudy, isNerveStudy, E, border);
}
}

@ -4,6 +4,7 @@ package org.wlld.nerveEntity;
import org.wlld.MatrixTools.Matrix;
import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.i.ActiveFunction;
import org.wlld.imageRecognition.border.Border;
import org.wlld.tools.ArithUtil;
import java.util.*;
@ -119,10 +120,11 @@ public abstract class Nerve {
return myMatrix;
}
public void sendMatrix(long enevtId, Matrix parameter, boolean isStudy, boolean isNerveStudy, Map<Integer, Double> E) throws Exception {
public void sendMatrix(long enevtId, Matrix parameter, boolean isStudy, boolean isNerveStudy,
Map<Integer, Double> E, Border border) throws Exception {
if (son.size() > 0) {
for (Nerve nerve : son) {
nerve.inputMartix(enevtId, parameter, isStudy, isNerveStudy, E);
nerve.inputMartix(enevtId, parameter, isStudy, isNerveStudy, E, border);
}
} else {
throw new Exception("this layer is lastIndex");
@ -151,7 +153,7 @@ public abstract class Nerve {
}
protected void inputMartix(long eventId, Matrix matrix, boolean isKernelStudy
, boolean isNerveStudy, Map<Integer, Double> E) throws Exception {//输入动态矩阵
, boolean isNerveStudy, Map<Integer, Double> E, Border border) throws Exception {//输入动态矩阵
}
private void backGetMessage(double parameter, long eventId) throws Exception {//反向传播

@ -3,6 +3,7 @@ package org.wlld.nerveEntity;
import org.wlld.MatrixTools.Matrix;
import org.wlld.i.ActiveFunction;
import org.wlld.i.OutBack;
import org.wlld.imageRecognition.border.Border;
import org.wlld.nerveCenter.NerveManager;
import org.wlld.tools.ArithUtil;
@ -21,6 +22,11 @@ public class OutNerve extends Nerve {
private NerveManager nerveManager;
private Map<Integer, Matrix> matrixMapE;//主键与期望矩阵的映射
private Matrix matrixF;
private boolean isBorder = false;
public void setBorder(boolean border) {
isBorder = border;
}
public OutNerve(int id, int upNub, int downNub, double studyPoint, boolean init,
ActiveFunction activeFunction, boolean isDynamic) throws Exception {
@ -63,7 +69,8 @@ public class OutNerve extends Nerve {
}
@Override
protected void inputMartix(long eventId, Matrix matrix, boolean isKernelStudy, boolean isNerveStudy, Map<Integer, Double> E) throws Exception {
protected void inputMartix(long eventId, Matrix matrix, boolean isKernelStudy, boolean isNerveStudy
, Map<Integer, Double> E, Border border) throws Exception {
Matrix myMatrix = dynamicNerve(matrix, eventId, isKernelStudy);
if (matrixF == null) {
matrixF = new Matrix(myMatrix.getX(), myMatrix.getY());
@ -81,6 +88,16 @@ public class OutNerve extends Nerve {
backMatrix(g, eventId);
}//所有训练集的卷积核训练结束,才需要再次训练全连接层
} else {//输出到全连接层
if (isBorder) {
int id = 0;
for (Map.Entry<Integer, Double> entry : E.entrySet()) {
if (entry.getValue() == 1) {
id = entry.getKey();
break;
}
}
border.end(myMatrix, id);
}
List<Double> featurList = getFeaturList(myMatrix);
intoNerve(eventId, featurList, isNerveStudy, E);
}

@ -1,6 +1,7 @@
package org.wlld.nerveEntity;
import org.wlld.MatrixTools.Matrix;
import org.wlld.imageRecognition.border.Border;
import java.util.List;
import java.util.Map;
@ -21,8 +22,9 @@ public class SensoryNerve extends Nerve {
sendMessage(eventId, parameter, isStudy, E);
}
public void postMatrixMessage(long eventId, Matrix parameter, boolean isKernelStudy, boolean isNerveStudy, Map<Integer, Double> E) throws Exception {
sendMatrix(eventId, parameter, isKernelStudy, isNerveStudy, E);
public void postMatrixMessage(long eventId, Matrix parameter, boolean isKernelStudy, boolean isNerveStudy
, Map<Integer, Double> E, Border border) throws Exception {
sendMatrix(eventId, parameter, isKernelStudy, isNerveStudy, E, border);
}
@Override

@ -2,6 +2,8 @@ package org.wlld;
import org.wlld.MatrixTools.Matrix;
import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.imageRecognition.border.Border;
import org.wlld.imageRecognition.border.BorderBody;
/**
* @author lidapeng
@ -13,16 +15,32 @@ public class MatrixTest {
test3();
}
public static void test4() throws Exception {
BorderBody borderBody = new BorderBody();
Matrix xw = borderBody.getxW();
String a = "[1]#" +
"[3]#" +
"[5]#";
xw = new Matrix(3, 1, a);
borderBody.setxW(xw);
Matrix xt = borderBody.getxW();
xt = MatrixOperation.push(xt, 9, false);
Matrix xm = borderBody.getxW();
System.out.println(xm.getString());
}
public static void test3() throws Exception {
Matrix matrix = new Matrix(3, 2);
Matrix matrixY = new Matrix(3, 1);
Matrix matrix = new Matrix(4, 3);
Matrix matrixY = new Matrix(4, 1);
String b = "[7]#" +
"[8]#" +
"[9]#";
"[9]#" +
"[19]#";
matrixY.setAll(b);
String a = "[1,2]#" +
"[3,4]#" +
"[5,6]#";
String a = "[1,2,17]#" +
"[3,4,18]#" +
"[5,6,10]#" +
"[15,16,13]#";
matrix.setAll(a);
//将参数矩阵转置
Matrix matrix1 = MatrixOperation.transPosition(matrix);
@ -34,6 +52,7 @@ public class MatrixTest {
Matrix matrix4 = MatrixOperation.mulMatrix(matrix3, matrix1);
//最后乘以输出矩阵,生成权重矩阵
Matrix matrix5 = MatrixOperation.mulMatrix(matrix4, matrixY);
System.out.println(matrix5.getString());
}
public static void test1() throws Exception {

Loading…
Cancel
Save