Backends/SiaNet.Backend.TensorSharp/Cpu/SpatialConvolutionMM.cs
/// <summary>
/// Conv2s the backward input frame.
/// </summary>
/// <param name="gradOutput">The grad output.</param>
/// <param name="gradInput">The grad input.</param>
/// <param name="weight">The weight.</param>
/// <param name="fgradInput">The fgrad input.</param>
/// <param name="cd">The cd.</param>
Conv2s the backward input frame.
Conv2s the backward input frame .
private static void Conv2BackwardInputFrame(NDArray gradOutput, NDArray gradInput, NDArray weight, NDArray fgradInput, ConvolutionDesc2d cd)
        {
            using (var gradOutput2d = gradOutput.View(gradOutput.Shape[0], gradOutput.Shape[1] * gradOutput.Shape[2]))
            {
                Ops.Addmm(fgradInput, 0, fgradInput, 1, weight, gradOutput2d);
            }
            Ops.Fill(gradInput, 0);
            IntPtr fgradInputPtr, gradInputPtr;
            using (NativeWrapper.BuildTensorRefPtr(fgradInput, out fgradInputPtr))
            using (NativeWrapper.BuildTensorRefPtr(gradInput, out gradInputPtr))
            {
                CpuOpsNative.TS_Unfolded_Acc(fgradInputPtr, gradInputPtr, cd.kW, cd.kH, cd.dW, cd.dH, cd.padW, cd.padH,
                (int)gradInput.Shape[0], (int)gradInput.Shape[2], (int)gradInput.Shape[1],
                (int)gradOutput.Shape[2], (int)gradOutput.Shape[1]);
            }
        }
private static void Conv2BackwardInputFrame ( NDArray gradOutput , NDArray gradInput , NDArray weight , NDArray fgradInput , ConvolutionDesc2d cd ) { using ( var gradOutput2d = gradOutput . View ( gradOutput . Shape [ 0 ] , gradOutput . Shape [ 1 ] * gradOutput . Shape [ 2 ] ) ) { Ops . Addmm ( fgradInput , 0 , fgradInput , 1 , weight , gradOutput2d ) ; } Ops . Fill ( gradInput , 0 ) ; IntPtr fgradInputPtr , gradInputPtr ; using ( NativeWrapper . BuildTensorRefPtr ( fgradInput , out fgradInputPtr ) ) using ( NativeWrapper . BuildTensorRefPtr ( gradInput , out gradInputPtr ) ) { CpuOpsNative . TS_Unfolded_Acc ( fgradInputPtr , gradInputPtr , cd . kW , cd . kH , cd . dW , cd . dH , cd . padW , cd . padH , ( int ) gradInput . Shape [ 0 ] , ( int ) gradInput . Shape [ 2 ] , ( int ) gradInput . Shape [ 1 ] , ( int ) gradOutput . Shape [ 2 ] , ( int ) gradOutput . Shape [ 1 ] ) ; } }
Conv2s the backward input frame.
Conv2s the backward input frame .
gradOutput
NDArray
The grad output.
The grad output .
gradInput
NDArray
The grad input.
The grad input .
weight
NDArray
None
fgradInput
NDArray
The fgrad input.
The fgrad input .
cd
ConvolutionDesc2d
None