Ejemplo n.º 1
0
        /// <summary>
        /// Copy the source object.
        /// </summary>
        /// <param name="src">Specifies the source data.</param>
        public override void Copy(OptionalParameter src)
        {
            base.Copy(src);

            if (src is ResizeParameter)
            {
                ResizeParameter p = (ResizeParameter)src;
                m_fProb = p.prob;
                m_mode  = p.resize_mode;
                m_pad   = p.pad_mode;

                m_rgInterp = new List <InterpMode>();
                foreach (InterpMode interp in p.m_rgInterp)
                {
                    m_rgInterp.Add(interp);
                }

                m_nHeight      = p.height;
                m_nWidth       = p.width;
                m_nHeightScale = p.height_scale;
                m_nWidthScale  = p.width_scale;

                m_rgfPadValue = new List <float>();
                foreach (float fPad in p.pad_value)
                {
                    m_rgfPadValue.Add(fPad);
                }
            }
        }
Ejemplo n.º 2
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);
        }
        /** @copydoc LayerParameterBase::Copy */
        public override void Copy(LayerParameterBase src)
        {
            DetectionEvaluateParameter p = (DetectionEvaluateParameter)src;

            m_nNumClasses          = p.m_nNumClasses;
            m_nBackgroundLabelId   = p.m_nBackgroundLabelId;
            m_fOverlapThreshold    = p.m_fOverlapThreshold;
            m_bEvaluateDifficultGt = p.m_bEvaluateDifficultGt;
            m_strNameSizeFile      = p.m_strNameSizeFile;

            if (p.m_resizeParam == null)
            {
                m_resizeParam = null;
            }
            else
            {
                m_resizeParam = p.resize_param.Clone();
            }
        }
        /// <summary>
        /// Copy the source object.
        /// </summary>
        /// <param name="src">Specifies the source data.</param>
        public override void Copy(OptionalParameter src)
        {
            base.Copy(src);

            if (src is SaveOutputParameter)
            {
                SaveOutputParameter p = (SaveOutputParameter)src;

                m_strOutputDirectory  = p.m_strOutputDirectory;
                m_strOutputNamePrefix = p.m_strOutputNamePrefix;
                m_outputFormat        = p.m_outputFormat;
                m_strLabelMapFile     = p.m_strLabelMapFile;
                m_strNameSizeFile     = p.m_strNameSizeFile;
                m_nNumTestImage       = p.m_nNumTestImage;

                m_resizeParam = null;
                if (p.resize_param != null)
                {
                    m_resizeParam = p.resize_param.Clone();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Copy the source object.
        /// </summary>
        /// <param name="src">Specifies the source data.</param>
        public void Copy(ResizeParameter src)
        {
            m_fProb = src.prob;
            m_mode  = src.resize_mode;
            m_pad   = src.pad_mode;

            m_rgInterp = new List <InterpMode>();
            foreach (InterpMode interp in src.m_rgInterp)
            {
                m_rgInterp.Add(interp);
            }

            m_nHeight      = src.height;
            m_nWidth       = src.width;
            m_nHeightScale = src.height_scale;
            m_nWidthScale  = src.width_scale;

            m_rgfPadValue = new List <float>();
            foreach (float fPad in src.pad_value)
            {
                m_rgfPadValue.Add(fPad);
            }
        }
        /// <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 DetectionEvaluateParameter FromProto(RawProto rp)
        {
            DetectionEvaluateParameter p = new DetectionEvaluateParameter();
            string strVal;

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

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

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

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

            p.name_size_file = rp.FindValue("name_size_file");

            RawProto rpResize = rp.FindChild("resize_param");

            if (rpResize != null)
            {
                p.resize_param = ResizeParameter.FromProto(rpResize);
            }

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

            RawProto rpOption = rp.FindChild("option");

            if (rpOption != null)
            {
                ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption));
            }

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

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

            if ((strVal = rp.FindValue("resize_mode")) != null)
            {
                switch (strVal)
                {
                case "WARP":
                    p.resize_mode = ResizeMode.WARP;
                    break;

                case "FIT_SMALL_SIZE":
                    p.resize_mode = ResizeMode.FIT_SMALL_SIZE;
                    break;

                case "FIT_LARGE_SIZE_AND_PAD":
                    p.resize_mode = ResizeMode.FIT_LARGE_SIZE_AND_PAD;
                    break;

                default:
                    throw new Exception("Unknown resize_mode '" + strVal + "'!");
                }
            }

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

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

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

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

            if ((strVal = rp.FindValue("pad_mode")) != null)
            {
                switch (strVal)
                {
                case "CONSTANT":
                    p.pad_mode = PadMode.CONSTANT;
                    break;

                case "MIRRORED":
                    p.pad_mode = PadMode.MIRRORED;
                    break;

                case "REPEAT_NEAREST":
                    p.pad_mode = PadMode.REPEAT_NEAREST;
                    break;

                default:
                    throw new Exception("Unknown pad_mode '" + strVal + "'!");
                }
            }

            p.pad_value = new List <float>();
            RawProtoCollection col = rp.FindChildren("pad_value");

            foreach (RawProto rp1 in col)
            {
                if ((strVal = rp.FindValue("pad_value")) != null)
                {
                    p.pad_value.Add(float.Parse(strVal));
                }
            }

            p.interp_mode = new List <InterpMode>();
            RawProtoCollection col1 = rp.FindChildren("interp_mode");

            foreach (RawProto pr1 in col1)
            {
                strVal = pr1.Value;

                switch (strVal)
                {
                case "LINEAR":
                    p.interp_mode.Add(InterpMode.LINEAR);
                    break;

                case "AREA":
                    p.interp_mode.Add(InterpMode.AREA);
                    break;

                case "NEAREST":
                    p.interp_mode.Add(InterpMode.NEAREST);
                    break;

                case "CUBIC":
                    p.interp_mode.Add(InterpMode.CUBIC);
                    break;

                case "LANCZOS4":
                    p.interp_mode.Add(InterpMode.LANCZOS4);
                    break;

                default:
                    throw new Exception("Unknown interp_mode '" + 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 new SaveOutputParameter FromProto(RawProto rp)
        {
            SaveOutputParameter p = new SaveOutputParameter(false);
            string strVal;

            RawProto rpOption = rp.FindChild("option");

            if (rpOption != null)
            {
                ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption));
            }

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

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

            if ((strVal = rp.FindValue("output_format")) != null)
            {
                if (strVal == OUTPUT_FORMAT.VOC.ToString())
                {
                    p.output_format = OUTPUT_FORMAT.VOC;
                }
                else if (strVal == OUTPUT_FORMAT.COCO.ToString())
                {
                    p.output_format = OUTPUT_FORMAT.COCO;
                }
                else
                {
                    throw new Exception("Unknown output_format '" + strVal + "'!");
                }
            }

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

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

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

            RawProto rpResize = rp.FindChild("resize_param");

            if (rpResize != null)
            {
                p.resize_param = ResizeParameter.FromProto(rpResize);
            }

            return(p);
        }