コード例 #1
0
ファイル: TinyYOLO.cs プロジェクト: ymym3412/WinMl-TinyYOLO
        public static async Task <TinyYOLOModel> CreateTinyYOLOModel(StorageFile file)
        {
            LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);

            TinyYOLOModel model = new TinyYOLOModel();

            model.learningModel = learningModel;
            return(model);
        }
コード例 #2
0
        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 TinyYOLOModel();
                        await MLHelper.CreateModelAsync(modelFile, model);
                    }
                }

                var input = new TinyYOLOInput()
                {
                    image = ImageFeatureValue.CreateFromVideoFrame(videoFrame)
                };

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

                if (res != null)
                {
                    var data  = res.grid.GetAsVectorView().ToList();
                    var boxes = model.ComputeBoundingBoxes(data);
                    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());
            }
        }