public static IList <int> PairwiseFeatures(Document document, Mention m1, Mention m2, Dictionaries dictionaries, bool isConll)
        {
            string      speaker1 = m1.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation));
            string      speaker2 = m2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation));
            IList <int> features = new List <int>();

            features.Add(isConll ? (speaker1.Equals(speaker2) ? 1 : 0) : 0);
            features.Add(isConll ? (CorefRules.AntecedentIsMentionSpeaker(document, m2, m1, dictionaries) ? 1 : 0) : 0);
            features.Add(isConll ? (CorefRules.AntecedentIsMentionSpeaker(document, m1, m2, dictionaries) ? 1 : 0) : 0);
            features.Add(m1.HeadsAgree(m2) ? 1 : 0);
            features.Add(m1.ToString().Trim().ToLower().Equals(m2.ToString().Trim().ToLower()) ? 1 : 0);
            features.Add(FeatureExtractor.RelaxedStringMatch(m1, m2) ? 1 : 0);
            return(features);
        }
            public bool IsFace(Bitmap image)
            {
                if (image == null)
                {
                    throw new ArgumentNullException(nameof(image));
                }

                using (var windowedImageForFeatureExtraction = image.ExtractImageSectionAndResize(new Rectangle(new Point(0, 0), image.Size), new Size(_sampleWidth, _sampleHeight)))
                {
                    return(_svm.Decide(
                               FeatureExtractor.GetFor(windowedImageForFeatureExtraction, _blockSize, optionalHogPreviewImagePath: null, normaliser: _normaliser).ToArray()
                               ));
                }
            }
Example #3
0
        private void LoadSignatures()
        {
            Svc2004Loader loader = new Svc2004Loader(@"Databases\Online\SVC2004\Task2.zip", true);

            Signers = new List <Signer>(loader.EnumerateSigners());

            foreach (var signer in Signers)
            {
                for (int i = 0; i < signer.Signatures.Count; i++)
                {
                    FeatureExtractor featureExtractor = new FeatureExtractor(signer.Signatures[i]);
                    signer.Signatures[i] = featureExtractor.GetAllDerivedSVC2004Features();
                }
            }
        }
