/// <summary>
        /// build a convolution function
        /// </summary>
        /// <param name="convolutionMap">convolution parameters (shape, type of the kernal)</param>
        /// <param name="operand">input variable</param>
        /// <param name="strides">strides to apply convolution</param>
        /// <param name="sharing">whether to share parameters (default = true)</param>
        /// <param name="autoPadding"></param>
        /// <returns></returns>
        public static Function Convolution(Variable convolutionMap, Variable operand, NDShape strides, IEnumerable <bool> sharing, IEnumerable <bool> autoPadding)
        {
            BoolVector sharingVec     = Helper.AsBoolVector(sharing);
            BoolVector autoPaddingVec = Helper.AsBoolVector(autoPadding);

            return(CNTKLib.Convolution(convolutionMap, operand, strides, sharingVec, autoPaddingVec));
        }
Ejemplo n.º 2
0
        private static OneArgumentModule Convolution(
            int nbFilters,
            int[] filterShape,
            int[] strides,
            bool[] paddings,
            int[] dilations,
            bool bias,
            bool[] sharing,
            uint reductionRank = 1,
            string name        = ""
            )
        {
            var kernelInitializer = C.GlorotUniformInitializer(
                C.DefaultParamInitScale,
                C.SentinelValueForInferParamInitRank,
                C.SentinelValueForInferParamInitRank);

            var rank = filterShape.Length;

            int[] kernelShape = new int[rank + 2];

            for (int i = 0; i < filterShape.Length; i++)
            {
                kernelShape[i] = filterShape[i];
            }

            kernelShape[rank]     = NDShape.InferredDimension;
            kernelShape[rank + 1] = nbFilters;


            int[] biasShape = new int[rank + 1];
            for (int i = 0; i < rank; i++)
            {
                biasShape[i] = 1;
            }
            biasShape[rank] = nbFilters;

            Parameter w = new Parameter(kernelShape, DataType.Float, kernelInitializer);

            Parameter b = bias ? new Parameter(biasShape, DataType.Float, 0) : null;

            Function _Convolve(Variable x)
            {
                var r = C.Convolution(w, x, strides, new BoolVector(sharing), new BoolVector(paddings), dilations, reductionRank, 0, name);

                if (bias)
                {
                    r += b;
                }

                return(r);
            }

            return(_Convolve);
        }