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); }
public static string Serialize(ManagedCNN network) { var model = Convert(network); var output = JsonConvert.SerializeObject(model); return(output); }
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); }