/// <summary>
        /// Load the parameter from a binary reader.
        /// </summary>
        /// <param name="br">Specifies the binary reader.</param>
        /// <param name="bNewInstance">When <i>true</i> a new instance is created (the default), otherwise the existing instance is loaded from the binary reader.</param>
        /// <returns>Returns an instance of the parameter.</returns>
        public override object Load(BinaryReader br, bool bNewInstance = true)
        {
            RawProto          proto = RawProto.Parse(br.ReadString());
            PriorBoxParameter p     = FromProto(proto);

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

            return(p);
        }
Exemplo n.º 2
0
        /** @copydoc EngineParameter::FromProto */
        public static new ReLUParameter FromProto(RawProto rp)
        {
            string strVal;
            ReLUParameter p = new ReLUParameter();

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

            if ((strVal = rp.FindValue("negative_slope")) != null)
                p.negative_slope = double.Parse(strVal);

            return p;
        }
Exemplo n.º 3
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 RecurrentParameter FromProto(RawProto rp)
        {
            string             strVal;
            RecurrentParameter p = new RecurrentParameter();

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

            if ((strVal = rp.FindValue("num_output")) != null)
            {
                p.num_output = 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("debug_info")) != null)
            {
                p.debug_info = bool.Parse(strVal);
            }

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

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

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

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

            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);
            }

            return(p);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load the and return a new ResizeParameter.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="bNewInstance"></param>
        /// <returns>The new object is returned.</returns>
        public ResizeParameter Load(BinaryReader br, bool bNewInstance = true)
        {
            RawProto        proto = RawProto.Parse(br.ReadString());
            ResizeParameter p     = FromProto(proto);

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

            return(p);
        }
Exemplo n.º 6
0
        /** @copydoc EngineParameter::ToProto */
        public override RawProto ToProto(string strName)
        {
            RawProto rpBase = base.ToProto("engine");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase.Children);

            if (negative_slope != 0)
                rgChildren.Add("negative_slope", negative_slope.ToString());

            return new RawProto(strName, "", rgChildren);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Convert this object to a raw proto.
        /// </summary>
        /// <param name="strName">Specifies the name of the proto.</param>
        /// <returns>The new proto is returned.</returns>
        public override RawProto ToProto(string strName)
        {
            RawProto           rpBase     = base.ToProto("option");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase);
            rgChildren.Add(new RawProto("active", Active.ToString()));
            rgChildren.Add(new RawProto("prob", prob.ToString()));
            rgChildren.Add(new RawProto("max_expand_ratio", max_expand_ratio.ToString()));

            return(new RawProto(strName, "", rgChildren));
        }
Exemplo n.º 8
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 GatherParameter FromProto(RawProto rp)
        {
            string          strVal;
            GatherParameter p = new GatherParameter();

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

            return(p);
        }
        /// <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 ThresholdParameter FromProto(RawProto rp)
        {
            string             strVal;
            ThresholdParameter p = new ThresholdParameter();

            if ((strVal = rp.FindValue("threshold")) != null)
            {
                p.threshold = ParseDouble(strVal);
            }

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

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

            return(p);
        }
Exemplo n.º 11
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 EluParameter FromProto(RawProto rp)
        {
            string       strVal;
            EluParameter p = new EluParameter();

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

            return(p);
        }
Exemplo n.º 12
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 TVLossParameter FromProto(RawProto rp)
        {
            string          strVal;
            TVLossParameter p = new TVLossParameter();

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

            return(p);
        }
