public static void DeserializeLayer(XElement layerElement, Layer layer, params SerializationOptions[] options) { if (layer.HasWeights) { var weightsElement = layerElement.Element("Weights"); if (weightsElement == null) { throw new Exception("Weights not found for layer : " + layer.Id); } var weightArray = layer.GetArray(ArrayName.Weights); var newData = weightsElement.Value.Split('\n').Select(x => float.Parse(x, CultureInfo.InvariantCulture)).ToArray(); if (newData.Length != weightArray.CPUArray.Length) { throw new Exception("Size of weight arrays dont match"); } weightArray.CPUArray = newData; var biasWeightElement = layerElement.Element("BiasWeights"); if (biasWeightElement == null) { throw new Exception("BiasWeights not found for layer : " + layer.Id); } var biasArray = layer.GetArray(ArrayName.BiasWeights); newData = biasWeightElement.Value.Split('\n').Select(x => float.Parse(x, CultureInfo.InvariantCulture)).ToArray(); if (newData.Length != biasArray.CPUArray.Length) { throw new Exception("Size of weight arrays dont match"); } biasArray.CPUArray = newData; } }
public static void SerializeLayer(XElement parent, Layer layer) { var layerElement = new XElement("Layer"); layerElement.AddElement("Id", layer.Id); layerElement.AddElement("Size", layer.Size.ToString()); if (layer.HasWeights) { var weights = layer.GetArray(ArrayName.Weights); var biasWeights = layer.GetArray(ArrayName.BiasWeights); weights.CopyToHost(); biasWeights.CopyToHost(); layerElement.AddElement("Weights", SerializeArrayValues(weights)); layerElement.AddElement("BiasWeights", SerializeArrayValues(biasWeights)); } parent.Add(layerElement); }
public static void SerializeLayer(XElement parent, Layer layer) { var layerElement = new XElement("Layer"); layerElement.AddElement("Id", layer.Id); layerElement.AddElement("Size", layer.Size.ToString()); if (layer.HasWeights) { var weights = layer.GetArray(ArrayName.Weights); var biasWeights = layer.GetArray(ArrayName.BiasWeights); weights.CopyToHost(); biasWeights.CopyToHost(); layerElement.AddElement("Weights", SerializeArrayValues(weights)); layerElement.AddElement("BiasWeights", SerializeArrayValues(biasWeights)); } parent.Add(layerElement); }
public static void DeserializeLayer(XElement layerElement, Layer layer, params SerializationOptions[] options) { if (layer.HasWeights) { var weightsElement = layerElement.Element("Weights"); if (weightsElement == null) throw new Exception("Weights not found for layer : " + layer.Id); var weightArray = layer.GetArray(ArrayName.Weights); var newData = weightsElement.Value.Split('\n').Select(x => float.Parse(x, CultureInfo.InvariantCulture)).ToArray(); if (newData.Length != weightArray.CPUArray.Length) throw new Exception("Size of weight arrays dont match"); weightArray.CPUArray = newData; var biasWeightElement = layerElement.Element("BiasWeights"); if (biasWeightElement == null) throw new Exception("BiasWeights not found for layer : " + layer.Id); var biasArray = layer.GetArray(ArrayName.BiasWeights); newData = biasWeightElement.Value.Split('\n').Select(x => float.Parse(x, CultureInfo.InvariantCulture)).ToArray(); if (newData.Length != biasArray.CPUArray.Length) throw new Exception("Size of weight arrays dont match"); biasArray.CPUArray = newData; } }
public void DumpArray(Layer layer, ArrayName name, string filePrefix, string dir) { var arr = layer.GetArray(name); if (arr != null) { var txt = arr.GetTxt(); var fileName = filePrefix + "_" + name.ToString() + ".txt"; var path = Path.Combine(dir, fileName); File.WriteAllText(path, txt); } }
public void DumpArray(Layer layer, ArrayName name, string filePrefix, string dir) { var arr = layer.GetArray(name); if (arr != null) { var txt = arr.GetTxt(); var fileName = filePrefix + "_" + name.ToString() + ".txt"; var path = Path.Combine(dir, fileName); File.WriteAllText(path, txt); } }