public void ProcessSubRegion(InternalArray ar, InternalArray[,] filters, InternalArray ret, int sx, int sy, int ww, int hout, int wout) { var hin = ar.Shape[1]; var win = ar.Shape[2]; var c = ar.Shape[0]; int shiftx = padding[0] - kernelSize[0] / 2; int shifty = padding[1] - kernelSize[1] / 2; var maxw = Math.Min(wout, (sy + 1) * ww); var maxh = Math.Min(hout, (sx + 1) * ww); var starth = sx * ww; var startw = sy * ww; for (int i = starth; i < maxh; i++) { for (int j = startw; j < maxw; j++) { for (int ch = 0; ch < outChannels; ch++) { float val = 0; for (int zz = 0; zz < c; zz++) { var kernel = filters[ch, zz]; for (int i1 = 0; i1 < kernelSize[0]; i1++) { for (int j1 = 0; j1 < kernelSize[0]; j1++) { //var x = i * stride[0] - kernelSize[0] / 2 + i1; //var y = j * stride[1] - kernelSize[1] / 2 + j1; //outspace var xout = (i) * stride[0] - kernelSize[0] / 2 + i1 * dilation[0]; var yout = (j) * stride[1] - kernelSize[1] / 2 + j1 * dilation[1]; //inspace var xin = xout - shiftx; var yin = yout - shifty; if (!ar.WithIn(zz, xin, yin)) { continue; } //var y=jmul+j1 var ii1 = i1 * kernel.Shape[1] + j1; var ii2 = zz * ar.offsets[0] + xin * ar.offsets[1] + yin; val += (float)(kernel.Get2D(i1, j1) * ar.Get3D(zz, xin, yin)); var ii3 = j + ch * ret.offsets[0] + i * ret.offsets[1]; } } } ret.Set3D(ch, i, j, val); } } } }
public InternalArray ProcessImage(InternalArray ar) { //CalcRegionsHashes(ar); indexes1.Clear(); indexes2.Clear(); indexes3.Clear(); var hin = ar.Shape[1]; var win = ar.Shape[2]; var c = ar.Shape[0]; var hout = ((hin + 2 * padding[0] - dilation[0] * (kernelSize[0] - 1) - 1) / stride[0]) + 1; var wout = ((win + 2 * padding[1] - dilation[1] * (kernelSize[1] - 1) - 1) / stride[1]) + 1; InternalArray ret = new InternalArray(new int[] { outChannels, hout, wout }); InternalArray[,] filters = new InternalArray[outChannels, c]; for (int ch = 0; ch < outChannels; ch++) { for (int zz = 0; zz < c; zz++) { var kernel = Weight.Get2DImageFrom4DArray(ch, zz); filters[ch, zz] = kernel; } } int shiftx = padding[0] - kernelSize[0] / 2; int shifty = padding[1] - kernelSize[1] / 2; for (int i = 0; i < hout; i++) { for (int j = 0; j < wout; j++) { for (int ch = 0; ch < outChannels; ch++) { float val = 0; for (int zz = 0; zz < c; zz++) { var kernel = filters[ch, zz]; for (int i1 = 0; i1 < kernelSize[0]; i1++) { for (int j1 = 0; j1 < kernelSize[0]; j1++) { //var x = i * stride[0] - kernelSize[0] / 2 + i1; //var y = j * stride[1] - kernelSize[1] / 2 + j1; //outspace var xout = (i) * stride[0] - kernelSize[0] / 2 + i1 * dilation[0]; var yout = (j) * stride[1] - kernelSize[1] / 2 + j1 * dilation[1]; //inspace var xin = xout - shiftx; var yin = yout - shifty; if (!ar.WithIn(zz, xin, yin)) { continue; } //var y=jmul+j1 var ii1 = i1 * kernel.Shape[1] + j1; var ii2 = zz * ar.offsets[0] + xin * ar.offsets[1] + yin; val += (float)(kernel.Get2D(i1, j1) * ar.Get3D(zz, xin, yin)); var ii3 = j + ch * ret.offsets[0] + i * ret.offsets[1]; //if (i == 0) { /*indexes1.Add(ii1); * indexes2.Add(ii2); * indexes3.Add(ii3);*/ } } } } ret.Set3D(ch, i, j, val); } } } return(ret); }