/// <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()
        {
            DetectionOutputParameter p = new DetectionOutputParameter();

            p.Copy(this);
            return(p);
        }
        /// <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());
            DetectionOutputParameter p = FromProto(proto);

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

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

            m_nNumClasses              = p.m_nNumClasses;
            m_bShareLocation           = p.m_bShareLocation;
            m_nBackgroundLabelId       = p.m_nBackgroundLabelId;
            m_nmsParam                 = p.m_nmsParam.Clone();
            m_saveOutputParam          = p.save_output_param.Clone() as SaveOutputParameter;
            m_codeType                 = p.m_codeType;
            m_bVarianceEncodedInTarget = p.m_bVarianceEncodedInTarget;
            m_nKeepTopK                = p.m_nKeepTopK;
            m_fConfidenceThreshold     = p.m_fConfidenceThreshold;
            m_bVisualize               = p.m_bVisualize;
            m_fVisualizeThreshold      = p.m_fVisualizeThreshold;
            m_strSaveFile              = p.m_strSaveFile;
        }
        /// <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 DetectionOutputParameter FromProto(RawProto rp)
        {
            DetectionOutputParameter p = new DetectionOutputParameter();
            string strVal;

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

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

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

            RawProto rpNms = rp.FindChild("nms_param");

            if (rpNms != null)
            {
                p.nms_param = NonMaximumSuppressionParameter.FromProto(rpNms);
            }

            RawProto rpSave = rp.FindChild("save_output_param");

            if (rpSave != null)
            {
                p.save_output_param = SaveOutputParameter.FromProto(rpSave);
            }

            if ((strVal = rp.FindValue("code_type")) != null)
            {
                if (strVal == PriorBoxParameter.CodeType.CENTER_SIZE.ToString())
                {
                    p.code_type = PriorBoxParameter.CodeType.CENTER_SIZE;
                }
                else if (strVal == PriorBoxParameter.CodeType.CORNER.ToString())
                {
                    p.code_type = PriorBoxParameter.CodeType.CORNER;
                }
                else if (strVal == PriorBoxParameter.CodeType.CORNER_SIZE.ToString())
                {
                    p.code_type = PriorBoxParameter.CodeType.CORNER_SIZE;
                }
                else
                {
                    throw new Exception("Unknown PriorBoxParameter.CodeType '" + strVal + "'!");
                }
            }

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

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

            if ((strVal = rp.FindValue("confidence_threshold")) != null)
            {
                p.confidence_threshold = ParseFloat(strVal);
            }

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

            if ((strVal = rp.FindValue("visualize_threshold")) != null)
            {
                p.visualize_threshold = ParseFloat(strVal);
            }

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

            return(p);
        }