/// <summary> /// Load the parameters from the string. /// <remarks>This should get called from load(). /// The format is binary and not necessarily fit for human consumption.</remarks> /// </summary> public void PLoad(BinaryReader reader) { string key, value; bool ok = false; string s; while (reader.BaseStream.Position < reader.BaseStream.Length) { //s = reader.ReadLine(); // to check me! BinIO.string_read(reader, out s); string[] parts = s.Trim().Split('='); if (parts.Length != 2) { break; } key = parts[0]; value = parts[1]; if (String.Equals(key, "END_OF_PARAMETERS", StringComparison.InvariantCulture)) { ok = true; break; } _params[key] = value; } if (!ok) { throw new Exception("PLoad: parameters not properly terminated in save file"); } }
/// <summary> /// Load network from new format /// </summary> /// <param name="filepath">full file path<</param> public override void Load(string filepath) { FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(stream); try { string s; BinIO.string_read(reader, out s); if (s == "<object>") { BinIO.string_read(reader, out s); if (s != this.Name && s != this.GetType().Name) { throw new Exception("LenetClassifier: incorrect file format"); } this.Load(reader); BinIO.string_read(reader, out s); if (s != "</object>") { throw new Exception("Expected string: </object>"); } } else { throw new Exception("Expected string: <object>"); } } finally { reader.Close(); stream.Close(); } }
public virtual void Load(BinaryReader reader) { // before doing anything else, clear all the // persistent variables to their default state foreach (string wname in _wrappers_dict.Keys) { _wrappers_dict[wname].Clear(); } BinIO.magic_read(reader, Name); this.PLoad(reader); string s; BinIO.string_read(reader, out s); if (s != "<component>") { throw new Exception("Expected string: <component>"); } while (true) { // read tag BinIO.string_read(reader, out s); if (s == "</component>") { break; } if (s != "<item>") { throw new Exception("Expected string: <item>"); } // read wrapper name BinIO.string_read(reader, out s); if (!_wrappers_dict.ContainsKey(s)) { throw new Exception(String.Format("Wrapper name '{0}' is not persisted", s)); } // read wrapper data if (ComponentIO.level == 2) { Global.Debugf("info", "{0," + (ComponentIO.level) + "}loading {1}", "", s); } _wrappers_dict[s].Load(reader); // read tag BinIO.string_read(reader, out s); if (s != "</item>") { throw new Exception("Expected string: </item>"); } } this.ReImport(); }
public override void Load(BinaryReader reader) { string s; BinIO.string_read(reader, out s); if (s == "<object>") { // load lenet arguments int nclasses; BinIO.scalar_read(reader, out nclasses); lenetWrap.Classes = new int[nclasses]; for (int i = 0; i < nclasses; i++) { BinIO.scalar_read(reader, out lenetWrap.Classes[i]); } byte boolval; BinIO.scalar_read(reader, out boolval); lenetWrap.TanhSigmoid = Convert.ToBoolean(boolval); BinIO.scalar_read(reader, out boolval); lenetWrap.NetNorm = Convert.ToBoolean(boolval); BinIO.scalar_read(reader, out boolval); lenetWrap.AsciiTarget = Convert.ToBoolean(boolval); // load Narray from stream BinIO.narray_read(reader, lenetparam); double[] dbuffer = lenetparam.To1DArray(); Global.Debugf("info", "loading " + Name + ".."); // create lenet if (lenetWrap.IsEmpty) { lenetWrap.CreateLenet(lenetWrap.Classes.Length, lenetWrap.Classes, lenetWrap.TanhSigmoid, lenetWrap.NetNorm, lenetWrap.AsciiTarget); } // send loaded buffer to created lenet lenetWrap.LoadNetworkFromBuffer(dbuffer, dbuffer.Length); BinIO.string_read(reader, out s); if (s != "</object>") { throw new Exception("Expected string: </object>"); } } }
public static IComponent load_component(BinaryReader reader) { IComponent result = null; string s; BinIO.string_read(reader, out s); Global.Debugf("iodetail", "{0}[got {1}]", level, s); if (s == "<object>") { level++; BinIO.string_read(reader, out s); if (level <= 2) { Global.Debugf("info", "{0," + (level - 1) + "}loading component {1}", "", s); } Global.Debugf("iodetail", "{0}[constructing {1}]", level, s); result = ComponentCreator.MakeComponent(s); result.Load(reader); BinIO.string_read(reader, out s); if (s != "</object>") { throw new Exception("Expected string: </object>"); } level--; } else if (s.StartsWith("OBJ:")) { s = s.Substring(4); level++; Global.Debugf("iodetail", "{0}[constructing {1}]", level, s); result = ComponentCreator.MakeComponent(s); result.Load(reader); BinIO.string_read(reader, out s); if (s != "OBJ:END") { throw new Exception("Expected string: </object>"); } level--; } Global.Debugf("iodetail", "{0}[done]", level); return(result); }