public async Task <VisualAlertScenarioData> ExportOnnxProject(Project project) { // get latest iteration IList <Iteration> iterations = await trainingApi.GetIterationsAsync(project.Id); Iteration latestTrainedIteration = iterations.Where(i => i.Status == "Completed").OrderByDescending(i => i.TrainedAt.Value).FirstOrDefault(); // export iteration - get download url Export exportProject = null; if (latestTrainedIteration != null && latestTrainedIteration.Exportable) { // get project's download Url for the particular platform Windows (ONNX) model exportProject = await CustomVisionServiceHelper.ExportIteration(trainingApi, project.Id, latestTrainedIteration.Id); } if (string.IsNullOrEmpty(exportProject?.DownloadUri)) { throw new ArgumentNullException("Download Uri"); } // download onnx model Guid newModelId = Guid.NewGuid(); StorageFolder onnxProjectDataFolder = await VisualAlertDataLoader.GetOnnxModelStorageFolderAsync(); StorageFile file = await onnxProjectDataFolder.CreateFileAsync($"{newModelId}.onnx", CreationCollisionOption.ReplaceExisting); bool success = await Util.UnzipModelFileAsync(exportProject.DownloadUri, file); if (!success) { await file.DeleteAsync(); return(null); } return(new VisualAlertScenarioData { Id = newModelId, Name = project.Name, ExportDate = DateTime.UtcNow, FileName = file.Name, FilePath = file.Path }); }
private async Task ExportProject(Platform currentPlatform) { CustomVisionProjectType customVisionProjectType = CustomVisionServiceHelper.ObjectDetectionDomainGuidList.Contains(this.CurrentProject.Settings.DomainId) ? CustomVisionProjectType.ObjectDetection : CustomVisionProjectType.Classification; bool success = false; try { this.shareStatusTextBlock.Text = "Exporting model..."; this.shareStatusPanelDescription.Visibility = Visibility.Collapsed; this.closeFlyoutBtn.Visibility = Visibility.Visible; this.projectShareProgressRing.IsActive = true; // get latest iteration of the project if (this.LatestTrainedIteration == null) { await this.LoadLatestIterationInCurrentProject(); } if (LatestTrainedIteration != null && LatestTrainedIteration.Exportable) { // get project's download Url for the particular platform // Windows (ONNX) model: export latest version of the ONNX model (1.2) Export exportProject = await CustomVisionServiceHelper.ExportIteration(trainingApi, this.CurrentProject.Id, LatestTrainedIteration.Id); success = await ExportOnnxProject(exportProject, customVisionProjectType); } } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "We couldn't export the model at this time."); } finally { this.projectShareProgressRing.IsActive = false; this.closeFlyoutBtn.Visibility = Visibility.Collapsed; this.shareStatusTextBlock.Text = success ? "The project was exported successfully." : "Something went wrong and we couldn't export the model. Sorry :("; } }