Example #1
0
        public async Task TestMobilenet()
        {
            using (Mobilenet mobilenet = new Mobilenet())
            {
                await mobilenet.Init();

                var result = mobilenet.Recognize("grace_hopper.jpg")[0];
            }
        }
Example #2
0
        private void onDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            Stopwatch watch  = Stopwatch.StartNew();
            var       result = _mobilenet.Recognize(_image[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(_image[0]);
            SetMessage(resStr);
        }
Example #3
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);
        }
Example #4
0
    private void RecognizeAndUpdateText(Texture2D texture)
    {
        Stopwatch watch = Stopwatch.StartNew();

        float[] probability = _mobilenet.Recognize(texture);

        watch.Stop();

        String resStr = String.Empty;

        if (probability != null)
        {
            Mobilenet.RecognitionResult[] results = _mobilenet.SortResults(probability);
            resStr = String.Format("Object is {0} with {1}% probability. Recognition completed in {2} milliseconds.", results[0].Label, results[0].Probability * 100, watch.ElapsedMilliseconds);
        }

        _displayMessage = resStr;
    }
Example #5
0
        public void TestMobilenet()
        {
            using (Mobilenet mobilenet = new Mobilenet())
            {
                bool processCompleted = false;
                mobilenet.OnDownloadCompleted += (sender, e) =>
                {
                    var result = mobilenet.Recognize("grace_hopper.jpg")[0];

                    processCompleted = true;
                };

                mobilenet.Init();
                while (!processCompleted)
                {
                    Thread.Sleep(1000);
                }
            }
        }
Example #6
0
    private void RecognizeAndUpdateText(Texture texture)
    {
        if (_mobilenet == null)
        {
            _displayMessage = "Waiting for mobile net model to be loaded...";
            return;
        }

        Stopwatch watch = Stopwatch.StartNew();

        Mobilenet.RecognitionResult[] results = _mobilenet.Recognize(texture);
        watch.Stop();

        String resStr = String.Empty;

        if (results != null)
        {
            resStr = String.Format("Object is {0} with {1}% probability. Recognition completed in {2} milliseconds.", results[0].Label, results[0].Probability * 100, watch.ElapsedMilliseconds);
        }
        _displayMessage = resStr;
    }
Example #7
0
        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);
        }