//private void readFile() //{ // string sourceDirectory = filePath; // //@"C:\Projects\leafsnap-dataset\leafsnap-dataset~\dataset\images\field"; // IEnumerable<String> Files = Directory.EnumerateFiles(sourceDirectory, "*.jpg", SearchOption.AllDirectories); // List<String> eachLeafImageFolder = Directory.GetDirectories(sourceDirectory).Take(10).ToList(); // int count = 0; // int totalCount = eachLeafImageFolder.Count; // foreach (String leafImage in eachLeafImageFolder) // { // count++; // ImageCategory category = new ImageCategory(); // String plantCategoryName = new DirectoryInfo(leafImage).Name; // List<String> eachLeafSpecies = Directory.GetFiles(leafImage, "*.*", SearchOption.AllDirectories).ToList(); // category.leafCategory = plantCategoryName; // category.listOfImages = eachLeafSpecies; // computeNumberOfTrainingDataSet(category); // Console.WriteLine("{0} category of {1} containing {2} leaves", count, totalCount, eachLeafSpecies.Count); // } //} private void computeNumberOfTrainingDataSet(ImageCategory LeafType) { List <String> trainingDataSet = new List <String>(); List <String> queryDataSet = new List <String>(); List <String> eachLeafSpecises = LeafType.listOfImages; int totalImages = eachLeafSpecises.Count; double trainingRatio = 0.8; int training = (int)Math.Ceiling(trainingRatio * totalImages); //Training model for (int i = 0; i < training; i++) { trainingDataSet.Add(eachLeafSpecises[i]); } //Ratio of query model. for (int j = training; j < eachLeafSpecises.Count; j++) { queryDataSet.Add(eachLeafSpecises[j]); } ImageCategory newImageTrainingSet = new ImageCategory(); newImageTrainingSet.listOfImages = trainingDataSet; newImageTrainingSet.leafCategory = LeafType.leafCategory; trainingModel.Add(newImageTrainingSet); ImageCategory newImageQueryDataSet = new ImageCategory(); newImageQueryDataSet.listOfImages = queryDataSet; newImageQueryDataSet.leafCategory = LeafType.leafCategory; queryModel.Add(newImageQueryDataSet); }
private void readFile() { string sourceDirectory = @"C:\Users\Funapp\Desktop\Capstone Project\leaf_dataset\leafsnap-dataset\subdataset"; var Files = Directory.EnumerateFiles(sourceDirectory, "*.jpg", SearchOption.AllDirectories); List <String> eachLeafImageFolder = Directory.GetDirectories(sourceDirectory).ToList(); foreach (String leafImage in eachLeafImageFolder) { ImageCategory category = new ImageCategory(); String plantCategoryName = new DirectoryInfo(leafImage).Name; List <String> eachLeafSpecies = Directory.GetFiles(leafImage, "*.*", SearchOption.AllDirectories).ToList(); category.leafCategory = plantCategoryName; category.listOfImages = eachLeafSpecies; computeNumberOfTrainingDataSet(category); } }
void ITrainModel.ReadFileSystem() { List <String> eachLeafImageFolder = this.eachLeafImageFolder; string sourceDirectory = this.filePath; int count = 0; int totalCount = eachLeafImageFolder.Count; foreach (String leafImage in eachLeafImageFolder) { count++; ImageCategory category = new ImageCategory(); String plantCategoryName = new DirectoryInfo(leafImage).Name; List <String> eachLeafSpecies = Directory.GetFiles(leafImage, "*.*", SearchOption.AllDirectories).ToList(); category.leafCategory = plantCategoryName; category.listOfImages = eachLeafSpecies; computeNumberOfTrainingDataSet(category); Console.WriteLine("{0} category of {1} containing {2} leaves", count, totalCount, eachLeafSpecies.Count); } }
void ITrainModel.ReadFileSystem() { List <String> eachLeafImageFolder = this.eachLeafImageFolder; string sourceDirectory = this.filePath; //@"C:\Projects\leafsnap-dataset\leafsnap-dataset~\dataset\images\field"; //IEnumerable<String> Files = Directory.EnumerateFiles(sourceDirectory, "*.jpg", SearchOption.AllDirectories); //List<String> eachLeafImageFolder = Directory.GetDirectories(sourceDirectory).ToList().GetRange(0,12); int count = 0; int totalCount = eachLeafImageFolder.Count; foreach (String leafImage in eachLeafImageFolder) { count++; ImageCategory category = new ImageCategory(); String plantCategoryName = new DirectoryInfo(leafImage).Name; List <String> eachLeafSpecies = Directory.GetFiles(leafImage, "*.*", SearchOption.AllDirectories).ToList(); category.leafCategory = plantCategoryName; category.listOfImages = eachLeafSpecies; computeNumberOfTrainingDataSet(category); Console.WriteLine("{0} category of {1} containing {2} leaves", count, totalCount, eachLeafSpecies.Count); } }