private void InitTrainButton_Click(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(selected_file) && DataSetNameField.Text != "Enter DataSet Name") { Console.WriteLine("Processing Images..."); string[] files = Directory.GetFiles(selected_file); Objects.DataSet new_dataset = new Objects.DataSet() { NumImages = files.Length, Trained = false, NumImagesNotPlastic = files.Length, NumImagesPlastic = files.Length, Name = DataSetNameField.Text }; Console.WriteLine("Images Added To Set..."); dataset_db.DataSets.Add(new_dataset); dataset_db.SaveChanges(); Console.WriteLine("Images Copying To Local Folder..."); ImageHelper.addImagesToSet(selected_file, new_dataset); MessageBox.Show("DataSet created"); this.Close(); } else { if (string.IsNullOrWhiteSpace(selected_file) && DataSetNameField.Text == "Enter DataSet Name") { MessageBox.Show("Please select a folder and a name for the DataSet"); } else if (string.IsNullOrWhiteSpace(selected_file)) { MessageBox.Show("Please select a folder"); } else { MessageBox.Show("Please select a name"); } } } catch (Exception ex) { Console.Write(ex.Message); } finally { this.Close(); } }
private void AddAlgorithmBtn_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(AlgorithmInputField.Text)) { db_context.Algorithms.Add(new Algorithm() { Name = AlgorithmInputField.Text }); db_context.SaveChanges(); Console.WriteLine("Algorithm added"); AlgorithmInputField.Clear(); refresh_algorithms_view(); } }
/* * This will add images specified in a directory * to a given DataSet in_dataset. Once the images * have compelted adding, it will copy the files * to a local file * * IN: * - file_path (Type: string): the path of the file directory * that contains the images to be added to the set * - in_dataset (Type: DataSet): the dataset to which the * images has to be added. */ public static void addImagesToSet(string file_path, DataSet in_dataset) { try { string[] fileEntries = Directory.GetFiles(file_path); List <Image> new_list = new List <Image>(); foreach (string fileName in fileEntries) { FileInfo file = new FileInfo(fileName); if (file.Extension != ".jpg") { continue; } new_list.Add(new Image { FileLocation = file.FullName, ImageSize = file.Length / 6, DataSetId = in_dataset.Id, IsPlastic = false }); } using (var db = new PlasticDBContext()) { in_dataset.Images = new_list; db.Images.AddRange(new_list); db.SaveChanges(); } copyToLocal(in_dataset); } catch (Exception ex) { Console.WriteLine(ex.Message); } }