Example #1
0
        public static async Task <TinyYOLOModelModel> CreateTinyYOLOModelModel(StorageFile file)
        {
            LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);

            TinyYOLOModelModel model = new TinyYOLOModelModel();

            model.learningModel = learningModel;
            return(model);
        }
        private async Task EvaluteImageAsync(VideoFrame videoFrame, bool isImage)
        {
            try
            {
                var startTime = DateTime.Now;
                if (model == null)
                {
                    var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/TinyYOLO.onnx"));

                    if (modelFile != null)
                    {
                        model = new TinyYOLOModelModel();
                        await MLHelper.CreateModelAsync(modelFile, model);
                    }
                }

                var input = new TinyYOLOModelModelInput()
                {
                    image = videoFrame
                };

                var res = await model.EvaluateAsync(input) as TinyYOLOModelModelOutput;

                if (res != null)
                {
                    var boxes = model.ComputeBoundingBoxes(res.grid);
                    await DrawDetectedObjectRectAsync(boxes, isImage);

                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                    {
                        previewControl.EvalutionTime = (DateTime.Now - startTime).TotalSeconds.ToString();
                    });
                }
            }
            catch (Exception ex)
            {
                await AlertHelper.ShowMessageAsync(ex.ToString());
            }
        }