Exemplo n.º 1
0
        /// <summary>
        /// Parses the parameter from a RawProto.
        /// </summary>
        /// <param name="rp">Specifies the RawProto to parse.</param>
        /// <returns>A new instance of the parameter is returned.</returns>
        public static new PoolingParameter FromProto(RawProto rp)
        {
            string           strVal;
            PoolingParameter p = new PoolingParameter();

            ((KernelParameter)p).Copy(KernelParameter.FromProto(rp));

            if ((strVal = rp.FindValue("pool")) != null)
            {
                switch (strVal)
                {
                case "MAX":
                    p.pool = PoolingMethod.MAX;
                    break;

                case "AVE":
                    p.pool = PoolingMethod.AVE;
                    break;

                case "STOCHASTIC":
                    p.pool = PoolingMethod.STOCHASTIC;
                    break;

                default:
                    throw new Exception("Unknown pooling 'method' value: " + strVal);
                }
            }

            if ((strVal = rp.FindValue("global_pooling")) != null)
            {
                p.global_pooling = bool.Parse(strVal);
            }

            return(p);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert the parameter into a RawProto.
        /// </summary>
        /// <param name="strName">Specifies the base name for the raw proto.</param>
        /// <returns>The RawProto is returned.</returns>
        public override RawProto ToProto(string strName)
        {
            RawProto           rpBase     = base.ToProto("engine");
            RawProtoCollection rgChildren = new RawProtoCollection();
            KernelParameter    p          = new KernelParameter();

            rgChildren.Add(rpBase.Children);
            rgChildren.Add <uint>("kernel_size", m_rgKernelSize);
            rgChildren.Add <uint>("stride", m_rgStride);
            rgChildren.Add <uint>("pad", m_rgPad);

            if (m_rgDilation.Count > 0)
            {
                rgChildren.Add <uint>("dilation", m_rgDilation);
            }

            rgChildren.Add("kernel_h", m_nKernelH);
            rgChildren.Add("kernel_w", m_nKernelW);
            rgChildren.Add("stride_h", m_nStrideH);
            rgChildren.Add("stride_w", m_nStrideW);
            rgChildren.Add("pad_h", m_nPadH);
            rgChildren.Add("pad_w", m_nPadW);

            return(new RawProto(strName, "", rgChildren));
        }
Exemplo n.º 3
0
        /** @copydoc EngineParameter::Clone */
        public override LayerParameterBase Clone()
        {
            KernelParameter p = new KernelParameter();

            p.Copy(this);
            return(p);
        }
Exemplo n.º 4
0
        /** @copydoc KernelParameter::FromProto */
        public static new ConvolutionParameter FromProto(RawProto rp)
        {
            string strVal;
            ConvolutionParameter p = new ConvolutionParameter();

            ((KernelParameter)p).Copy(KernelParameter.FromProto(rp));

            if ((strVal = rp.FindValue("num_output")) != null)
            {
                p.num_output = uint.Parse(strVal);
            }

            if ((strVal = rp.FindValue("bias_term")) != null)
            {
                p.bias_term = bool.Parse(strVal);
            }

            if ((strVal = rp.FindValue("group")) != null)
            {
                p.group = uint.Parse(strVal);
            }

            RawProto rpWeightFiller = rp.FindChild("weight_filler");

            if (rpWeightFiller != null)
            {
                p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
            }

            RawProto rpBiasFiller = rp.FindChild("bias_filler");

            if (rpBiasFiller != null)
            {
                p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
            }

            if ((strVal = rp.FindValue("axis")) != null)
            {
                p.axis = int.Parse(strVal);
            }

            if ((strVal = rp.FindValue("force_nd_im2col")) != null)
            {
                p.force_nd_im2col = bool.Parse(strVal);
            }

            if ((strVal = rp.FindValue("cudnn_workspace_limit")) != null)
            {
                p.cudnn_workspace_limit = int.Parse(strVal);
            }

            if ((strVal = rp.FindValue("cudnn_worspace_allow_on_groups")) != null)
            {
                p.cudnn_workspace_allow_on_groups = bool.Parse(strVal);
            }

            return(p);
        }
Exemplo n.º 5
0
        /** @copydoc EngineParameter::Load */
        public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
        {
            RawProto        proto = RawProto.Parse(br.ReadString());
            KernelParameter p     = FromProto(proto);

            if (!bNewInstance)
            {
                Copy(p);
            }

            return(p);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Parse a RawProto into a new instance of the parameter.
        /// </summary>
        /// <param name="rp">Specifies the RawProto to parse.</param>
        /// <returns>A new instance of the parameter is returned.</returns>
        public static new KernelParameter FromProto(RawProto rp)
        {
            KernelParameter p = new KernelParameter();

            ((EngineParameter)p).Copy(EngineParameter.FromProto(rp));

            p.m_rgPad        = rp.FindArray <uint>("pad");
            p.m_rgStride     = rp.FindArray <uint>("stride");
            p.m_rgKernelSize = rp.FindArray <uint>("kernel_size");
            p.m_rgDilation   = rp.FindArray <uint>("dilation");
            p.m_nPadH        = (uint?)rp.FindValue("pad_h", typeof(uint));
            p.m_nPadW        = (uint?)rp.FindValue("pad_w", typeof(uint));
            p.m_nStrideH     = (uint?)rp.FindValue("stride_h", typeof(uint));
            p.m_nStrideW     = (uint?)rp.FindValue("stride_w", typeof(uint));
            p.m_nKernelH     = (uint?)rp.FindValue("kernel_h", typeof(uint));
            p.m_nKernelW     = (uint?)rp.FindValue("kernel_w", typeof(uint));

            return(p);
        }
Exemplo n.º 7
0
        /** @copydoc EngineParameter::Copy */
        public override void Copy(LayerParameterBase src)
        {
            base.Copy(src);

            if (src is KernelParameter)
            {
                KernelParameter p = (KernelParameter)src;
                m_rgPad        = Utility.Clone <uint>(p.m_rgPad);
                m_rgStride     = Utility.Clone <uint>(p.m_rgStride);
                m_rgKernelSize = Utility.Clone <uint>(p.m_rgKernelSize);
                m_rgDilation   = Utility.Clone <uint>(p.m_rgDilation);
                m_nPadH        = p.m_nPadH;
                m_nPadW        = p.m_nPadW;
                m_nStrideH     = p.m_nStrideH;
                m_nStrideW     = p.m_nStrideW;
                m_nKernelH     = p.m_nKernelH;
                m_nKernelW     = p.m_nKernelW;
            }
        }