... using Microsoft.Cognitive.CustomVision.Training; using Microsoft.Cognitive.CustomVision.Training.Models; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; ... namespace VisionRacing.TrainingRacingImages { class Program { ... private static async Task CreateTagImages(TrainingApi trainingApi, Guid projectId, ImageType imageType) { Console.Clear(); var imageTag = await GetOrCreateTag(trainingApi, projectId, imageType.ToString()); var racingTag = await GetOrCreateTag(trainingApi, projectId, "Racing"); var imageTypeCount = GetImageCountPerImageType(imageType); if (imageTag.ImageCount != imageTypeCount) { Console.WriteLine($"{imageType} images creation in progress..."); var images = new List<ImageUrlCreateEntry>(); for (int i = 1; i <= imageTypeCount; i++) { images.Add(new ImageUrlCreateEntry($"https://github.com/vivienchevallier/Article-AzureCognitive.Vision-Racing/raw/master/Images/{imageType}/{imageType}%20({i}).jpg")); } var tags = new List<Guid>() { imageTag.Id, racingTag.Id }; var response = await trainingApi.CreateImagesFromUrlsAsync(projectId, new ImageUrlCreateBatch(images, tags)); Console.Clear(); Console.WriteLine($"{imageType} images successfully created."); } else { Console.WriteLine($"{imageType} images already created."); } Console.WriteLine(); Console.WriteLine("Press any key to continue"); Console.ReadLine(); } 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; default: return 0; } } ... private static async Task<Tag> GetOrCreateTag(TrainingApi trainingApi, Guid projectId, string name) { var tagList = await trainingApi.GetTagsAsync(projectId); var tag = tagList.Tags.Where(t => t.Name.ToUpper() == name.ToUpper()).SingleOrDefault(); if (tag == null) { tag = await trainingApi.CreateTagAsync(projectId, name); } return tag; } ... } }