/// <summary> /// Parses a RawProto representing a NetState into a NetState instance. /// </summary> /// <param name="rp">Specifies the RawProto representing the NetState.</param> /// <returns>The new instance of the NetState is returned.</returns> public static NetState FromProto(RawProto rp) { string strVal; NetState p = new NetState(); if ((strVal = rp.FindValue("phase")) != null) { switch (strVal) { case "TEST": p.phase = Phase.TEST; break; case "TRAIN": p.phase = Phase.TRAIN; break; case "NONE": p.phase = Phase.NONE; break; default: throw new Exception("Unknown 'phase' value: " + strVal); } } if ((strVal = rp.FindValue("level")) != null) { p.level = int.Parse(strVal); } p.stage = rp.FindArray <string>("stage"); 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 LabelMappingParameter FromProto(RawProto rp) { LabelMappingParameter p = new LabelMappingParameter(); p.m_rgMapping = LabelMappingCollection.Parse(rp.FindArray <string>("mapping")); string strUpdateDb = rp.FindValue("update_database"); if (strUpdateDb != null && strUpdateDb.ToLower() == "true") { p.m_bUpdateDatabase = true; } string strReset = rp.FindValue("reset_database_labels"); if (strReset != null && strReset.ToLower() == "true") { p.m_bResetDatabaseLabels = true; } p.m_strLabelBoosts = rp.FindValue("label_boosts"); if (p.m_strLabelBoosts == null) { p.m_strLabelBoosts = ""; } return(p); }
/// <summary> /// Collect the inputs from the RawProto. /// </summary> /// <param name="rp">Specifies the raw proto.</param> /// <returns>A dictionary of the inputs and their shapes is returned.</returns> public static Dictionary <string, BlobShape> InputFromProto(RawProto rp) { List <string> rgstrInput = rp.FindArray <string>("input"); List <BlobShape> rgShape = new List <BlobShape>(); RawProtoCollection rgp = rp.FindChildren("input_shape"); foreach (RawProto rpChild in rgp) { rgShape.Add(BlobShape.FromProto(rpChild)); } if (rgstrInput.Count != rgShape.Count) { throw new Exception("The input array and shape array must have the same count!"); } Dictionary <string, BlobShape> rgInput = new Dictionary <string, BlobShape>(); for (int i = 0; i < rgstrInput.Count; i++) { rgInput.Add(rgstrInput[i], rgShape[i]); } return(rgInput); }
/// <summary> /// Parses the parameter from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto to parse.</param> /// <param name="p">Optionally, specifies an instance to load. If <i>null</i>, a new instance is created and loaded.</param> /// <returns>A new instance of the parameter is returned.</returns> public static ModelDataParameter FromProto(RawProto rp, ModelDataParameter p = null) { string strVal; if (p == null) { p = new ModelDataParameter(); } p.source = rp.FindArray <string>("source"); if ((strVal = rp.FindValue("batch_size")) != null) { p.batch_size = uint.Parse(strVal); } if ((strVal = rp.FindValue("time_steps")) != null) { p.time_steps = uint.Parse(strVal); } if ((strVal = rp.FindValue("input_dim")) != null) { p.input_dim = uint.Parse(strVal); } if ((strVal = rp.FindValue("shuffle")) != null) { p.shuffle = bool.Parse(strVal); } return(p); }
/// <summary> /// Parse a RawProto into a new instance of the parameter. /// </summary> /// <param name="rp">Specifies the RawProto to parse.</param> /// <returns>A new instance of the parameter is returned.</returns> public static NetParameter FromProto(RawProto rp) { string strVal; NetParameter p = new NetParameter(); if ((strVal = rp.FindValue("name")) != null) { p.name = strVal; } p.input = rp.FindArray <string>("input"); RawProtoCollection rgp = rp.FindChildren("input_shape"); foreach (RawProto rpChild in rgp) { p.input_shape.Add(BlobShape.FromProto(rpChild)); } p.input_dim = rp.FindArray <int>("input_dim"); if ((strVal = rp.FindValue("force_backward")) != null) { p.force_backward = bool.Parse(strVal); } RawProto rpState = rp.FindChild("state"); if (rpState != null) { p.state = NetState.FromProto(rpState); } if ((strVal = rp.FindValue("debug_info")) != null) { p.debug_info = bool.Parse(strVal); } rgp = rp.FindChildren("layer", "layers"); foreach (RawProto rpChild in rgp) { p.layer.Add(LayerParameter.FromProto(rpChild)); } return(p); }
/// <summary> /// Parse a RawProto into a new instance of the parameter. /// </summary> /// <param name="rp">Specifies the RawProto to parse.</param> /// <returns>A new instance of the parameter is returned.</returns> public static new KernelParameter FromProto(RawProto rp) { KernelParameter p = new KernelParameter(); ((EngineParameter)p).Copy(EngineParameter.FromProto(rp)); p.m_rgPad = rp.FindArray <uint>("pad"); p.m_rgStride = rp.FindArray <uint>("stride"); p.m_rgKernelSize = rp.FindArray <uint>("kernel_size"); p.m_rgDilation = rp.FindArray <uint>("dilation"); p.m_nPadH = (uint?)rp.FindValue("pad_h", typeof(uint)); p.m_nPadW = (uint?)rp.FindValue("pad_w", typeof(uint)); p.m_nStrideH = (uint?)rp.FindValue("stride_h", typeof(uint)); p.m_nStrideW = (uint?)rp.FindValue("stride_w", typeof(uint)); p.m_nKernelH = (uint?)rp.FindValue("kernel_h", typeof(uint)); p.m_nKernelW = (uint?)rp.FindValue("kernel_w", typeof(uint)); return(p); }
/// <summary> /// Parses a RawProto representing a NetStateRule and creates a new instance of a NetStateRule from it. /// </summary> /// <param name="rp">Specifies the RawProto used.</param> /// <returns>The new NeteStateRule instance is returned.</returns> public static NetStateRule FromProto(RawProto rp) { string strVal; NetStateRule p = new NetStateRule(); if ((strVal = rp.FindValue("phase")) != null) { switch (strVal) { case "TEST": p.phase = Phase.TEST; break; case "TRAIN": p.phase = Phase.TRAIN; break; case "RUN": p.phase = Phase.RUN; break; case "NONE": p.phase = Phase.NONE; break; case "ALL": p.phase = Phase.ALL; break; default: throw new Exception("Unknown 'phase' value: " + strVal); } } p.min_level = (int?)rp.FindValue("min_level", typeof(int)); p.max_level = (int?)rp.FindValue("max_level", typeof(int)); p.stage = rp.FindArray <string>("stage"); p.not_stage = rp.FindArray <string>("not_stage"); 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 UnPoolingParameter FromProto(RawProto rp) { UnPoolingParameter p = new UnPoolingParameter(); ((PoolingParameter)p).Copy(PoolingParameter.FromProto(rp)); p.m_rgUnpool = rp.FindArray <uint>("unpool_size"); p.m_nUnPoolH = (uint?)rp.FindValue("unpool_h", typeof(uint)); p.m_nUnPoolW = (uint?)rp.FindValue("unpool_w", typeof(uint)); 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 EltwiseParameter FromProto(RawProto rp) { string strVal; EltwiseParameter p = new EltwiseParameter(); if ((strVal = rp.FindValue("operation")) != null) { switch (strVal) { case "PROD": p.operation = EltwiseOp.PROD; break; case "SUM": p.operation = EltwiseOp.SUM; break; case "MAX": p.operation = EltwiseOp.MAX; break; case "MIN": p.operation = EltwiseOp.MIN; break; case "DIV": p.operation = EltwiseOp.DIV; break; case "SUB": p.operation = EltwiseOp.SUB; break; default: throw new Exception("Unknown 'operation' value: " + strVal); } } p.coeff = rp.FindArray <double>("coeff"); if ((strVal = rp.FindValue("stable_prod_grad")) != null) { p.stable_prod_grad = bool.Parse(strVal); } if ((strVal = rp.FindValue("coeff_blob")) != null) { p.coeff_blob = bool.Parse(strVal); } return(p); }
/// <summary> /// Parses a new BlobProto from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto to parse.</param> /// <returns>A new instance of the BlobProto is returned.</returns> public static BlobProto FromProto(RawProto rp) { BlobProto p = new BlobProto(); RawProto rpShape = rp.FindChild("shape"); if (rpShape != null) { p.shape = BlobShape.FromProto(rpShape); } p.num = (int?)rp.FindValue("num", typeof(int)); p.channels = (int?)rp.FindValue("channels", typeof(int)); p.height = (int?)rp.FindValue("height", typeof(int)); p.width = (int?)rp.FindValue("width", typeof(int)); p.double_data = rp.FindArray <double>("double_data"); p.double_diff = rp.FindArray <double>("double_diff"); p.data = rp.FindArray <float>("data"); p.diff = rp.FindArray <float>("diff"); 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 CropParameter FromProto(RawProto rp) { string strVal; CropParameter p = new CropParameter(); if ((strVal = rp.FindValue("axis")) != null) { p.axis = int.Parse(strVal); } p.offset = rp.FindArray <uint>("offset"); 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 DataLabelMappingParameter FromProto(RawProto rp) { DataLabelMappingParameter p = new DataLabelMappingParameter(true); RawProto rpOption = rp.FindChild("option"); if (rpOption != null) { ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption)); } p.m_rgMapping = LabelMappingCollection.Parse(rp.FindArray <string>("mapping")); 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 DummyDataParameter FromProto(RawProto rp) { DummyDataParameter p = new DummyDataParameter(); RawProtoCollection rgp; rgp = rp.FindChildren("data_filler"); foreach (RawProto child in rgp) { p.data_filler.Add(FillerParameter.FromProto(child)); } rgp = rp.FindChildren("shape"); foreach (RawProto child in rgp) { p.shape.Add(BlobShape.FromProto(child)); } p.num = rp.FindArray <uint>("num"); p.channels = rp.FindArray <uint>("channels"); p.height = rp.FindArray <uint>("height"); p.width = rp.FindArray <uint>("width"); 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 DummyDataParameter FromProto(RawProto rp) { DummyDataParameter p = new DummyDataParameter(); RawProtoCollection rgp; rgp = rp.FindChildren("data_filler"); foreach (RawProto child in rgp) { p.data_filler.Add(FillerParameter.FromProto(child)); } rgp = rp.FindChildren("shape"); foreach (RawProto child in rgp) { p.shape.Add(BlobShape.FromProto(child)); } p.num = rp.FindArray <uint>("num"); p.channels = rp.FindArray <uint>("channels"); p.height = rp.FindArray <uint>("height"); p.width = rp.FindArray <uint>("width"); string strVal; if ((strVal = rp.FindValue("primary_data")) != null) { p.primary_data = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_refill")) != null) { p.force_refill = 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 SliceParameter FromProto(RawProto rp) { string strVal; SliceParameter p = new SliceParameter(); if ((strVal = rp.FindValue("axis")) != null) { p.axis = int.Parse(strVal); } p.slice_point = rp.FindArray <uint>("slice_point"); if ((strVal = rp.FindValue("slice_dim")) != null) { p.slice_dim = uint.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 ConstantParameter FromProto(RawProto rp) { string strVal; ConstantParameter p = new ConstantParameter(); RawProto shape = rp.FindChild("output_shape"); if (shape != null) { p.m_outputShape = BlobShape.FromProto(shape); } p.m_rgF = rp.FindArray <float>("valuef"); strVal = rp.FindValue("binary_data_file"); if (strVal != null) { p.m_strBinaryDataFile = replace(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 TransformationParameter FromProto(RawProto rp) { string strVal; TransformationParameter p = new TransformationParameter(); if ((strVal = rp.FindValue("scale")) != null) { p.scale = double.Parse(strVal); } if ((strVal = rp.FindValue("mirror")) != null) { p.mirror = bool.Parse(strVal); } if ((strVal = rp.FindValue("crop_size")) != null) { p.crop_size = uint.Parse(strVal); } if ((strVal = rp.FindValue("use_image_mean")) != null || (strVal = rp.FindValue("use_imagedb_mean")) != null) { p.use_imagedb_mean = bool.Parse(strVal); } if ((strVal = rp.FindValue("mean_file")) != null) { p.use_imagedb_mean = true; } p.mean_value = rp.FindArray <double>("mean_value"); if ((strVal = rp.FindValue("force_color")) != null) { p.force_color = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_gray")) != null) { p.force_gray = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_positive_range_max")) != null) { p.forced_positive_range_max = double.Parse(strVal); } if ((strVal = rp.FindValue("mean_file")) != null) { p.mean_file = strVal; } if ((strVal = rp.FindValue("color_order")) != null) { if (strVal == COLOR_ORDER.BGR.ToString()) { p.color_order = COLOR_ORDER.BGR; } else { p.color_order = COLOR_ORDER.RGB; } } RawProto rpResize = rp.FindChild("resize_param"); p.resize_param = (rpResize != null) ? ResizeParameter.FromProto(rpResize) : null; RawProto rpNoise = rp.FindChild("noise_param"); p.noise_param = (rpNoise != null) ? NoiseParameter.FromProto(rpNoise) : null; RawProto rpDistort = rp.FindChild("distortion_param"); p.distortion_param = (rpDistort != null) ? DistortionParameter.FromProto(rpDistort) : null; RawProto rpExpand = rp.FindChild("expansion_param"); p.expansion_param = (rpExpand != null) ? ExpansionParameter.FromProto(rpExpand) : null; RawProto rpEmitCon = rp.FindChild("emit_constraint"); p.emit_constraint = (rpEmitCon != null) ? EmitConstraint.FromProto(rpEmitCon) : null; return(p); }
/// <summary> /// Parses a new SolverParameter from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto representing the SolverParameter.</param> /// <returns>The new SolverParameter instance is returned.</returns> public static SolverParameter FromProto(RawProto rp) { string strVal; SolverParameter p = new SolverParameter(); RawProto rpNetParam = rp.FindChild("net_param"); if (rpNetParam != null) { p.net_param = NetParameter.FromProto(rpNetParam); } RawProto rpTrainNetParam = rp.FindChild("train_net_param"); if (rpTrainNetParam != null) { p.train_net_param = NetParameter.FromProto(rpTrainNetParam); } RawProtoCollection rgpTn = rp.FindChildren("test_net_param"); foreach (RawProto rpTest in rgpTn) { p.test_net_param.Add(NetParameter.FromProto(rpTest)); } RawProto rpTrainState = rp.FindChild("train_state"); if (rpTrainState != null) { p.train_state = NetState.FromProto(rpTrainState); } RawProtoCollection rgpNs = rp.FindChildren("test_state"); foreach (RawProto rpNs in rgpNs) { p.test_state.Add(NetState.FromProto(rpNs)); } p.test_iter = rp.FindArray <int>("test_iter"); if ((strVal = rp.FindValue("test_interval")) != null) { p.test_interval = int.Parse(strVal); } if ((strVal = rp.FindValue("test_compute_loss")) != null) { p.test_compute_loss = bool.Parse(strVal); } if ((strVal = rp.FindValue("test_initialization")) != null) { p.test_initialization = bool.Parse(strVal); } if ((strVal = rp.FindValue("base_lr")) != null) { p.base_lr = double.Parse(strVal); } if ((strVal = rp.FindValue("display")) != null) { p.display = int.Parse(strVal); } if ((strVal = rp.FindValue("average_loss")) != null) { p.average_loss = int.Parse(strVal); } if ((strVal = rp.FindValue("max_iter")) != null) { p.max_iter = int.Parse(strVal); } if ((strVal = rp.FindValue("iter_size")) != null) { p.iter_size = int.Parse(strVal); } if ((strVal = rp.FindValue("lr_policy")) != null) { p.lr_policy = strVal; } if ((strVal = rp.FindValue("gamma")) != null) { p.gamma = double.Parse(strVal); } if ((strVal = rp.FindValue("power")) != null) { p.power = double.Parse(strVal); } if ((strVal = rp.FindValue("momentum")) != null) { p.momentum = double.Parse(strVal); } if ((strVal = rp.FindValue("weight_decay")) != null) { p.weight_decay = double.Parse(strVal); } if ((strVal = rp.FindValue("regularization_type")) != null) { p.regularization_type = strVal; } if ((strVal = rp.FindValue("stepsize")) != null) { p.stepsize = int.Parse(strVal); } p.stepvalue = rp.FindArray <int>("stepvalue"); if ((strVal = rp.FindValue("clip_gradients")) != null) { p.clip_gradients = double.Parse(strVal); } if ((strVal = rp.FindValue("snapshot")) != null) { p.snapshot = int.Parse(strVal); } if ((strVal = rp.FindValue("snapshot_prefix")) != null) { p.snapshot_prefix = strVal; } if ((strVal = rp.FindValue("snapshot_diff")) != null) { p.snapshot_diff = bool.Parse(strVal); } if ((strVal = rp.FindValue("snapshot_format")) != null) { switch (strVal) { case "BINARYPROTO": p.snapshot_format = SnapshotFormat.BINARYPROTO; break; case "HDF5": p.snapshot_format = SnapshotFormat.BINARYPROTO; break; default: throw new Exception("Unknown 'snapshot_format' value: " + strVal); } } if ((strVal = rp.FindValue("device_id")) != null) { p.device_id = int.Parse(strVal); } if ((strVal = rp.FindValue("random_seed")) != null) { p.random_seed = long.Parse(strVal); } if ((strVal = rp.FindValue("type")) != null) { string strVal1 = strVal.ToLower(); switch (strVal1) { case "sgd": p.type = SolverType.SGD; break; case "nesterov": p.type = SolverType.NESTEROV; break; case "adagrad": p.type = SolverType.ADAGRAD; break; case "adadelta": p.type = SolverType.ADADELTA; break; case "adam": p.type = SolverType.ADAM; break; case "rmsprop": p.type = SolverType.RMSPROP; break; case "lbgfs": p.type = SolverType.LBFGS; break; default: throw new Exception("Unknown solver 'type' value: " + strVal); } } if ((strVal = rp.FindValue("delta")) != null) { p.delta = double.Parse(strVal); } if ((strVal = rp.FindValue("momentum2")) != null) { p.momentum2 = double.Parse(strVal); } if ((strVal = rp.FindValue("rms_decay")) != null) { p.rms_decay = double.Parse(strVal); } if ((strVal = rp.FindValue("debug_info")) != null) { p.debug_info = bool.Parse(strVal); } if ((strVal = rp.FindValue("lbgfs_corrections")) != null) { p.lbgfs_corrections = int.Parse(strVal); } if ((strVal = rp.FindValue("snapshot_after_train")) != null) { p.snapshot_after_train = bool.Parse(strVal); } if ((strVal = rp.FindValue("custom_trainer")) != null) { p.custom_trainer = strVal; } if ((strVal = rp.FindValue("custom_trainer_properties")) != null) { p.custom_trainer_properties = strVal; } if ((strVal = rp.FindValue("output_average_results")) != null) { p.output_average_results = bool.Parse(strVal); } if ((strVal = rp.FindValue("snapshot_include_weights")) != null) { p.snapshot_include_weights = bool.Parse(strVal); } if ((strVal = rp.FindValue("snapshot_include_state")) != null) { p.snapshot_include_state = bool.Parse(strVal); } return(p); }
/// <summary> /// Parses the parameter from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto to parse.</param> /// <param name="p">Optionally, specifies an instance to load. If <i>null</i>, a new instance is created and loaded.</param> /// <returns>A new instance of the parameter is returned.</returns> public static DataNormalizerParameter FromProto(RawProto rp, DataNormalizerParameter p = null) { string strVal; if (p == null) { p = new DataNormalizerParameter(); } List <string> rgstrStep = rp.FindArray <string>("step"); p.steps = new List <NORMALIZATION_STEP>(); foreach (string strStep in rgstrStep) { p.steps.Add(convertStep(strStep)); } if ((strVal = rp.FindValue("across_data_and_label")) != null) { p.across_data_and_label = bool.Parse(strVal); } p.ignore_channels = rp.FindArray <int>("ignore_ch"); if ((strVal = rp.FindValue("input_min")) != null) { p.input_min = ParseDouble(strVal); } if ((strVal = rp.FindValue("input_max")) != null) { p.input_max = ParseDouble(strVal); } if ((strVal = rp.FindValue("output_min")) != null) { p.output_min = ParseDouble(strVal); } if ((strVal = rp.FindValue("output_max")) != null) { p.output_max = ParseDouble(strVal); } if ((strVal = rp.FindValue("input_mean")) != null) { p.input_mean = ParseDouble(strVal); } else { p.input_mean = null; } if ((strVal = rp.FindValue("input_stdev")) != null) { p.input_stdev = ParseDouble(strVal); } else { p.input_stdev = null; } if ((strVal = rp.FindValue("label_data_channel")) != null) { p.label_data_channel = int.Parse(strVal); } else { p.label_data_channel = null; } 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 TransformationParameter FromProto(RawProto rp) { string strVal; TransformationParameter p = new TransformationParameter(); if ((strVal = rp.FindValue("scale")) != null) { p.scale = ParseDouble(strVal); } if ((strVal = rp.FindValue("scale_operator")) != null) { if (strVal == SCALE_OPERATOR.MUL.ToString()) { p.scale_operator = SCALE_OPERATOR.MUL; } else if (strVal == SCALE_OPERATOR.POW.ToString()) { p.scale_operator = SCALE_OPERATOR.POW; } else { p.scale_operator = SCALE_OPERATOR.NONE; } } else { p.scale_operator = null; } if ((strVal = rp.FindValue("mirror")) != null) { p.mirror = bool.Parse(strVal); } if ((strVal = rp.FindValue("crop_size")) != null) { p.crop_size = uint.Parse(strVal); } if ((strVal = rp.FindValue("use_image_mean")) != null || (strVal = rp.FindValue("use_imagedb_mean")) != null) { p.use_imagedb_mean = bool.Parse(strVal); } if ((strVal = rp.FindValue("mean_file")) != null) { p.use_imagedb_mean = true; } p.mean_value = rp.FindArray <double>("mean_value"); if ((strVal = rp.FindValue("force_color")) != null) { p.force_color = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_gray")) != null) { p.force_gray = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_positive_range_max")) != null) { p.forced_positive_range_max = ParseDouble(strVal); } if ((strVal = rp.FindValue("mean_file")) != null) { p.mean_file = strVal; } if ((strVal = rp.FindValue("color_order")) != null) { if (strVal == COLOR_ORDER.BGR.ToString()) { p.color_order = COLOR_ORDER.BGR; } else { p.color_order = COLOR_ORDER.RGB; } } RawProto rpResize = rp.FindChild("resize_param"); if (rpResize != null) { p.resize_param = ResizeParameter.FromProto(rpResize); } else { p.resize_param = null; } RawProto rpNoise = rp.FindChild("noise_param"); if (rpNoise != null) { p.noise_param = NoiseParameter.FromProto(rpNoise); } else { p.noise_param = null; } RawProto rpDistort = rp.FindChild("distortion_param"); if (rpDistort != null) { p.distortion_param = DistortionParameter.FromProto(rpDistort); } RawProto rpExpand = rp.FindChild("expansion_param"); if (rpExpand != null) { p.expansion_param = ExpansionParameter.FromProto(rpExpand); } else { p.expansion_param = null; } RawProto rpEmitCon = rp.FindChild("emit_constraint"); if (rpEmitCon != null) { p.emit_constraint = EmitConstraint.FromProto(rpEmitCon); } else { p.emit_constraint = null; } RawProto rpMask = rp.FindChild("mask_param"); if (rpMask != null) { p.mask_param = MaskParameter.FromProto(rpMask); } RawProto rpLabelMapping = rp.FindChild("label_mapping"); if (rpLabelMapping != null) { p.label_mapping = DataLabelMappingParameter.FromProto(rpLabelMapping); } 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 PriorBoxParameter FromProto(RawProto rp) { PriorBoxParameter p = new PriorBoxParameter(); string strVal; p.min_size = rp.FindArray <float>("min_size"); p.max_size = rp.FindArray <float>("max_size"); p.aspect_ratio = rp.FindArray <float>("aspect_ratio"); if ((strVal = rp.FindValue("flip")) != null) { p.flip = bool.Parse(strVal); } if ((strVal = rp.FindValue("clip")) != null) { p.clip = bool.Parse(strVal); } p.variance = rp.FindArray <float>("variance"); if ((strVal = rp.FindValue("img_size")) != null) { p.img_size = uint.Parse(strVal); } else { if ((strVal = rp.FindValue("img_h")) != null) { p.img_h = uint.Parse(strVal); } if ((strVal = rp.FindValue("img_w")) != null) { p.img_w = uint.Parse(strVal); } } if ((strVal = rp.FindValue("step")) != null) { p.step = float.Parse(strVal); } else { if ((strVal = rp.FindValue("step_h")) != null) { p.step_h = float.Parse(strVal); } if ((strVal = rp.FindValue("step_w")) != null) { p.step_w = float.Parse(strVal); } } if ((strVal = rp.FindValue("offset")) != null) { p.offset = 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 TransformationParameter FromProto(RawProto rp) { string strVal; TransformationParameter p = new TransformationParameter(); if ((strVal = rp.FindValue("scale")) != null) { p.scale = double.Parse(strVal); } if ((strVal = rp.FindValue("mirror")) != null) { p.mirror = bool.Parse(strVal); } if ((strVal = rp.FindValue("crop_size")) != null) { p.crop_size = uint.Parse(strVal); } if ((strVal = rp.FindValue("use_image_mean")) != null || (strVal = rp.FindValue("use_imagedb_mean")) != null) { p.use_imagedb_mean = bool.Parse(strVal); } if ((strVal = rp.FindValue("mean_file")) != null) { p.use_imagedb_mean = true; } p.mean_value = rp.FindArray <double>("mean_value"); if ((strVal = rp.FindValue("force_color")) != null) { p.force_color = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_gray")) != null) { p.force_gray = bool.Parse(strVal); } if ((strVal = rp.FindValue("force_positive_range_max")) != null) { p.forced_positive_range_max = double.Parse(strVal); } if ((strVal = rp.FindValue("mean_file")) != null) { p.mean_file = strVal; } if ((strVal = rp.FindValue("color_order")) != null) { if (strVal == COLOR_ORDER.BGR.ToString()) { p.color_order = COLOR_ORDER.BGR; } else { p.color_order = COLOR_ORDER.RGB; } } return(p); }
/// <summary> /// Parse a new BlobShape from a RawProto. /// </summary> /// <param name="rp">Specifies the RawProto containing a representation of the BlobShape.</param> /// <returns>A new instance of the BlobShape is returned.</returns> public static BlobShape FromProto(RawProto rp) { return(new BlobShape(rp.FindArray <int>("dim"))); }