コード例 #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;
            }
        }
コード例 #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);
 }
コード例 #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);
        }
コード例 #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;
            }
        }
コード例 #5
0
ファイル: AsciiDumper.cs プロジェクト: zhimingz/kaggle_criteo
        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);
            }

        }
コード例 #6
0
ファイル: AsciiDumper.cs プロジェクト: zhimingz/kaggle_criteo
        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);
            }
        }