/// <summary> /// Parse a new SampleConstraint from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto containing a representation of the SampleConstraint.</param> /// <returns>A new instance of the SampleConstraint is returned.</returns> public static SamplerConstraint FromProto(RawProto rp) { string strVal; SamplerConstraint p = new SamplerConstraint(); if ((strVal = rp.FindValue("min_jaccard_overlap")) != null) { p.min_jaccard_overlap = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("max_jaccard_overlap")) != null) { p.max_jaccard_overlap = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("min_sample_coverage")) != null) { p.min_sample_coverage = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("max_sample_coverage")) != null) { p.max_sample_coverage = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("min_object_coverage")) != null) { p.min_object_coverage = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("max_object_coverage")) != null) { p.max_object_coverage = BaseParameter.ParseFloat(strVal); } return(p); }
private void load(StreamReader sr, InnerProductLayer <T> layer) { for (int i = 0; i < layer.blobs.Count; i++) { List <float> rgf = new List <float>(); string strLine = sr.ReadLine(); string[] rgstr = strLine.Split(','); for (int j = 0; j < rgstr.Length; j++) { rgf.Add(BaseParameter.ParseFloat(rgstr[j])); } layer.blobs[i].mutable_cpu_data = Utility.ConvertVec <T>(rgf.ToArray()); } for (int i = 0; i < layer.internal_blobs.Count; i++) { List <float> rgf = new List <float>(); string strLine = sr.ReadLine(); string[] rgstr = strLine.Split(','); for (int j = 0; j < rgstr.Length; j++) { rgf.Add(BaseParameter.ParseFloat(rgstr[j])); } layer.internal_blobs[i].mutable_cpu_data = Utility.ConvertVec <T>(rgf.ToArray()); } }
/// <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 NonMaximumSuppressionParameter FromProto(RawProto rp) { NonMaximumSuppressionParameter p = new NonMaximumSuppressionParameter(false); string strVal; RawProto rpOption = rp.FindChild("option"); if (rpOption != null) { ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption)); } if ((strVal = rp.FindValue("nms_threshold")) != null) { p.nms_threshold = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("top_k")) != null) { p.top_k = int.Parse(strVal); } if ((strVal = rp.FindValue("eta")) != null) { p.eta = BaseParameter.ParseFloat(strVal); } return(p); }
/// <summary> /// Parse a new Sample from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto containing a representation of the Sample.</param> /// <returns>A new instance of the Sample is returned.</returns> public static Sampler FromProto(RawProto rp) { string strVal; Sampler p = new Sampler(); if ((strVal = rp.FindValue("min_scale")) != null) { p.min_scale = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("max_scale")) != null) { p.max_scale = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("min_aspect_ratio")) != null) { p.min_aspect_ratio = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("max_aspect_ratio")) != null) { p.max_aspect_ratio = BaseParameter.ParseFloat(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 SaltPepperParameter FromProto(RawProto rp) { SaltPepperParameter p = new SaltPepperParameter(false); string strVal; RawProto rpOption = rp.FindChild("option"); if (rpOption != null) { ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption)); } if ((strVal = rp.FindValue("fraction")) != null) { p.fraction = BaseParameter.ParseFloat(strVal); } p.value = new List <float>(); RawProtoCollection col = rp.FindChildren("value"); foreach (RawProto rp1 in col) { if ((strVal = rp.FindValue("value")) != null) { p.value.Add(BaseParameter.ParseFloat(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 EmitConstraint FromProto(RawProto rp) { EmitConstraint p = new EmitConstraint(false); string strVal; RawProto rpOption = rp.FindChild("option"); if (rpOption != null) { ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption)); } if ((strVal = rp.FindValue("emit_type")) != null) { switch (strVal) { case "CENTER": p.emit_type = EmitType.CENTER; break; case "MIN_OVERLAP": p.emit_type = EmitType.MIN_OVERLAP; break; default: throw new Exception("Unknown emit_type '" + strVal + "'!"); } } if ((strVal = rp.FindValue("emit_overlap")) != null) { p.emit_overlap = BaseParameter.ParseFloat(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 ExpansionParameter FromProto(RawProto rp) { ExpansionParameter p = new ExpansionParameter(false); string strVal; RawProto rpOption = rp.FindChild("option"); if (rpOption != null) { ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption)); } if ((strVal = rp.FindValue("prob")) != null) { p.prob = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("max_expand_ratio")) != null) { p.max_expand_ratio = BaseParameter.ParseFloat(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 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 = BaseParameter.ParseFloat(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); }
/// <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 NoiseParameter FromProto(RawProto rp) { NoiseParameter p = new NoiseParameter(false); string strVal; RawProto rpOption = rp.FindChild("option"); if (rpOption != null) { ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption)); } if ((strVal = rp.FindValue("prob")) != null) { p.prob = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("hist_eq")) != null) { p.hist_eq = bool.Parse(strVal); } if ((strVal = rp.FindValue("inverse")) != null) { p.inverse = bool.Parse(strVal); } if ((strVal = rp.FindValue("decolorize")) != null) { p.decolorize = bool.Parse(strVal); } if ((strVal = rp.FindValue("gauss_blur")) != null) { p.gauss_blur = bool.Parse(strVal); } if ((strVal = rp.FindValue("jpeg")) != null) { p.jpeg = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("posterize")) != null) { p.posterize = bool.Parse(strVal); } if ((strVal = rp.FindValue("erode")) != null) { p.erode = bool.Parse(strVal); } if ((strVal = rp.FindValue("saltpepper")) != null) { p.saltpepper = bool.Parse(strVal); } RawProto rp1 = rp.FindChild("saltpepper_param"); if (rp1 != null) { p.saltpepper_param = SaltPepperParameter.FromProto(rp1); } if ((strVal = rp.FindValue("clahe")) != null) { p.clahe = bool.Parse(strVal); } if ((strVal = rp.FindValue("convert_to_hsv")) != null) { p.convert_to_hsv = bool.Parse(strVal); } if ((strVal = rp.FindValue("convert_to_lab")) != null) { p.convert_to_lab = bool.Parse(strVal); } return(p); }
private bool loadXmlAnnotationFile(Log log, string strFile, SimpleDatum datum, Dictionary <string, int> rgNameToLabel) { XDocument doc = XDocument.Load(strFile); XElement size = doc.Descendants("size").First(); XElement val; val = size.Descendants("width").First(); int nWidth = int.Parse(val.Value); val = size.Descendants("height").First(); int nHeight = int.Parse(val.Value); val = size.Descendants("depth").First(); int nChannels = int.Parse(val.Value); if (datum.Height != nHeight || datum.Width != nWidth || datum.Channels != nChannels) { log.FAIL("Inconsistent image size, expected (" + datum.Channels.ToString() + "," + datum.Height.ToString() + "," + datum.Width.ToString() + ") but annotation has size (" + nChannels.ToString() + "," + nHeight.ToString() + "," + nWidth.ToString() + ")."); } int nInstanceId = 0; List <XElement> objects = doc.Descendants("object").ToList(); foreach (XElement obj in objects) { val = obj.Descendants("name").First(); string strName = val.Value; val = obj.Descendants("difficult").First(); bool bDifficult = (val.Value == "0") ? false : true; XElement bndbox = obj.Descendants("bndbox").First(); val = bndbox.Descendants("xmin").First(); float fxmin = BaseParameter.ParseFloat(val.Value); if (fxmin > nWidth || fxmin < 0) { log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary."); } val = bndbox.Descendants("ymin").First(); float fymin = BaseParameter.ParseFloat(val.Value); if (fymin > nHeight || fymin < 0) { log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary."); } val = bndbox.Descendants("xmax").First(); float fxmax = BaseParameter.ParseFloat(val.Value); if (fxmax > nWidth || fxmax < 0) { log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary."); } val = bndbox.Descendants("ymax").First(); float fymax = BaseParameter.ParseFloat(val.Value); if (fymax > nHeight || fymax < 0) { log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary."); } if (!rgNameToLabel.ContainsKey(strName)) { log.FAIL("Could not find the label '" + strName + "' in the label mapping!"); return(false); } int nLabel = rgNameToLabel[strName]; NormalizedBBox bbox = new NormalizedBBox(fxmin / nWidth, fymin / nHeight, fxmax / nWidth, fymax / nHeight, nLabel, bDifficult); datum.SetLabel(nLabel); foreach (AnnotationGroup g in datum.annotation_group) { if (nLabel == g.group_label) { if (g.annotations.Count == 0) { nInstanceId = 0; } else { nInstanceId = g.annotations[g.annotations.Count - 1].instance_id + 1; } g.annotations.Add(new Annotation(bbox, nInstanceId)); bbox = null; break; } } if (bbox != null) { nInstanceId = 0; AnnotationGroup grp = new AnnotationGroup(null, nLabel); grp.annotations.Add(new Annotation(bbox, nInstanceId)); datum.annotation_group.Add(grp); bbox = null; } } return(true); }
/// <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 = BaseParameter.ParseFloat(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(BaseParameter.ParseFloat(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 DistortionParameter FromProto(RawProto rp) { DistortionParameter p = new DistortionParameter(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("brightness_prob")) != null) { p.brightness_prob = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("brightness_delta")) != null) { p.brightness_delta = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("contrast_prob")) != null) { p.contrast_prob = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("contrast_lower")) != null) { p.contrast_lower = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("contrast_upper")) != null) { p.contrast_upper = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("saturation_prob")) != null) { p.saturation_prob = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("saturation_lower")) != null) { p.saturation_lower = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("saturation_upper")) != null) { p.saturation_upper = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("random_order_prob")) != null) { p.random_order_prob = BaseParameter.ParseFloat(strVal); } if ((strVal = rp.FindValue("use_gpu")) != null) { p.use_gpu = bool.Parse(strVal); } if ((strVal = rp.FindValue("random_seed")) != null) { p.random_seed = long.Parse(strVal); } return(p); }