Пример #1
0
        public override object Load(XmlNode node)
        {
            var result = (NeuralNetwork)Activator.CreateInstance(Type);

            var loss = XmlStorage.GetObjectValue <LossFunction>(node, "LossFunction");

            result.UseLossFunction(loss);

            var optimizer = XmlStorage.GetObjectValue <IOptimizer>(node, "Optimizer");

            result.UseOptimizer(optimizer);

            var regularizer = XmlStorage.GetObjectValue <IRegularizer>(node, "Regularizer");

            result.UseRegularizer(regularizer);

            var nodeList = node.SelectSingleNode("Layers").ChildNodes;

            foreach (XmlNode n in nodeList)
            {
                var layer = XmlStorage.LoadFromNode <ILayer>(n);
                result.AddLayer(layer);
            }

            return(result);
        }
Пример #2
0
        public override object Load(XmlNode node)
        {
            if (node == null)
            {
                return(null);
            }

            if (!node.HasChildNodes)
            {
                return(null);
            }

            var unitCount = XmlStorage.GetIntValue(node, "UnitCount");
            var result    = (FullLayer)Activator.CreateInstance(typeof(FullLayer), unitCount);

            var weights = XmlStorage.GetObjectValue <TensorOld>(node, "Weights");

            if (weights != null)
            {
                result.SetWeights(weights);
            }

            var bias = XmlStorage.GetObjectValue <TensorOld>(node, "Bias");

            if (bias != null)
            {
                result.SetBias(bias);
            }

            return(result);
        }
Пример #3
0
        public override object Load(XmlNode node)
        {
            var count         = XmlStorage.GetIntValue(node, "FilterCount");
            var rows          = XmlStorage.GetIntValue(node, "FilterRows");
            var columns       = XmlStorage.GetIntValue(node, "FilterColumns");
            var rowStride     = XmlStorage.GetIntValue(node, "RowStride");
            var columnStride  = XmlStorage.GetIntValue(node, "ColumnStride");
            var rowPadding    = XmlStorage.GetIntValue(node, "RowPadding");
            var columnPadding = XmlStorage.GetIntValue(node, "ColumnPadding");
            var paddingValue  = XmlStorage.GetDoubleValue(node, "PaddingValue");

            var result = (ConvLayer)Activator.CreateInstance(typeof(ConvLayer), count, rows, columns, rowStride, columnStride, rowPadding, columnPadding);

            result.PaddingValue = paddingValue;

            var filters = XmlStorage.GetObjectValue <TensorOld>(node, "Filters");

            if (filters != null)
            {
                result.SetFilters(filters);
            }

            var bias = XmlStorage.GetObjectValue <TensorOld>(node, "Bias");

            if (bias != null)
            {
                result.SetBias(bias);
            }

            return(result);
        }
Пример #4
0
        public override object Load(XmlNode node)
        {
            var rows         = XmlStorage.GetIntValue(node, "Rows");
            var columns      = XmlStorage.GetIntValue(node, "Columns");
            var rowStride    = XmlStorage.GetIntValue(node, "RowStride");
            var columnStride = XmlStorage.GetIntValue(node, "ColumnStride");

            return(Activator.CreateInstance(typeof(MaxPooling), rows, columns, rowStride, columnStride));
        }
Пример #5
0
        internal static XmlElement SavePoolingLayer(string type, XmlDocument doc, PoolingLayer layer)
        {
            var el = doc.CreateElement(type);

            XmlStorage.AddChild(el, "Rows", layer.Rows.ToString());
            XmlStorage.AddChild(el, "Columns", layer.Columns.ToString());
            XmlStorage.AddChild(el, "RowStride", layer.RowStride.ToString());
            XmlStorage.AddChild(el, "ColumnStride", layer.ColumnStride.ToString());

            return(el);
        }
Пример #6
0
        public override XmlElement Save(XmlDocument doc, object o)
        {
            if (!(o is FullLayer layer))
            {
                throw new Exception("layer must be FullLayer!");
            }

            var el = GetRootElement(doc);

            XmlStorage.AddChild(el, "UnitCount", layer.UnitCount);
            XmlStorage.AddObjectChild(el, "Weights", layer.Weights);
            XmlStorage.AddObjectChild(el, "Bias", layer.Bias);

            return(el);
        }
Пример #7
0
        public override object Load(XmlNode node)
        {
            if (node == null)
            {
                return(null);
            }

            if (!node.HasChildNodes)
            {
                return(null);
            }

            var shape  = XmlStorage.GetIntArray(node, "Shape");
            var values = XmlStorage.GetDoubleArray(node, "Values");

            return(Activator.CreateInstance(typeof(TensorOld), values, shape));
        }
Пример #8
0
        public override XmlElement Save(XmlDocument doc, object o)
        {
            var el = doc.CreateElement("Tensor");

            if (o == null)
            {
                return(el);
            }

            if (!(o is TensorOld tensor))
            {
                throw new Exception("layer must be Tensor!");
            }

            XmlStorage.AddArrayChild(el, "Shape", tensor.shape);
            XmlStorage.AddArrayChild(el, "Values", tensor.GetRawValues());

            return(el);
        }
Пример #9
0
        public override XmlElement Save(XmlDocument doc, object o)
        {
            if (!(o is NeuralNetwork nn))
            {
                throw new Exception("object must be NeuralNetwork");
            }

            var el = GetRootElement(doc);

            XmlStorage.AddObjectChild(el, "LossFunction", nn.LossFunction);
            XmlStorage.AddObjectChild(el, "Optimizer", nn.Optimizer);
            XmlStorage.AddObjectChild(el, "Regularizer", nn.Regularizer);

            var layers = doc.CreateElement("Layers");

            foreach (var item in nn.TrainingLayers)
            {
                XmlStorage.AddObjectChild(layers, item);
            }
            XmlStorage.AddChild(el, layers);

            return(el);
        }
Пример #10
0
        public override XmlElement Save(XmlDocument doc, object o)
        {
            if (!(o is ConvLayer layer))
            {
                throw new Exception("layer must be ConvLayer!");
            }

            var el = GetRootElement(doc);

            XmlStorage.AddChild(el, "FilterCount", layer.FilterCount.ToString());
            XmlStorage.AddChild(el, "FilterRows", layer.FilterRows.ToString());
            XmlStorage.AddChild(el, "FilterColumns", layer.FilterColumns.ToString());
            XmlStorage.AddChild(el, "RowStride", layer.RowStride.ToString());
            XmlStorage.AddChild(el, "ColumnStride", layer.ColumnStride.ToString());
            XmlStorage.AddChild(el, "RowPadding", layer.RowPadding.ToString());
            XmlStorage.AddChild(el, "ColumnPadding", layer.ColumnPadding.ToString());
            XmlStorage.AddChild(el, "PaddingValue", layer.PaddingValue.ToString());

            XmlStorage.AddObjectChild(el, "Filters", layer.Filters);
            XmlStorage.AddObjectChild(el, "Bias", layer.Bias);

            return(el);
        }