Example #4
0
        /// <inheritdoc/>
        public void Transform(Signature signature)
        {
            var extractor = new FeatureExtractor(signature);

            extractor.GetAllDerivedSVC2004Features();
        }
        public static int Main(string[] args)
        {
            DataSets sets    = new DataSets();
            DataSet  dataset = sets.LoadMall();

            string            datasetPath = dataset.Path;
            Image <Bgr, byte> background  = new Image <Bgr, byte>(Path.Combine(datasetPath, "derived images", "background.png"));

            int width  = 320; // dataset.DefaultWidth;
            int height = 240; // dataset.DefaultHeight;

            //IPerspectiveCorrector linearPerspectiveCorrector = new LinearPerspectiveCorrector(75 / 480.0, 53.0, 408 / 480.0, 143.0);

            int N = 8; //dataset.DefaultGridN;
            int M = 8; // dataset.DefaultGridM;

            FeatureExtractor extractor      = new FeatureExtractor(new IdlePerspectiveCorrector(), N, M, width, height, background);
            IDataNormalizer  dataNormalizer = new MeanAndVarianceDataNormalizer();

            IMultiRegression        regression         = new MultiRidgeRegression(1e-3);//100, 1e-5);
            CrowdCountingRegression countingRegression = new CrowdCountingRegression(extractor, dataNormalizer, regression);
            //countingRegression.CachePath = Path.Combine(dataset.Path, "cache");

            //string experimentFile = Path.Combine(datasetPath,"analysis","experiments_nullcorrection.txt");

            Stopwatch sw = new Stopwatch();

            sw.Start();
            countingRegression.Train(dataset.TrainPlusValidationInput, dataset.TrainPlusValidationOutput);
            Console.WriteLine("Training time (800 frames): {0} ms", sw.ElapsedMilliseconds);

            //PeopleCountingVideoCreator.CreateVideo(countingRegression, N, M, width, height, dataset.TestInput, dataset.TestOutput);
            MathN::Matrix <double> shouldBe = PeoplePositions.GridQuantize(dataset.TestOutput, N, M, 640, 480);

            sw.Restart();
            MathN::Matrix <double> predictions2 = countingRegression.Predict(dataset.TestInput);

            sw.Stop();
            Console.WriteLine("Parallelized prediction time (1200 frames): {0} ms", sw.ElapsedMilliseconds);

            File.WriteAllText("D:\\groundtruth.txt", shouldBe.ToMatrixString(5000, 5000), Encoding.UTF8);


            sw.Restart();
            double[] results = Evaluator.Evaluate(predictions2, shouldBe, new SquaredErrorCalculator(), new AbsoluteErrorCalculator(), new RelativeDeviationErrorCalculator());
            sw.Stop();
            Console.WriteLine("Eval time: {0} ms", sw.ElapsedMilliseconds);

            string resultString = String.Format("{0} ; {1}", countingRegression.ToString(), String.Join(" ; ", results));


            Console.WriteLine(resultString);

            MathN::Matrix <double> shouldBeTrain = PeoplePositions.GridQuantize(dataset.TrainOutput, N, M, 640, 480);

            Console.Write(shouldBeTrain.Row(0));

            //MathN::Matrix<double> predictions = countingRegression.Predict(dataset.ValidationInput);

            //countingRegression.Train(new List<string>(dataset.TrainInput.Concat(dataset.ValidationInput)),
            //    new List<IList<PointF>>(dataset.TrainOutput.Concat(dataset.ValidationOutput)));

            //MathN::Matrix<double> predictions = countingRegression.Predict(dataset.TestInput);
            //MathN::Matrix<double> shouldBe = PeoplePositions.GridQuantize(dataset.ValidationOutput, N, M, 640, 480);

            //double[] results = Evaluator.Evaluate(predictions, shouldBe, new SquaredErrorCalculator(), new AbsoluteErrorCalculator(), new RelativeDeviationErrorCalculator());
            //string resultString = String.Format("{0} ; {1}", countingRegression.ToString(), String.Join(" ; ", results));



            //object locker = new object();

            //IMultiRegression regression = new SVMRegression(1, 1e-3);
            //CrowdCountingRegression countingRegression = new CrowdCountingRegression(extractor, dataNormalizer, regression);
            //countingRegression.CachePath = Path.Combine(dataset.Path, "cache");

            ////lock (locker)
            ////{
            ////    if (File.ReadLines(experimentFile).FirstOrDefault((string s) => s.StartsWith(countingRegression.ToString() + " ;")) != null)
            ////    {
            ////        ; //already did this experiment
            ////    }
            ////}

            //Console.WriteLine(countingRegression.ToString());
            //countingRegression.Train(dataset.TrainInput, dataset.TrainOutput);

            //MathN::Matrix<double> predictions = countingRegression.Predict(dataset.ValidationInput);

            ////countingRegression.Train(new List<string>(dataset.TrainInput.Concat(dataset.ValidationInput)),
            ////    new List<IList<PointF>>(dataset.TrainOutput.Concat(dataset.ValidationOutput)));

            ////MathN::Matrix<double> predictions = countingRegression.Predict(dataset.TestInput);
            //MathN::Matrix<double> shouldBe = PeoplePositions.GridQuantize(dataset.ValidationOutput, N, M, 640, 480);

            //double[] results = Evaluator.Evaluate(predictions, shouldBe, new SquaredErrorCalculator(), new AbsoluteErrorCalculator(), new RelativeDeviationErrorCalculator());
            //string resultString = String.Format("{0} ; {1}", countingRegression.ToString(), String.Join(" ; ", results));

            //lock (locker)
            //{
            //    File.AppendAllLines(experimentFile, new string[] { resultString });
            //}
            ////    }
            ////});


            return(0);
        }
Example #6
0
 public CrowdCountingRegression(FeatureExtractor featureExtractor, IDataNormalizer dataNormalizer, IMultiRegression regression)
 {
     this.featureExtractor = featureExtractor;
     this.dataNormalizer   = dataNormalizer;
     this.innerRegression  = regression;
 }
Example #7
0
 /// <summary>
 /// Gets the topics important in this document
 /// </summary>
 /// <param name="comparisonDocuments">The comparison documents.</param>
 /// <param name="featureCount">The feature count.</param>
 /// <param name="featureExtractionType">Type of the feature extraction.</param>
 /// <returns>The features/topics important in this document.</returns>
 public string[] GetFeatures(Document[] comparisonDocuments, int featureCount, FeatureExtractionType featureExtractionType)
 {
     return(FeatureExtractor.Extract(this, comparisonDocuments, featureCount, featureExtractionType));
 }
Example #8
0
 internal FeatureImageSize(FeatureExtractor featureExtractor)
 {
     parent = featureExtractor;
 }
 internal FeatureMargin(FeatureExtractor extractor)
 {
     parent = extractor;
 }
Example #10
0
 public virtual double[] ExtractFeatureVector(string doc, out bool isEmpty)
 {
     return(FeatureExtractor.ExtractFeatureVector(doc, out isEmpty));
 }