public void SaveData(string fileName) { CNN_Data cNN_Data = new CNN_Data(); for (int i = 0; i < Layers.Length; i++) { switch (Layers[i].LayerType) { case LayerType.INPUT: break; case LayerType.CONVOLUTIONAL: cNN_Data.Kernels.Add((layers[i] as ConvLayer).Kernels); cNN_Data.Ker_Biases.Add((layers[i] as ConvLayer).Biases); break; case LayerType.MAXPOOLING: break; case LayerType.FULLY_CONNECTED: for (int j = 0; j < (layers[i] as FC_Network).Layers.Length; j++) { cNN_Data.Weights.Add((layers[i] as FC_Network).Layers[j].Weights); cNN_Data.Biases.Add((layers[i] as FC_Network).Layers[j].Biases); } break; default: break; } } cNN_Data.Descriptions = descriptions.ToList(); int fileCount = Directory.GetFiles(saved_network_path, "*.json").Length; if (string.IsNullOrEmpty(fileName)) { fileName = string.Format("network{0}.json", fileCount); } string fullPath = Path.Combine(saved_network_path, fileName); JsonFileController.WriteToJsonFile(fullPath, cNN_Data); }
public void LoadData(string fileName) { int convLayCount = 0; CNN_Data cNN_Data = JsonFileController.ReadDataFromJsonFile <CNN_Data>(Path.Combine(saved_network_path, fileName)); descriptions = cNN_Data.Descriptions.ToArray(); layers = new Layer[descriptions.Length]; for (int i = 0; i < descriptions.Length; i++) { NewLayer(descriptions[i]); switch (descriptions[i].layerType) { case LayerType.INPUT: break; case LayerType.CONVOLUTIONAL: (layers[i] as ConvLayer).Kernels = cNN_Data.Kernels[convLayCount]; (layers[i] as ConvLayer).Biases = cNN_Data.Ker_Biases[convLayCount]; convLayCount++; break; case LayerType.MAXPOOLING: break; case LayerType.FULLY_CONNECTED: for (int j = 0; j < (layers[i] as FC_Network).Layers.Length; j++) { (layers[i] as FC_Network).Layers[j].Weights = cNN_Data.Weights[j]; (layers[i] as FC_Network).Layers[j].Biases = cNN_Data.Biases[j]; } break; default: throw new UndefinedLayerException("This is not a recognizeable layer!!!"); } } }