// Use this for initialization void Start() { bool loaded = Emgu.TF.Lite.TfLiteInvoke.CheckLibraryLoaded(); _mobilenet = new Emgu.TF.Lite.Models.Mobilenet(); _liveCameraView = false; /* * WebCamDevice[] devices = WebCamTexture.devices; * cameraCount = devices.Length; * * if (cameraCount == 0) * { * _liveCameraView = false; * } * else * { * _liveCameraView = true; * webcamTexture = new WebCamTexture(devices[0].name); * * baseRotation = transform.rotation; * webcamTexture.Play(); * //data = new Color32[webcamTexture.width * webcamTexture.height]; * }*/ DisplayText.text = "Downloading model, please wait..."; StartCoroutine(_mobilenet.Init()); }
// Use this for initialization IEnumerator Start() { bool tryUseCamera = true; bool loaded = Emgu.TF.Lite.TfLiteInvoke.CheckLibraryLoaded(); _mobilenet = new Emgu.TF.Lite.Models.Mobilenet(); WebCamDevice[] devices = WebCamTexture.devices; if (tryUseCamera && devices.Length != 0) { yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam)); if (Application.HasUserAuthorization(UserAuthorization.WebCam)) { UnityEngine.Debug.Log("webcam use authorized"); _webcamTexture = new WebCamTexture(devices[0].name); RawImage image = this.GetComponent <RawImage>(); image.texture = _webcamTexture; _webcamTexture.Play(); } } DisplayText.text = "Downloading model, please wait..."; StartCoroutine(_mobilenet.Init()); }
public async Task TestMobilenet() { using (Mobilenet mobilenet = new Mobilenet()) { await mobilenet.Init(); var result = mobilenet.Recognize("grace_hopper.jpg")[0]; } }
private async void OnButtonClicked(Object sender, EventArgs args) { SetMessage("Please wait while the Mobilenet Model is being downloaded..."); await _mobilenet.Init(); SetImage(); String[] imageFiles = await LoadImages(new string[] { "space_shuttle.jpg" }); Stopwatch watch = Stopwatch.StartNew(); var result = _mobilenet.Recognize(imageFiles[0]); watch.Stop(); String resStr = String.Format("Object is {0} with {1}% probability. Recognition completed in {2} milliseconds.", result[0].Label, result[0].Probability * 100, watch.ElapsedMilliseconds); SetImage(imageFiles[0]); SetMessage(resStr); }
// Use this for initialization void Start() { bool loaded = Emgu.TF.Lite.TfLiteInvoke.CheckLibraryLoaded(); _mobilenet = new Emgu.TF.Lite.Models.Mobilenet(); WebCamDevice[] devices = WebCamTexture.devices; if (false) //if (devices.Length != 0) { _webcamTexture = new WebCamTexture(devices[0].name); baseRotation = transform.rotation; _webcamTexture.Play(); } DisplayText.text = "Downloading model, please wait..."; StartCoroutine(_mobilenet.Init()); }
public void TestMobilenet() { using (Mobilenet mobilenet = new Mobilenet()) { bool processCompleted = false; mobilenet.OnDownloadCompleted += (sender, e) => { var result = mobilenet.MostLikely("grace_hopper.jpg"); processCompleted = true; }; mobilenet.Init(); while (!processCompleted) { Thread.Sleep(1000); } } }
public MobilenetPage() : base() { var button = this.GetButton(); button.Text = "Perform Image Classification"; button.Clicked += OnButtonClicked; _mobilenet = new Mobilenet(); OnImagesLoaded += (sender, image) => { SetMessage("Please wait..."); SetImage(); _image = image; #if !DEBUG try #endif { if (_mobilenet.Imported) { onDownloadCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(null, false, null)); } else { SetMessage("Please wait while the Mobilenet Model is being downloaded..."); _mobilenet.OnDownloadProgressChanged += onDownloadProgressChanged; _mobilenet.OnDownloadCompleted += onDownloadCompleted; _mobilenet.Init(); } } #if !DEBUG catch (Exception e) { String msg = e.Message.Replace(System.Environment.NewLine, " "); SetMessage(msg); } #endif }; }
private async void OnButtonClicked(Object sender, EventArgs args) { SetImage(); String[] imageFiles = await LoadImages(new string[] { "space_shuttle.jpg" }); //handle user cancel if (imageFiles == null || (imageFiles.Length > 0 && imageFiles[0] == null)) { SetMessage(""); return; } SetMessage("Please wait while the Mobilenet Model is being downloaded..."); if (_mobilenet == null) { _mobilenet = new Mobilenet(); _mobilenet.OnDownloadProgressChanged += onDownloadProgressChanged; } await _mobilenet.Init(); var picker = this.Picker; if (picker.SelectedIndex > 0) { String selectedBackend = picker.SelectedItem.ToString(); if (selectedBackend.Equals("NNAPI")) { try { Status addNNApiDelegateStatus = _mobilenet.Interpreter.ModifyGraphWithDelegate(TfLiteInvoke.DefaultNnApiDelegate); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e); throw; } } else if (selectedBackend.Equals("GPU")) { try { Status addGpuDelegateStatus = _mobilenet.Interpreter.ModifyGraphWithDelegate(TfLiteInvoke.DefaultGpuDelegateV2); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e); throw; } } } Stopwatch watch = Stopwatch.StartNew(); var result = _mobilenet.Recognize(imageFiles[0]); watch.Stop(); String resStr = String.Format("Object is {0} with {1}% probability. Recognition completed in {2} milliseconds.", result[0].Label, result[0].Probability * 100, watch.ElapsedMilliseconds); SetImage(imageFiles[0]); SetMessage(resStr); }