/// <summary> /// Saves the current ANN settings to an OpenCV ANN file which can be loaded /// later for initialization, training and use later. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveAnnButton_Click(object sender, RoutedEventArgs e) { // Configure save file dialog box Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "NeuralNetwork"; // Default file name dlg.DefaultExt = ".xml"; // Default file extension dlg.Filter = "XML documents (.xml)|*.xml"; // Filter files by extension dlg.Title = "Where to save your new Neural Network?"; // Show save file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { // Save document string filepath = dlg.FileName; Console.WriteLine("Saving neural network to " + filepath); Hashtable hashtable = new Hashtable(); hashtable.Add("identity", ANN.ActivationFunction.Identity); hashtable.Add("sigmoid", ANN.ActivationFunction.Sigmoid); hashtable.Add("gaussian", ANN.ActivationFunction.Gaussian); hashtable.Add("Identity", ANN.ActivationFunction.Identity); hashtable.Add("Sigmoid", ANN.ActivationFunction.Sigmoid); hashtable.Add("Gaussian", ANN.ActivationFunction.Gaussian); ANN.ActivationFunction actFunc = ANN.ActivationFunction.Sigmoid; if (hashtable.ContainsKey(AnnActivationFunction.Text)) { // TODO: (Ko) Use combobox key and not it's values (important for translation) Console.WriteLine("Using activation function: " + hashtable[AnnActivationFunction.Text]); actFunc = (ANN.ActivationFunction)hashtable[AnnActivationFunction.Text]; } _Klu.CreateAndSaveAnn(_ANN.NumNeuronsPerLayer, actFunc, Convert.ToDouble(AnnAlpha.Text), Convert.ToDouble(AnnBeta.Text), filepath); } }
/// <summary> /// Create a neural network using the given parameters and saves it as a reusable /// OpenCV XML file to the desired "filepath". /// </summary> /// <param name="numNeuronsPerLayer"></param> /// <param name="activationFunction"></param> /// <param name="filepath"></param> /// <returns>true if successful; otherwise false</returns> public bool CreateAndSaveAnn(int[] numNeuronsPerLayer, ANN.ActivationFunction activationFunction, double alpha, double beta, string filepath) { int res = klu_createAndSaveAnn(numNeuronsPerLayer, numNeuronsPerLayer.Count(), (int)activationFunction, alpha, beta, filepath); return(res == 1); }