private async Task LoadScenariosAsync() { try { IList <VisualAlertScenarioData> scenarioList = await VisualAlertDataLoader.GetScenarioCollectionAsync(); ScenarioCollection.Clear(); ScenarioCollection.AddRange(scenarioList); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure loading alerts"); } }
private async Task LoadCurrentScenarioAsync(VisualAlertScenarioData scenario) { try { StorageFolder onnxProjectDataFolder = await VisualAlertDataLoader.GetOnnxModelStorageFolderAsync(); StorageFile scenarioFile = await onnxProjectDataFolder.GetFileAsync(scenario.FileName); this.customVisionONNXModel = await CustomVisionModel.CreateONNXModel(scenarioFile); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure loading current project"); } }
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 TrainAndSaveNewScenarioAsync(VisualAlertModelData data) { Project project = null; VisualAlertScenarioData scenario = null; try { this.newAlertProgressBar.IsIndeterminate = true; UpdateScenarioListPanel(BuilderMode.Processing); await UpdateStatus(string.Empty); // create new custom vision project UpdateProcessingStatus(data.Name, AlertCreateProcessingStatus.Creating); project = await customVisionServiceWrapper.CreateVisualAlertProjectAsync(data.Name, data.PositiveImages, data.NegativeImages); // train project UpdateProcessingStatus(data.Name, AlertCreateProcessingStatus.Training); Iteration iteration = await customVisionServiceWrapper.TrainProjectAsync(project.Id); // export project UpdateProcessingStatus(data.Name, AlertCreateProcessingStatus.Exporting); scenario = await customVisionServiceWrapper.ExportOnnxProject(project); // store project await VisualAlertDataLoader.StoreScenarioAsync(scenario); // update scenario collection await LoadScenariosAsync(); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure creating alert"); } finally { if (project != null) { await customVisionServiceWrapper.DeleteProjectAsync(project); } this.newAlertProgressBar.IsIndeterminate = false; UpdateScenarioListPanel(BuilderMode.ScenarioList, scenario); } }
private async Task DeleteScenariosAsync(IList <VisualAlertScenarioData> scenarios) { try { this.progressRing.IsActive = true; this.customVisionONNXModel = null; await VisualAlertDataLoader.DeleteScenariosAsync(scenarios); // update scenario collection await LoadScenariosAsync(); UpdateScenarioListPanel(BuilderMode.ScenarioList); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure deleting scenario(s)"); } finally { this.progressRing.IsActive = false; } }