public async Task <object> GetProjectWithImagesAndRegions(CustomVisionProject customVisionProject, Guid id, Guid iteration) { //var response = await _customVisionService.GetProjectWithImagesAndRegions(customVisionProject, id, iteration); var response = await _customVisionService.GetProjectWithImageAndAnnotations(customVisionProject, id, iteration, "customvision"); return(response); }
public async Task <SpectraProjectWithMetadata> GetProject(CustomVisionProject project, string projectId) { CustomVisionTrainingClient trainingApi = AuthenticateTraining(project.Endpoint, project.TrainingKey); var spectraProjectCollection = _database.GetCollection <SpectraProject>("spectra-projects"); var projectMetaData = spectraProjectCollection.Find(x => x.ProjectId == projectId).FirstOrDefault(); // Get all the Custom Vision projects var customVisionProject = await trainingApi.GetProjectAsync(Guid.Parse(projectId)); var mergedObject = new SpectraProjectWithMetadata { Category = projectMetaData.Category, DemoUrls = projectMetaData.DemoUrls, HeroUrl = projectMetaData.HeroUrl, Created = customVisionProject.Created, Description = customVisionProject.Description, DrModeEnabled = customVisionProject.DrModeEnabled, Id = customVisionProject.Id, LastModified = customVisionProject.LastModified, Name = customVisionProject.Name, Settings = customVisionProject.Settings, Status = customVisionProject.Status, ThumbnailUri = customVisionProject.ThumbnailUri }; return(mergedObject); }
public async Task <IList <SpectraProjectWithMetadata> > GetProjects(CustomVisionProject project) { CustomVisionTrainingClient trainingApi = AuthenticateTraining(project.Endpoint, project.TrainingKey); var spectraProjectCollection = _database.GetCollection <SpectraProject>("spectra-projects"); var projectMetaData = spectraProjectCollection.Find(project => true).ToList(); // Get all the Custom Vision projects var customVisionProjects = await trainingApi.GetProjectsAsync(); IList <SpectraProjectWithMetadata> spectraProjects = new List <SpectraProjectWithMetadata>(); IList <Project> metaDataMatches = new List <Project>(); List <SpectraProjectWithMetadata> mergedList = projectMetaData.Join( customVisionProjects, x1 => Guid.Parse(x1.ProjectId), x2 => x2.Id, (x1, x2) => new SpectraProjectWithMetadata { Category = x1.Category, DemoUrls = x1.DemoUrls, HeroUrl = x1.HeroUrl, Created = x2.Created, Description = x2.Description, DrModeEnabled = x2.DrModeEnabled, Id = x2.Id, LastModified = x2.LastModified, Name = x2.Name, Settings = x2.Settings, Status = x2.Status, ThumbnailUri = x2.ThumbnailUri }) .ToList(); return(mergedList); }
public async Task <object> GetProjectWithImageAndYoloAnnotations(CustomVisionProject customVisionProject, Guid id, Guid iteration) { var response = await _customVisionService.GetProjectWithImageAndAnnotations(customVisionProject, id, iteration, "yolo"); return(response); }
public async Task <SpectraProjectWithMetadata> GetProject(CustomVisionProject customVisionProject, string id) { return(await _customVisionService.GetProject(customVisionProject, id)); }
public async Task <IList <SpectraProjectWithMetadata> > GetProjects(CustomVisionProject customVisionProject) { return(await _customVisionService.GetProjects(customVisionProject)); }
public async Task <object> GetProjectWithImageAndAnnotations(CustomVisionProject project, Guid projectId, Guid iterationId, string convertTo) { try { // Set the training API trainingApi = AuthenticateTraining(project.Endpoint, project.TrainingKey); // Set the blob client blobClient = InitiateBlobClient(); // Set the container if it doesn't exist cloudBlobContainer = await FindOrCreateBlob(blobClient, projectId); // Get the current Project var currentProject = await trainingApi.GetProjectAsync(projectId); // Get the images and regions of the current project and iteration IList <Image> projectWithImagesAndRegions = await GetProjectWithImagesAndRegions(projectId, iterationId); // Set the file metadata var _path = Path.GetTempPath(); var _startPath = $"{_path}/Images"; var _zippedPath = $"{_path}/Zip"; string _fileName = $"{projectId}-{iterationId}-{convertTo}.zip"; // Does the Zip file already exist? bool zipUrl = DoesFileExist(_fileName, blobClient, projectId.ToString()); if (zipUrl) { CloudBlockBlob cloudZipBlob = cloudBlobContainer.GetBlockBlobReference(_fileName); return(new { project_id = projectId, project_name = currentProject.Name, image_count = projectWithImagesAndRegions.Count(), zipped_project = cloudZipBlob.Uri }); } _logger.LogInformation($"[INFO] Creating Temp Directory at {_startPath}"); // Create the Temp directory if it doesn't exist if (!Directory.Exists(_startPath)) { Directory.CreateDirectory(_startPath); } // Extract the Custom Vision regions from each individual image. bool successfullExtraction = await ExtractRegionsFromCustomVisionImage(projectWithImagesAndRegions, projectId, convertTo); // Finally, zip the directory. _logger.LogInformation($"[INFO] Zipping Project to {_startPath}{_zippedPath}"); string zippedPath = ZipAndUploadDirectory(_startPath, $"{_zippedPath}/{_fileName}"); // Upload the zip file to Azure Uri zippedFileUri = await UploadBlobToAzure(cloudBlobContainer, zippedPath, _fileName); // Clean-up DirectoryInfo dInfo = new DirectoryInfo(_startPath); foreach (FileInfo file in dInfo.GetFiles()) { file.Delete(); } dInfo = new DirectoryInfo(_zippedPath); foreach (FileInfo file in dInfo.GetFiles()) { file.Delete(); } // Generate Response var response = new { project_id = projectId, project_name = currentProject.Name, image_count = projectWithImagesAndRegions.Count(), zipped_project = zippedFileUri }; return(response); } catch (Exception e) { _logger.LogError($"[ERROR] {e.Message}"); return(new { error = e.Message }); } }