Example #1
0
        public static AdaBoostRespons[] executeAdaBoost(Matrix[] integralImages, Feature[] allFeatures, Matrix isFaceList, int nrNegative, int nrWeakClassifiers)
        {
            FeatureType[] featureTypes =
                (from feature in allFeatures
                 select feature.type).Distinct().ToArray();

            InitiateFeatureValues(integralImages, allFeatures, featureTypes);

            AdaBoostRespons[] adaBoostRespons = new AdaBoostRespons[nrWeakClassifiers];

            Matrix weights = getInitializedWeights(isFaceList.nr_vals - nrNegative, nrNegative);

            for (int t = 0; t < nrWeakClassifiers; t++)
            {
                weights = weights / weights.getSum();

                FeatureIndex bestFeatureIndex = new FeatureIndex(FeatureType.type1, int.MinValue);
                WeakClassifier bestClassifier = new WeakClassifier(int.MaxValue, double.MaxValue, double.MaxValue);

                foreach (FeatureType featureType in featureTypes)
                {
                    Matrix allFeatureValuesOfSameType = Matrix.DeserializeFromXML("FeatureValues_" + featureType.ToString() + ".xml");

                    for (int j = 1; j <= allFeatureValuesOfSameType.nr_rows; j++)
                    {
                        WeakClassifier weakClassifier = learnWeakClassifier(allFeatureValuesOfSameType, weights, isFaceList, j);
                        if (weakClassifier.error < bestClassifier.error)
                        {
                            bestClassifier = weakClassifier;
                            bestFeatureIndex.featureType = featureType;
                            bestFeatureIndex.j = j;
                        }
                    }
                }

                double beta = bestClassifier.error / (1 - bestClassifier.error);
                double alpha = Math.Log(1 / beta);

                Matrix featureValuesOfSameType = Matrix.DeserializeFromXML("FeatureValues_" + bestFeatureIndex.featureType.ToString() + ".xml");
                for (int i = 1; i <= featureValuesOfSameType.nr_cols; i++)
                {
                    int classification = getWeakClassification(featureValuesOfSameType[i, bestFeatureIndex.j], bestClassifier.parity, bestClassifier.threshold);
                    weights[i] = Math.Abs(classification - isFaceList[i]) == 0 ? weights[i] * beta : weights[i];
                }

                adaBoostRespons[t] = new AdaBoostRespons(bestClassifier, alpha, bestFeatureIndex);
            }

            return adaBoostRespons;
        }
Example #2
0
 public AdaBoostRespons(WeakClassifier weakClassifier, double alpha, FeatureIndex featureIndex)
 {
     this.weakClassifier = weakClassifier;
     this.alpha = alpha;
     this.featureIndex = featureIndex;
 }