Backends/SiaNet.Backend.TensorSharp/Cpu/CpuMaxPoolingOps.cs
/// <summary>
/// Spatials the maximum pooling backward.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="gradOutput">The grad output.</param>
/// <param name="gradInput">The grad input.</param>
/// <param name="indices">The indices.</param>
/// <param name="cd">The cd.</param>
/// <param name="ceilMode">if set to <c>true</c> [ceil mode].</param>
Spatials the maximum pooling backward.
Spatials the maximum pooling backward .
public static void SpatialMaxPoolingBackward(NDArray input, NDArray gradOutput, NDArray gradInput, NDArray indices, ConvolutionDesc2d cd, bool ceilMode)
        {
            var dimw = 3;
            var dimh = 2;
            var dimc = 1;
            var nbatch = input.Shape[0];
            var nslices = input.Shape[dimc];
            var iheight = input.Shape[dimh];
            var iwidth = input.Shape[dimw];
            var owidth = gradOutput.Shape[dimw];
            var oheight = gradOutput.Shape[dimh];
            Ops.Fill(gradInput, 0);
            using (var gradOutputContig = Ops.AsContiguous(gradOutput))
            {
                for (int i = 0; i < nbatch; ++i)
                {
                    using (var gradInput_i = gradInput.Select(0, i))
                    using (var gradOutput_i = gradOutputContig.Select(0, i))
                    using (var indices_i = indices.Select(0, i))
                    {
                        IntPtr gradInput_iPtr, gradOutput_iPtr, indices_iPtr;
                        using (NativeWrapper.BuildTensorRefPtr(gradInput_i, out gradInput_iPtr))
                        using (NativeWrapper.BuildTensorRefPtr(gradOutput_i, out gradOutput_iPtr))
                        using (NativeWrapper.BuildTensorRefPtr(indices_i, out indices_iPtr))
                        {
                            CpuOpsNative.TS_SpatialMaxPooling_updateGradInput_frame(gradInput_iPtr, gradOutput_iPtr, indices_iPtr,
                                nslices, iwidth, iheight,
                                owidth, oheight,
                                cd.dW, cd.dH);
                        }
                    }
                }
            }
        }
public static void SpatialMaxPoolingBackward ( NDArray input , NDArray gradOutput , NDArray gradInput , NDArray indices , ConvolutionDesc2d cd , bool ceilMode ) { var dimw = 3 ; var dimh = 2 ; var dimc = 1 ; var nbatch = input . Shape [ 0 ] ; var nslices = input . Shape [ dimc ] ; var iheight = input . Shape [ dimh ] ; var iwidth = input . Shape [ dimw ] ; var owidth = gradOutput . Shape [ dimw ] ; var oheight = gradOutput . Shape [ dimh ] ; Ops . Fill ( gradInput , 0 ) ; using ( var gradOutputContig = Ops . AsContiguous ( gradOutput ) ) { for ( int i = 0 ; i < nbatch ; ++ i ) { using ( var gradInput_i = gradInput . Select ( 0 , i ) ) using ( var gradOutput_i = gradOutputContig . Select ( 0 , i ) ) using ( var indices_i = indices . Select ( 0 , i ) ) { IntPtr gradInput_iPtr , gradOutput_iPtr , indices_iPtr ; using ( NativeWrapper . BuildTensorRefPtr ( gradInput_i , out gradInput_iPtr ) ) using ( NativeWrapper . BuildTensorRefPtr ( gradOutput_i , out gradOutput_iPtr ) ) using ( NativeWrapper . BuildTensorRefPtr ( indices_i , out indices_iPtr ) ) { CpuOpsNative . TS_SpatialMaxPooling_updateGradInput_frame ( gradInput_iPtr , gradOutput_iPtr , indices_iPtr , nslices , iwidth , iheight , owidth , oheight , cd . dW , cd . dH ) ; } } } } }
Spatials the maximum pooling backward.
Spatials the maximum pooling backward .
input
NDArray
None
gradOutput
NDArray
The grad output.
The grad output .
gradInput
NDArray
The grad input.
The grad input .
indices
NDArray
None
cd
ConvolutionDesc2d
None
ceilMode
bool
if set to true
if set to true