public void Train() { videoGrab.Pause(); var images = trainDataDAL.GetImages().ToList(); labelMap = new LabelMap(trainDataDAL.GetLabelMap()); var faceEmbeddings = images .Select(img => (labelMap.Map[img.Label], detectionModule.GetFaceEmbedding(img.Image))) .Where(tuple => tuple.Item2 != null) .ToList(); if (faceEmbeddings != null && faceEmbeddings.Any()) { recognitionModule.Train(faceEmbeddings, trainedModel, "PersonalModels//First//"); } var faceEmbeddingsSecond = images .Select(img => (labelMap.Map[img.Label], detectionModule.GetFaceEmbeddingSecond(img.Image))) .Where(tuple => tuple.Item2 != null) .ToList(); if (faceEmbeddings != null && faceEmbeddings.Any()) { recognitionModule.Train(faceEmbeddingsSecond, trainedSecondModel, "PersonalModels//Second//"); } _hasTrainedModel = false; //force reloading the new model before start recognition videoGrab.Start(); }
private static void RunOptions(FaceRecognitionParams facePars) { var images = GetImages(facePars.DataSet).ToList(); var detectionModule = new DetectionModule(facePars); var faces = detectionModule .GetFaces(images) .Select(f => (GetPersonName(f.Item1), f.Item2)) .ToList(); var labelMap = new LabelMap(faces.Select(f => f.Item1).Distinct()); var labeledFaces = faces.Select(f => (labelMap.Map[f.Item1], f.Item2)); var testImages = GetImages(facePars.TestSet).ToList(); var recognitionModule = new FaceRecognitionModule(); recognitionModule.Train(labeledFaces.ToList(), facePars.Embeddings); foreach (var(name, bytes) in testImages) { var testImg = detectionModule.ProcessImage(bytes); var prediction = recognitionModule.Predict(testImg); Console.WriteLine($"Img name : {name} Prediction: {labelMap.ReverseMap[prediction.Label]}, Dist : {prediction.Distance}"); } }