public void Load(string file) { string json = File.ReadAllText(file); NetworkMemory memory = JsonConvert.DeserializeObject <NetworkMemory>(json); Sizes = memory.Sizes; NumberOfLayer = memory.Sizes.Length; Biases = memory.Biases.Select(b => new Matrix(b)).ToArray(); Weights = memory.Weights.Select(w => new Matrix(w)).ToArray(); }
/// <summary> /// Save wieghts and biases within a file /// </summary> /// <param name="file">path to the file</param> public void Save(string file) { NetworkMemory memory = new NetworkMemory { Biases = Biases.Select(b => b.mat).ToArray(), Weights = Weights.Select(b => b.mat).ToArray(), Sizes = Sizes }; JsonSerializer serializer = new JsonSerializer(); using (StreamWriter sw = new StreamWriter(file)) using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, memory); } }