Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private void loadTrainDataToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     trainData = FeatureDetector.GetAllTrainImageData(dataPath, configure.trainFolders);
     trainData = trainData.BalanceData();
     trainData.Shuffle();
     testData = trainData.SplitTestData((int)(0.1 * trainData.Count()));
     TrainDataInfo[] infos     = trainData.GetInfo(configure.trainFolders.Count());
     TrainDataInfo[] testinfos = testData.GetInfo(configure.trainFolders.Count());
     logger.logStr(Utils.ToJsonString(infos, true));
     logger.logStr(Utils.ToJsonString(testinfos, true));
 }
Esempio n. 3
0
        public int Evaluate(ImageTrainDataSet trainData)
        {
            double[][] features    = trainData.GetFeature(bow, mask);
            int[]      labelIndexs = trainData.GetLabelIndexs();
            String[]   labels      = trainData.GetLabels();
            int        errorCount  = 0;

            for (int i = 0; i < trainData.Count(); i++)
            {
                //double[] feature = bow.Transform(images[i]);
                double[] answer = network.Compute(features[i]);

                int expected = labelIndexs[i];
                int actual; answer.Max(out actual);
                if (actual != expected)
                {
                    errorCount++;
                }
            }
            return(errorCount);
        }