using Microsoft.Cognitive.CustomVision.Prediction; using Microsoft.Cognitive.CustomVision.Training; using Microsoft.Cognitive.CustomVision.Training.Models; ... using System; using System.Linq; using System.Threading.Tasks; ... namespace VisionRacing.PredictingRacingImages { class Program { ... private static async Task WorkOnProject(TrainingApi trainingApi, PredictionEndpoint predictionEndpoint, string name) { var option = " "; while (!string.IsNullOrEmpty(option)) { Console.Clear(); var project = await GetOrCreateProject(trainingApi, name); Console.WriteLine($" --- Project {project.Name} ---"); Console.WriteLine(); await ListProjectTags(trainingApi, project.Id); Console.WriteLine("Type an option number:"); Console.WriteLine(" 1: Predict Karting images"); Console.WriteLine(" 2: Predict F1 images"); Console.WriteLine(" 3: Predict MotoGP images"); Console.WriteLine(" 4: Predict Rally images"); Console.WriteLine(" 5: Predict Test images"); Console.WriteLine(); Console.WriteLine($"Press any other key to exit project {name}"); option = Console.ReadLine(); switch (option) { case "1": await StartPrediction(predictionEndpoint, project.Id, ImageType.Karting); break; case "2": await StartPrediction(predictionEndpoint, project.Id, ImageType.F1); break; case "3": await StartPrediction(predictionEndpoint, project.Id, ImageType.MotoGP); break; case "4": await StartPrediction(predictionEndpoint, project.Id, ImageType.Rally); break; case "5": await StartPrediction(predictionEndpoint, project.Id, ImageType.Test); break; default: option = string.Empty; break; } } } ... private static async Task<Project> GetOrCreateProject(TrainingApi trainingApi, string name) { var projects = await trainingApi.GetProjectsAsync(); var project = projects.Where(p => p.Name.ToUpper() == name.ToUpper()).SingleOrDefault(); if (project == null) { project = await trainingApi.CreateProjectAsync(name); } return project; } ... private static async Task ListProjectTags(TrainingApi trainingApi, Guid projectId) { var tagList = await trainingApi.GetTagsAsync(projectId); if (tagList.Tags.Any()) { Console.WriteLine($"Tags: {Environment.NewLine}{string.Join(Environment.NewLine, tagList.Tags.Select(t => $" {t.Name} (Image count: {t.ImageCount})"))}{Environment.NewLine}"); } else { Console.WriteLine($"No tags yet...{Environment.NewLine}"); } } ... private enum ImageType { F1, Karting, MotoGP, Rally, Test } } }