public ImageTrainDataSet BalanceData() { Random rand = new Random(); ImageTrainDataSet ret = new ImageTrainDataSet(); ret.AddRange(this); TrainDataInfo[] infos = this.GetInfo(this.GetNumOutput()); int maxCount = infos.Max(x => x.count); for (int i = 0; i < infos.Length; i++) { for (int j = infos[i].count; j < maxCount; j++) { //Random _self for that index while (true) { int index = rand.Next(this.Count); if (this[index].labelIndex == i) { ret.Add(this[index].Clone()); break; } } } } return(ret); }
public ImageTrainDataSet SplitTestData(int num) { Random rand = new Random(); //List<ImageTrainData> ret = _self.GetRange(0, num); //_self.RemoveRange(0, num); int numOutput = this.GetNumOutput(); ImageTrainDataSet ret = new ImageTrainDataSet(); while (ret.Count() < num) { for (int i = 0; i < numOutput; i++) { while (true) { int index = rand.Next(this.Count); if (this[index].labelIndex == i) { ret.Add(this[index]); this.RemoveAt(index); break; } } } } return(ret); }
public static ImageTrainDataSet GetAllTrainImageData(String folder, String[] subFolders, String imageFilter = "*.png", String imageFilterOut = "mask.png") { ImageTrainDataSet ret = new ImageTrainDataSet(); for (int i = 0; i < subFolders.Length; i++) { String folderName = folder + @"\" + subFolders[i]; ImageFileData[] images = GetImagesFromDir(folderName, imageFilter, imageFilterOut); foreach (ImageFileData img in images) { ret.Add( new ImageTrainData() { label = subFolders[i], labelIndex = i, fileName = img.fileName, } ); } } return(ret); }