/// <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 = float.Parse(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(float.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 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 = float.Parse(strVal); } if ((strVal = rp.FindValue("top_k")) != null) { p.top_k = int.Parse(strVal); } if ((strVal = rp.FindValue("eta")) != null) { p.eta = float.Parse(strVal); } return(p); }
/// <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); } } }
/// <summary> /// Copy the object. /// </summary> /// <param name="src">The copy is placed in this parameter.</param> public override void Copy(OptionalParameter src) { base.Copy(src); if (src is NoiseParameter) { NoiseParameter p = (NoiseParameter)src; m_fProb = p.prob; } }
public void TestIsInstanceOfGeneric() { var p1 = new OptionalParameter <int>(); bool r1 = ReflectionUtilities.IsInstanceOfGeneric(p1, typeof(OptionalParameter <>)); var p2 = new RequiredParameter <string>(); bool r2 = ReflectionUtilities.IsInstanceOfGeneric(p2, typeof(RequiredParameter <>)); Assert.IsTrue(r1); Assert.IsTrue(r2); }
/// <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 EmitConstraint) { EmitConstraint p = (EmitConstraint)src; m_emitType = p.emit_type; m_fEmitOverlap = p.emit_overlap; } }
/// <summary> /// Copy the object. /// </summary> /// <param name="src">The copy is placed in this parameter.</param> public override void Copy(OptionalParameter src) { base.Copy(src); if (src is ExpansionParameter) { ExpansionParameter p = (ExpansionParameter)src; m_fProb = p.prob; m_fMaxExpandRatio = p.max_expand_ratio; } }
/// <summary> /// Copy the object. /// </summary> /// <param name="src">The copy is placed in this parameter.</param> public override void Copy(OptionalParameter src) { base.Copy(src); if (src is NonMaximumSuppressionParameter) { NonMaximumSuppressionParameter p = (NonMaximumSuppressionParameter)src; m_fNmsThreshold = p.nms_threshold; m_nTopK = p.top_k; m_fEta = p.eta; } }
/// <summary> /// Copy the object. /// </summary> /// <param name="src">The copy is placed in this parameter.</param> public override void Copy(OptionalParameter src) { base.Copy(src); if (src is SaltPepperParameter) { SaltPepperParameter p = (SaltPepperParameter)src; m_fFraction = p.fraction; m_rgValue = new List <float>(); foreach (float fVal in p.value) { m_rgValue.Add(fVal); } } }
/// <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(); } } }
public override uint Parse(byte[] msg) { int pos = (int)base.Parse(msg); uint cmdLength = SupportOperations.FromBigEndianUInt(msg); int newpos = 0; byte[] localArray; ASCIIEncoding ascii = new ASCIIEncoding(); ServiceType = SupportOperations.getStringValue(msg, pos, out newpos); localArray = new byte[msg.Length - newpos]; Array.Copy(msg, newpos, localArray, 0, msg.Length - newpos); pos = newpos + (int)Source.Parse(localArray); localArray = new byte[msg.Length - pos]; Array.Copy(msg, pos, localArray, 0, msg.Length - pos); pos += (int)Destination.Parse(localArray); EsmClass = msg[pos++]; RegisteredDelivery = msg[pos++]; DataCoding = (dataCodingEnum)Enum.Parse(typeof(dataCodingEnum), msg[pos++].ToString()); // parse optional params localArray = new byte[2]; while (pos < cmdLength) { OptionalParameter op = new OptionalParameter(); Array.Copy(msg, pos, localArray, 0, 2); op.Param = (OptionalParameter.tagEnum)Enum.Parse(typeof(OptionalParameter.tagEnum), SupportOperations.FromBigEndianUShort(localArray).ToString()); pos += 2; Array.Copy(msg, pos, localArray, 0, 2); op.Length = SupportOperations.FromBigEndianUShort(localArray); pos += 2; op.Value = new byte[op.Length]; Array.Copy(msg, pos, op.Value, 0, op.Length); pos += op.Length; OptionalParamList.Add(op); } return((uint)pos); }
/// <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> /// Copy the object. /// </summary> /// <param name="src">The copy is placed in this parameter.</param> public override void Copy(OptionalParameter src) { base.Copy(src); if (src is DistortionParameter) { DistortionParameter p = (DistortionParameter)src; m_fBrightnessProb = p.brightness_prob; m_fBrightnessDelta = p.brightness_delta; m_fContrastProb = p.contrast_prob; m_fContrastLower = p.contrast_lower; m_fContrastUpper = p.contrast_upper; m_fSaturationProb = p.saturation_prob; m_fSaturationLower = p.saturation_lower; m_fSaturationUpper = p.saturation_upper; m_fRandomOrderProb = p.random_order_prob; m_lRandomSeed = p.m_lRandomSeed; m_bUseGpu = p.use_gpu; } }
/// <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 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 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 = float.Parse(strVal); } if ((strVal = rp.FindValue("brightness_delta")) != null) { p.brightness_delta = float.Parse(strVal); } if ((strVal = rp.FindValue("contrast_prob")) != null) { p.contrast_prob = float.Parse(strVal); } if ((strVal = rp.FindValue("contrast_lower")) != null) { p.contrast_lower = float.Parse(strVal); } if ((strVal = rp.FindValue("contrast_upper")) != null) { p.contrast_upper = float.Parse(strVal); } if ((strVal = rp.FindValue("saturation_prob")) != null) { p.saturation_prob = float.Parse(strVal); } if ((strVal = rp.FindValue("saturation_lower")) != null) { p.saturation_lower = float.Parse(strVal); } if ((strVal = rp.FindValue("saturation_upper")) != null) { p.saturation_upper = float.Parse(strVal); } if ((strVal = rp.FindValue("random_order_prob")) != null) { p.random_order_prob = float.Parse(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); }
static void Main(string[] args) { /* * Console.WriteLine("Hello welcome to C# world!!"); * Console.WriteLine("Please enter your name?"); * * string name = Console.ReadLine(); * * //using placeholder * Console.WriteLine("My name is {0}", name); * * //using Concatenation * Console.WriteLine("My name is " + name); */ //Program.EvenNumber(30) ----If the EvenNumber method is static, then we can call using Class name directly. Program p = new Program(); //p.Practice1(); //p.EvenNumber(30); //int a = p.Add(4, 6); //Console.WriteLine(a); /* * int Sum = 0; * int Product = 0; * Calculate(7, 5, out Sum, out Product); * Console.WriteLine("Sum of number is {0} and Product of number is {1}", Sum, Product); */ /*FTE FullTimeEmployee = new FTE(); * FullTimeEmployee.FirstName = "Vivek"; * FullTimeEmployee.LastName = "Kumar"; * FullTimeEmployee.PrintFullName(); */ OptionalParameter opt = new OptionalParameter(); var varInt = 20; var varFloat = 20.1234; var varChar = "A"; var varString = "Vivek"; dynamic dynamicA = 20; dynamic dynamicF = 20.1234; dynamic dynamicB = "A"; dynamic dynamicC = "Vivek"; Console.WriteLine("20 - treated as --> " + varInt.GetType()); Console.WriteLine("20.1234 - treated as --> " + varFloat.GetType()); Console.WriteLine("A - treated as --> " + varChar.GetType().GetType()); Console.WriteLine("Vivek - treated as --> " + varString.GetType()); Console.WriteLine("========================="); Console.WriteLine("20 - treated as --> " + dynamicA.GetType()); Console.WriteLine("20.1234 - treated as --> " + dynamicF.GetType()); Console.WriteLine("A - treated as --> " + dynamicB.GetType()); Console.WriteLine("Vivek - treated as --> " + dynamicC.GetType()); Console.WriteLine("========================="); opt.EmployeeDetail(FName: "vivek", PortalId: 4444); }
/// <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); }
/// <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); }
// TODO: rewrite this method in following fashion: with regex search for {...}, than search for Fields or Properties with ... name, if they are required check value for null /// <summary> /// Returns formatted formula. If formula is longer than maximum allowed length InvalidOperationException is thrown. /// </summary> /// <returns>String representation of formula.</returns> public sealed override string ToString() { string formula = this.Template; MemberInfo[] memberInfos = this.GetType().FindMembers(MemberTypes.Field | MemberTypes.Property, BindingFlags.Public | BindingFlags.Instance, FilterMembers, null); foreach (MemberInfo memberInfo in memberInfos) { object[] requiredAttrs = memberInfo.GetCustomAttributes(typeof(RequiredParameter), false); object[] optionalAttrs = memberInfo.GetCustomAttributes(typeof(OptionalParameter), false); object fieldValue = null; switch (memberInfo.MemberType) { case MemberTypes.Field: { fieldValue = (memberInfo as FieldInfo).GetValue(this); break; } case MemberTypes.Property: { fieldValue = (memberInfo as PropertyInfo).GetValue(this, null); break; } } // if is required and null throw exception if (requiredAttrs.Length == 1 && fieldValue == null) { throw new ArgumentException(String.Format("Field {0} is required and must not be null.", memberInfo.Name)); } if (requiredAttrs.Length == 1 && fieldValue != null) { RequiredParameter attr = requiredAttrs[0] as RequiredParameter; // if parameter has overriden Name use it, otherwise use name of field formula = attr.Name != null ? formula.Replace("{" + attr.Name + "}", fieldValue.ToString()) : formula.Replace("{" + memberInfo.Name + "}", fieldValue.ToString()); } else if (optionalAttrs.Length == 1 && fieldValue != null) { OptionalParameter attr = optionalAttrs[0] as OptionalParameter; // if parameter has overriden Name use it, otherwise use name of field formula = attr.Name != null ? formula.Replace("{" + attr.Name + "}", fieldValue.ToString()) : formula.Replace("{" + memberInfo.Name + "}", fieldValue.ToString()); } else if (optionalAttrs.Length == 1 && fieldValue == null) { OptionalParameter attr = optionalAttrs[0] as OptionalParameter; // if parameter has overriden Name use it, otherwise use name of field formula = attr.Name != null ? formula.Replace("{" + attr.Name + "}", "") : formula.Replace("{" + memberInfo.Name + "}", ""); } } if (formula.Length > MaximumFormulaLength) { throw new InvalidOperationException(String.Format("This formula contains {0} characters which is more than maximum allowed length.", formula.Length)); } return(formula); }