예제 #1
0
        public static ManagedCNN DeserializeCNN(string json)
        {
            var model = JsonConvert.DeserializeObject <ManagedCNNJSON>(json);

            var network = new ManagedCNN();

            foreach (var layer in model.Layers)
            {
                if (layer.Type == (int)LayerTypes.Input)
                {
                    network.Layers.Add(new ManagedLayer());
                }

                if (layer.Type == (int)LayerTypes.Convolution)
                {
                    network.Layers.Add(new ManagedLayer(layer.OutputMaps, layer.KernelSize));

                    var index = network.Layers.Count;

                    network.Layers[index - 1].FeatureMap = Set(layer.FeatureMap);
                    network.Layers[index - 1].Bias       = Set(layer.Bias, false);
                }

                if (layer.Type == (int)LayerTypes.Subsampling)
                {
                    network.Layers.Add(new ManagedLayer(layer.Scale));
                }
            }

            network.Weights = Set(model.Weights);
            network.Bias    = Set(model.Bias, true);

            return(network);
        }
예제 #2
0
        public static string Serialize(ManagedCNN network)
        {
            var model = Convert(network);

            var output = JsonConvert.SerializeObject(model);

            return(output);
        }
예제 #3
0
        public static ManagedCNNJSON Convert(ManagedCNN network)
        {
            var model = new ManagedCNNJSON
            {
                Layers  = new List <ManagedLayerJSON>(),
                Weights = Convert2D(network.Weights),
                Bias    = Convert1D(network.Bias)
            };

            foreach (var layer in network.Layers)
            {
                model.Layers.Add(Convert(layer));
            }

            return(model);
        }