示例#1
0
        public void EnsureTrained()
        {
            if (File.Exists(trainedModel))
            {
                Console.WriteLine("[INFO] Model exists, loading");
                recognitionModule = new FaceRecognitionModule(); // prevent crashes during repeatable load
                recognitionModule.Load(trainedModel);
            }
            else
            {
                Console.WriteLine("[INFO] Model doesn't exist, started training");
                Train();
            }

            if (File.Exists(trainedSecondModel))
            {
                Console.WriteLine("[INFO] Second Model exists, loading");
                recognitionModuleSecond.Load(trainedSecondModel);
            }
            else
            {
                Console.WriteLine("[INFO] Model doesn't exist, started training");
                Train();
            }
            _hasTrainedModel = true;
        }
示例#2
0
        public double PredictPersonConfidenceFirst(Mat mat, int personId)
        {
            if (!_hasTrainedModel)
            {
                EnsureTrained();
            }
            var faceEmb = detectionModule.GetFaceEmbedding(mat);

            if (faceEmb == null)
            {
                return(0);
            }
            var recognitionPersonModule   = new FaceRecognitionModule();
            var personalModelFileFilePath = String.Format("PersonalModels//First//{0}.trained", personId);

            if (File.Exists(personalModelFileFilePath))
            {
                Console.WriteLine("[INFO] Second Model exists, loading");
                recognitionPersonModule.Load(personalModelFileFilePath);
            }
            else
            {
                Console.WriteLine("[INFO] Model doesn't exist, started training");
                Train();
            }
            var prediction = recognitionPersonModule.Predict(faceEmb);

            return(prediction.Distance);
        }