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

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

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

            if ((strVal = rp.FindValue("loc_weight")) != null)
            {
                p.loc_weight = float.Parse(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("match_type")) != null)
            {
                p.match_type = MatchTypeFromString(strVal);
            }

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

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

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

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

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

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

            if ((strVal = rp.FindValue("code_type")) != null)
            {
                p.code_type = PriorBoxParameter.CodeTypeFromString(strVal);
            }

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

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

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

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

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

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

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

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

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