public double[,,,] forward(double[,,,] input) { //获取样本的总数 int sampleCount = input.GetLength(0); //获取单个样本的深度 int sampleSingleDepth = input.GetLength(1); //获取特征图的行数(高) int inputRow = input.GetLength(2); //获取特征图的列数(宽) int inputColumn = input.GetLength(3); //创建最大值的 SingleMaxIndex = new int[sampleCount][][]; int row = (inputRow - PadRow) / Stride + 1; int column = (inputColumn - PadColumn) / Stride + 1; var result = new double[sampleCount, sampleSingleDepth, row, column]; for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { //初始化特征图最大索引对象 SingleMaxIndex[sampleIndex] = new int[sampleSingleDepth][]; //记录特征图的行和列信息 InputShape = new MatrixShape(inputRow, inputColumn); for (int depth = 0; depth < sampleSingleDepth; depth++) { LMatrix pad = im2col(input.GetNextDimVal(sampleIndex, depth, inputRow, inputColumn), row, column, PadRow, PadColumn, Stride); SingleMaxIndex[sampleIndex][depth] = pad.MaxIndex(); //LMatrix data = pad.Matrix.Select(m => m.Max()).ToArray(); LMatrix data = pad.Max(1); result.SetDimVal(data.ReShape(row, column), sampleIndex, depth, row, column); } } return(result); }
public double Accuracy(LMatrix lable) { var y = Predict(); int len = y.GetLength(0); LMatrix maxtrx = y; var res = maxtrx.MaxIndex(); var lab = lable.MaxIndex(); int sum = 0; for (int i = 0; i < len; i++) { sum += (res[i] == lab[i]) ? 1 : 0; } return(sum * 1.0d / len); }