using Microsoft.Cognitive.CustomVision.Prediction; ... using System; using System.Linq; using System.Threading.Tasks; using ImageUrl = Microsoft.Cognitive.CustomVision.Prediction.Models.ImageUrl; namespace VisionRacing.PredictingRacingImages { class Program { ... private static int GetImageCountPerImageType(ImageType imageType) { switch (imageType) { case ImageType.F1: return 7; case ImageType.Karting: return 35; case ImageType.MotoGP: return 7; case ImageType.Rally: return 6; case ImageType.Test: return 10; default: return 0; } } private static string GetImageDescriptionPerImageTypeAndNumber(ImageType imageType, int imageNumber) { switch (imageType) { case ImageType.Test: switch (imageNumber) { case 1: case 2: return "Solo kart racer on track"; case 3: case 7: case 10: return "Multiple kart racers on track"; case 4: case 9: return "Solo kart racer on pre-grid"; case 5: return "Kart racers on a podium"; case 6: return "A tent in a karting paddock"; case 8: return "A racing helmet"; default: return string.Empty; } case ImageType.F1: case ImageType.Karting: case ImageType.MotoGP: case ImageType.Rally: default: return string.Empty; } } ... private static async Task StartPrediction(PredictionEndpoint predictionEndpoint, Guid projectId, ImageType imageType) { var imageTypeCount = GetImageCountPerImageType(imageType); for (int i = 1; i <= imageTypeCount; i++) { Console.Clear(); Console.WriteLine($"Image {imageType} {i}/{imageTypeCount} prediction in progress..."); var imageDescription = GetImageDescriptionPerImageTypeAndNumber(imageType, i); if (!string.IsNullOrEmpty(imageDescription)) { Console.WriteLine(); Console.WriteLine($"Description: {imageDescription}"); } var imagePredictionResult = await predictionEndpoint.PredictImageUrlWithNoStoreAsync(projectId, new ImageUrl($"https://github.com/vivienchevallier/Article-AzureCognitive.Vision-Racing/raw/master/Images/{imageType}/{imageType}%20({i}).jpg")); Console.Clear(); if (imagePredictionResult.Predictions.Any()) { Console.WriteLine($"Image {imageType} {i}/{imageTypeCount}: {imageDescription}{Environment.NewLine}{string.Join(Environment.NewLine, imagePredictionResult.Predictions.Select(p => $" {p.Tag}: {p.Probability:P1}"))}{Environment.NewLine}"); } else { Console.WriteLine($"Image {imageType} {i}/{imageTypeCount}: no predictions yet...{Environment.NewLine}"); } if (i < imageTypeCount) { Console.WriteLine("Press enter to predict next image or any other key to stop predictions"); if (Console.ReadKey().Key != ConsoleKey.Enter) { break; } } else { Console.WriteLine("All images predicted... Press any key to continue"); Console.ReadLine(); } } } ... } }