The training status entity.
Ejemplo n.º 1
0
        // Model is retrained every time new person picture is added or deleted (see AddPersonPicture and DeletePersonPicture
        private async Task TrainModelAsync()
        {
            await faceServiceClient.TrainPersonGroupAsync(PERSON_GROUP_ID);

            Microsoft.ProjectOxford.Face.Contract.TrainingStatus trainingStatus = null;
            while (true)
            {
                trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(PERSON_GROUP_ID);

                if (trainingStatus.Status != Status.Running)
                {
                    break;
                }

                await Task.Delay(1000);
            }
        }
Ejemplo n.º 2
0
        private static async Task <Boolean> TrainingAI(string personGroupId)
        {
            Boolean trained = false;
            await faceServiceClient.TrainPersonGroupAsync(personGroupId);

            Microsoft.ProjectOxford.Face.Contract.TrainingStatus training = null;
            while (true)
            {
                training = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                if (training.Status != Microsoft.ProjectOxford.Face.Contract.Status.Running)
                {
                    break;
                }
                await Task.Delay(1000);
            }
            trained = true;
            return(trained);
        }
        public static async Task Train()
        {
            FaceAPI.FaceServiceClient _faceClient = new FaceAPI.FaceServiceClient("952a5cbdd78845948079fe7e2c61807d", "https://australiaeast.api.cognitive.microsoft.com/face/v1.0");

            string personGroupId = "myfriendsServtechAPJ";
            await _faceClient.CreatePersonGroupAsync(personGroupId, "My Friends");

            // Define Jose
            CreatePersonResult Josefriend = await _faceClient.CreatePersonAsync(
                // Id of the PersonGroup that the person belonged to
                personGroupId,
                // Name of the person
                "Jose"
                );

            // Define Jose
            CreatePersonResult Aaronfriend = await _faceClient.CreatePersonAsync(
                // Id of the PersonGroup that the person belonged to
                personGroupId,
                // Name of the person
                "Aaron"
                );

            // Directory contains image files of Anna
            const string JoseImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Jose\";

            foreach (string imagePath in Directory.GetFiles(JoseImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Anna
                    await _faceClient.AddPersonFaceAsync(
                        personGroupId, Josefriend.PersonId, s);
                }
            }
            // Do the same for Bill and Clare

            const string AaronImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Aaron\";

            foreach (string imagePath in Directory.GetFiles(AaronImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Anna
                    await _faceClient.AddPersonFaceAsync(
                        personGroupId, Aaronfriend.PersonId, s);
                }
            }
            // Do the same for Bill and Clare


            await _faceClient.TrainPersonGroupAsync(personGroupId);

            FaceAPI.Contract.TrainingStatus trainingStatus = null;
            while (true)
            {
                trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                if (trainingStatus.Status != Status.Running)
                {
                    break;
                }

                await Task.Delay(1000);
            }

            Console.Write("Training successfully completed");
        }