/// <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 HDF5DataParameter FromProto(RawProto rp, HDF5DataParameter p = null) { string strVal; if (p == null) p = new HDF5DataParameter(); if ((strVal = rp.FindValue("source")) != null) p.source = strVal.Trim('\"'); if ((strVal = rp.FindValue("batch_size")) != null) p.batch_size = uint.Parse(strVal); if ((strVal = rp.FindValue("shuffle")) != null) p.shuffle = bool.Parse(strVal); p.m_rgExpectedTopShapes = new List<BlobShape>(); RawProtoCollection colExpectedTopShapes = rp.FindChildren("expected_top_shape"); foreach (RawProto rp1 in colExpectedTopShapes) { p.m_rgExpectedTopShapes.Add(BlobShape.FromProto(rp1)); } 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> /// <returns>A new instance of the parameter is returned.</returns> public static ParameterParameter FromProto(RawProto rp) { ParameterParameter p = new ParameterParameter(); RawProto rp1 = rp.FindChild("shape"); if (rp1 != null) { p.shape = BlobShape.FromProto(rp1); } 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 InputParameter FromProto(RawProto rp) { InputParameter p = new InputParameter(); RawProtoCollection col = rp.FindChildren("shape"); foreach (RawProto rp1 in col) { BlobShape b = BlobShape.FromProto(rp1); p.m_rgShape.Add(b); } 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> /// 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 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 ReshapeParameter FromProto(RawProto rp) { string strVal; ReshapeParameter p = new ReshapeParameter(); RawProto rpShape = rp.FindChild("shape"); if (rpShape != null) { p.shape = BlobShape.FromProto(rpShape); } if ((strVal = rp.FindValue("axis")) != null) { p.axis = int.Parse(strVal); } if ((strVal = rp.FindValue("num_axes")) != null) { p.num_axes = int.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 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 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); }