Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
        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);
            }

        }
Esempio n. 6
0
        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);
            }
        }