예제 #1
0
        /// <summary>
        /// Creates a new copy of this instance of the parameter.
        /// </summary>
        /// <returns>A new instance of this parameter is returned.</returns>
        public override LayerParameterBase Clone()
        {
            DecodeParameter p = new DecodeParameter();

            p.Copy(this);
            return(p);
        }
예제 #2
0
        /// <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(System.IO.BinaryReader br, bool bNewInstance = true)
        {
            RawProto        proto = RawProto.Parse(br.ReadString());
            DecodeParameter p     = FromProto(proto);

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

            return(p);
        }
예제 #3
0
        /// <summary>
        /// Copy on parameter to another.
        /// </summary>
        /// <param name="src">Specifies the parameter to copy.</param>
        public override void Copy(LayerParameterBase src)
        {
            DecodeParameter p = (DecodeParameter)src;

            m_nCentroidOutputIteration = p.m_nCentroidOutputIteration;
            m_nCacheSize              = p.m_nCacheSize;
            m_bOutputCentroids        = p.m_bOutputCentroids;
            m_dfPreGenAlpha           = p.m_dfPreGenAlpha;
            m_nPreGenerateTargetCount = p.m_nPreGenerateTargetCount;
            m_bEnableCentroidUpdate   = p.m_bEnableCentroidUpdate;

            if (p.m_rgIgnoreLabels != null)
            {
                m_rgIgnoreLabels = Utility.Clone <int>(p.m_rgIgnoreLabels);
            }

            m_target = p.m_target;
            m_nK     = p.m_nK;
        }
예제 #4
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 DecodeParameter FromProto(RawProto rp)
        {
            string          strVal;
            DecodeParameter p = new DecodeParameter();

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

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

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

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

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

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

            p.ignore_labels = new List <int>();
            RawProtoCollection rpIgnore = rp.FindChildren("ignore_label");

            foreach (RawProto rplabel in rpIgnore)
            {
                int nLabel = int.Parse(rplabel.Value);
                if (!p.ignore_labels.Contains(nLabel))
                {
                    p.ignore_labels.Add(nLabel);
                }
            }

            if ((strVal = rp.FindValue("target")) != null)
            {
                if (strVal == TARGET.KNN.ToString())
                {
                    p.target = TARGET.KNN;
                }
                else if (strVal == TARGET.PREGEN.ToString())
                {
                    p.target = TARGET.PREGEN;
                }
                else
                {
                    p.target = TARGET.CENTROID;
                }
            }

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

            return(p);
        }