private void OnEditScenarioListButtonClicked(object sender, RoutedEventArgs e) { switch (this.scenarioListView.SelectionMode) { case ListViewSelectionMode.Single: this.customVisionONNXModel = null; prevScenario = this.scenarioListView.SelectedItem as VisualAlertScenarioData; this.deleteButton.Visibility = Visibility.Visible; this.scenarioListView.SelectionMode = ListViewSelectionMode.Multiple; break; case ListViewSelectionMode.Multiple: default: this.scenarioListView.SelectionMode = ListViewSelectionMode.Single; this.deleteButton.Visibility = Visibility.Collapsed; if (prevScenario != null) { this.scenarioListView.SelectedItem = prevScenario; } else { this.scenarioListView.SelectedIndex = 0; } break; } }
public async Task initModel() { FileOpenPicker fileOpenPicker = new FileOpenPicker(); fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.FileTypeFilter.Add(".onnx"); StorageFile selectedStorageFile = await fileOpenPicker.PickSingleFileAsync(); //TemporaryFix for debug StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile sf2 = await selectedStorageFile.CopyAsync(storageFolder, selectedStorageFile.Name, NameCollisionOption.ReplaceExisting); // Load the model //StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///CustomVision.onnx")); try { _model = await CustomVisionModel.CreateFromStorageFile(selectedStorageFile); StackButtons.Visibility = Visibility.Visible; }catch (Exception ex) { StackButtons.Visibility = Visibility.Collapsed; new MessageDialog(ex.StackTrace, ex.Message).ShowAsync(); } }
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"); } }
private async Task LoadCurrentModelAsync(CustomVisionModelData currentProject) { try { this.deleteBtn.Visibility = currentProject.IsPrebuiltModel ? Visibility.Collapsed : Visibility.Visible; LoadSupportedClasses(currentProject); StorageFile modelFile = await GetModelFileAsync(currentProject); this.customVisionModel = await CustomVisionModel.CreateONNXModel(modelFile); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure loading current project"); } }
private async void OnScenarioListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { switch (this.scenarioListView.SelectionMode) { case ListViewSelectionMode.Multiple: var selectedScenarios = this.scenarioListView.SelectedItems.Cast <VisualAlertScenarioData>().ToArray(); this.deleteButton.IsEnabled = selectedScenarios != null && selectedScenarios.Any(); break; case ListViewSelectionMode.Single: default: this.customVisionONNXModel = null; if (this.scenarioListView.SelectedValue is VisualAlertScenarioData project) { await LoadCurrentScenarioAsync(project); } break; } }
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; } }
private void LoadModel() { // Check for an Onnx model exported from Custom Vision var customVisionExport = Directory.GetFiles(modelsDirectory, "*.zip").FirstOrDefault(); // If there is one, use it. if (customVisionExport != null) { var customVisionModel = new CustomVisionModel(customVisionExport); var modelConfigurator = new OnnxModelConfigurator(customVisionModel); outputParser = new OnnxOutputParser(customVisionModel); customVisionPredictionEngine = modelConfigurator.GetMlNetPredictionEngine <CustomVisionPrediction>(); } else // Otherwise default to Tiny Yolo Onnx model { var tinyYoloModel = new TinyYoloModel(Path.Combine(modelsDirectory, "TinyYolo2_model.onnx")); var modelConfigurator = new OnnxModelConfigurator(tinyYoloModel); outputParser = new OnnxOutputParser(tinyYoloModel); tinyYoloPredictionEngine = modelConfigurator.GetMlNetPredictionEngine <TinyYoloPrediction>(); } }
public async Task <CustomVisionModel> DetectPersonByImage(byte[] faceImageData) { CustomVisionModel result = null; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Prediction-key", CSPredictionKey); string url = $"{CSBaseUrl}/{CSProjectId}/image"; using (ByteArrayContent content = new ByteArrayContent(faceImageData)) { var response = await client.PostAsync(url, content); if (response.IsSuccessStatusCode) { string responseJson = await response.Content.ReadAsStringAsync(); result = Newtonsoft.Json.JsonConvert.DeserializeObject <CustomVisionModel>(responseJson); } } return(result); }
private void InitializeModel() { var modelsDirectory = Path.Combine(Environment.CurrentDirectory, @"ML\OnnxModels"); var customVisionExport = Directory.GetFiles(modelsDirectory, "*.zip").FirstOrDefault(); // custom vision model if (customVisionExport != null) { var customVisionModel = new CustomVisionModel(customVisionExport); var modelConfigurator = new OnnxModelConfigurator(customVisionModel); OutputParser = new OnnxOutputParser(customVisionModel); CustomVisionPredictionEngine = modelConfigurator.GetMlNetPredictionEngine <CustomVisionPrediction>(); } else // default model { var tinyYoloModel = new TinyYoloModel(Path.Combine(modelsDirectory, "TinyYolo2_model.onnx")); var modelConfigurator = new OnnxModelConfigurator(tinyYoloModel); OutputParser = new OnnxOutputParser(tinyYoloModel); TinyYoloPredictionEngine = modelConfigurator.GetMlNetPredictionEngine <TinyYoloPrediction>(); } }