Exemplo n.º 13
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 EltwiseParameter FromProto(RawProto rp)
        {
            string           strVal;
            EltwiseParameter p = new EltwiseParameter();

            if ((strVal = rp.FindValue("operation")) != null)
            {
                switch (strVal)
                {
                case "PROD":
                    p.operation = EltwiseOp.PROD;
                    break;

                case "SUM":
                    p.operation = EltwiseOp.SUM;
                    break;

                case "MAX":
                    p.operation = EltwiseOp.MAX;
                    break;

                case "MIN":
                    p.operation = EltwiseOp.MIN;
                    break;

                case "DIV":
                    p.operation = EltwiseOp.DIV;
                    break;

                case "SUB":
                    p.operation = EltwiseOp.SUB;
                    break;

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

            p.coeff = rp.FindArray <double>("coeff");

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

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

            return(p);
        }
Exemplo n.º 14
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 DistortionParameter FromProto(RawProto rp)
        {
            DistortionParameter p = new DistortionParameter();
            string strVal;

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

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

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

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

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

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

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

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

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

            return(p);
        }
Exemplo n.º 15
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 PermuteParameter FromProto(RawProto rp)
        {
            PermuteParameter p = new PermuteParameter();

            RawProtoCollection rgChildren = rp.FindChildren("order");

            foreach (RawProto rp1 in rgChildren)
            {
                p.order.Add(int.Parse(rp1.Value));
            }

            return(p);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Convert this object to a raw proto.
        /// </summary>
        /// <param name="strName">Specifies the name of the proto.</param>
        /// <returns>The new proto is returned.</returns>
        public override RawProto ToProto(string strName)
        {
            RawProto           rpBase     = base.ToProto("option");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase);
            rgChildren.Add(new RawProto("boundary_left", boundary_left.ToString()));
            rgChildren.Add(new RawProto("boundary_right", boundary_right.ToString()));
            rgChildren.Add(new RawProto("boundary_top", boundary_top.ToString()));
            rgChildren.Add(new RawProto("boundary_bottom", boundary_bottom.ToString()));

            return(new RawProto(strName, "", rgChildren));
        }
Exemplo n.º 17
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 ParameterParameter FromProto(RawProto rp)
        {
            ParameterParameter p = new ParameterParameter();

            RawProto rp1 = rp.FindChild("shape");

            if (rp1 != null)
            {
                p.shape = BlobShape.FromProto(rp1);
            }

            return(p);
        }
Exemplo n.º 18
0
        /** @copydoc PoolingParameter::ToProto */
        public override RawProto ToProto(string strName)
        {
            dilation.Clear();
            RawProto           rpBase     = base.ToProto("pooling");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase.Children);
            rgChildren.Add <uint>("unpool_size", m_rgUnpool);
            rgChildren.Add("unpool_h", m_nUnPoolH);
            rgChildren.Add("unpool_w", m_nUnPoolW);

            return(new RawProto(strName, "", rgChildren));
        }
Exemplo n.º 19
0
        public void TestCreateSolver()
        {
            ModelBuilder builder = create();

            SolverParameter solverParam = builder.CreateSolver();
            RawProto        proto       = solverParam.ToProto("root");
            string          strSolver   = proto.ToString();

            RawProto        proto2       = RawProto.Parse(strSolver);
            SolverParameter solverParam2 = SolverParameter.FromProto(proto2);

            m_log.CHECK(solverParam2.Compare(solverParam), "The two solver parameters should be the same!");
        }
Exemplo n.º 20
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 TileParameter FromProto(RawProto rp)
        {
            string strVal;
            TileParameter p = new TileParameter();

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

            if ((strVal = rp.FindValue("tiles")) != null)
                p.tiles = int.Parse(strVal);

            return p;
        }
Exemplo n.º 21
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 ContrastiveLossParameter FromProto(RawProto rp)
        {
            string strVal;
            ContrastiveLossParameter p = new ContrastiveLossParameter();

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

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

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

            if ((strVal = rp.FindValue("centroid_learning")) != null)
            {
                if (strVal == CENTROID_LEARNING.ALL.ToString())
                {
                    p.centroid_learning = CENTROID_LEARNING.ALL;
                }
                else if (strVal == CENTROID_LEARNING.MATCHING.ToString())
                {
                    p.centroid_learning = CENTROID_LEARNING.MATCHING;
                }
                else if (strVal == CENTROID_LEARNING.NONMATCHING.ToString())
                {
                    p.centroid_learning = CENTROID_LEARNING.NONMATCHING;
                }
            }

            if ((strVal = rp.FindValue("distance_calculation")) != null)
            {
                if (strVal == DISTANCE_CALCULATION.MANHATTAN.ToString())
                {
                    p.distance_calculation = DISTANCE_CALCULATION.MANHATTAN;
                }
            }

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

            return(p);
        }
Exemplo n.º 22
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 ReductionParameter FromProto(RawProto rp)
        {
            string             strVal;
            ReductionParameter p = new ReductionParameter();

            if ((strVal = rp.FindValue("operation")) != null)
            {
                switch (strVal)
                {
                case "ASUM":
                    p.operation = ReductionOp.ASUM;
                    break;

                case "MEAN":
                    p.operation = ReductionOp.MEAN;
                    break;

                case "SUM":
                    p.operation = ReductionOp.SUM;
                    break;

                case "SUMSQ":
                    p.operation = ReductionOp.SUMSQ;
                    break;

                case "MIN":
                    p.operation = ReductionOp.MIN;
                    break;

                case "MAX":
                    p.operation = ReductionOp.MAX;
                    break;

                default:
                    throw new Exception("Uknown 'operation' value: " + strVal);
                }
            }

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

            if ((strVal = rp.FindValue("coeff")) != null)
            {
                p.coeff = ParseDouble(strVal);
            }

            return(p);
        }
Exemplo n.º 23
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 SwishParameter FromProto(RawProto rp)
        {
            string         strVal;
            SwishParameter p = new SwishParameter();

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

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

            return(p);
        }
Exemplo n.º 24
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 SoftmaxParameter FromProto(RawProto rp)
        {
            string           strVal;
            SoftmaxParameter p = new SoftmaxParameter();

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

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

            return(p);
        }
Exemplo n.º 25
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 CropParameter FromProto(RawProto rp)
        {
            string        strVal;
            CropParameter p = new CropParameter();

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

            p.offset = rp.FindArray <uint>("offset");

            return(p);
        }
Exemplo n.º 26
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 EluParameter FromProto(RawProto rp)
        {
            string       strVal;
            EluParameter p = new EluParameter();

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

            if ((strVal = rp.FindValue("alpha")) != null)
            {
                p.alpha = ParseDouble(strVal);
            }

            return(p);
        }
Exemplo n.º 27
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 InputParameter FromProto(RawProto rp)
        {
            InputParameter p = new InputParameter();

            RawProtoCollection col = rp.FindChildren("shape");

            foreach (RawProto rp1 in col)
            {
                BlobShape b = BlobShape.FromProto(rp1);
                p.m_rgShape.Add(b);
            }

            return(p);
        }
Exemplo n.º 28
0
        /** @copydoc EngineParameter::ToProto */
        public override RawProto ToProto(string strName)
        {
            RawProto           rpBase     = base.ToProto("engine");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase.Children);
            rgChildren.Add("local_size", local_size.ToString());
            rgChildren.Add("alpha", alpha.ToString());
            rgChildren.Add("beta", beta.ToString());
            rgChildren.Add("norm_region", norm_region.ToString());
            rgChildren.Add("k", k.ToString());

            return(new RawProto(strName, "", rgChildren));
        }
Exemplo n.º 29
0
        /** @copydoc LayerParameterBase::ToProto */
        public override RawProto ToProto(string strName)
        {
            RawProto           rpBase     = base.ToProto("engine");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase.Children);

            if (beta != 0)
            {
                rgChildren.Add("beta", beta.ToString());
            }

            return(new RawProto(strName, "", rgChildren));
        }
Exemplo n.º 30
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 LabelMap FromProto(RawProto rp)
        {
            LabelMap p = new LabelMap();

            RawProtoCollection col = rp.FindChildren("item");

            foreach (RawProto child in col)
            {
                LabelMapItem item = LabelMapItem.FromProto(child);
                p.item.Add(item);
            }

            return(p);
        }