Example #1
0
    private async Task LoadModelAsync()
    {
        StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(fileName));

        _model = new ObjectDetection(new string[] { "AceOfHearts" });
        await _model.Init(modelFile);
    }
Example #2
0
        private async void InitModel()
        {
            _objectDetection = new ObjectDetection();
            var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/model.onnx"));

            await _objectDetection.Init(modelFile);
        }
        private async void InitONNX()
        {
            var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Model/{ModelFilename}"));

            objectDetection = new ObjectDetection(new List <string>()
            {
                "Mask", "No Mask"
            });
            await objectDetection.Init(modelFile);
        }
Example #4
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            StorageFile modelFile =
                await StorageFile.GetFileFromApplicationUriAsync(
                    new Uri("ms-appx:///Assets/model.onnx"));

            string labelsString =
                await File.ReadAllTextAsync("Assets/labels.txt");

            var labels = labelsString.Split("\r\n");

            model = new ObjectDetection(labels);
            await model.Init(modelFile);
        }
Example #5
0
    async void Start()
    {
        try
        {
            // Get components
            _user = GetComponent <UserInput>();

            // Load model
            StatusBlock.text = $"Loading ONNX ...";
#if ENABLE_WINMD_SUPPORT
            _file = await Package.Current.InstalledLocation.GetFileAsync("model.onnx");

            _dnnModel = new ObjectDetection(new[] { "Arc Mouse", "Surface Book", "Surface Pro" });
            await _dnnModel.Init(_file);

            StatusBlock.text = $"Loaded model. Starting camera...";


            // Configure camera to return frames fitting the model input size
            _mediaCapturer = new MediaCapturer();
            await _mediaCapturer.StartCapturing(416, 416);

            StatusBlock.text = $"Camera started. Running!";

            // Run processing loop in separate parallel Task
            _isRunning = true;
            await Task.Run(async() =>
            {
                while (_isRunning)
                {
                    using (var videoFrame = _mediaCapturer.GetLatestFrame())
                    {
                        if (videoFrame != null)
                        {
                            await EvaluateFrame(videoFrame);
                        }
                    }
                }
            });
#endif
        }
        catch (Exception ex)
        {
#if ENABLE_WINMD_SUPPORT
            string filename = _file != null ? _file.Name : "nofile";
            StatusBlock.text = $"File: {filename}, Error init: {ex.Message}";
#endif
            Debug.LogError(ex);
        }
    }
    // Use this for initialization
    void Start()
    {
#if UNITY_UWP
        Task.Run(async() =>
        {
            var modelFile = await
                            StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appx:///Assets/LearningModel.onnx"));
            _objectDetection = new ObjectDetection(new List <string>(new[] { "AngelPie", "ChocoPie" }), 20, .3f, .45f);
            await _objectDetection.Init(modelFile);

            IsReady = true;
        });
#endif
    }
    // Use this for initialization
    void Start()
    {
#if UNITY_UWP
        Task.Run(async() =>
        {
            var modelFile = await
                            StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appx:///Assets/LearningModel.onnx"));
            //学習させた内容に合わせてタグは適宜変更する
            _objectDetection = new ObjectDetection(new List <string>(new[] { "curry", "gyoza", "meat", "pizza", "sushi" }), 20, .3f, .45f);
            await _objectDetection.Init(modelFile);

            IsReady = true;
        });
#endif
    }
Example #8
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var maximumObjects = 5; //maximum number of Objects that can be detected

            StorageFile labelsFile =
                await StorageFile.GetFileFromApplicationUriAsync(
                    new Uri("ms-appx:///Assets/labels.txt"));

            IList <string> data = await FileIO.ReadLinesAsync(labelsFile);

            List <string> labelsList = data.ToList();

            od = new ObjectDetection(labelsList, maximumObjects);
            StorageFile modelFile =
                await StorageFile.GetFileFromApplicationUriAsync(
                    new Uri("ms-appx:///Assets/model.onnx"));

            await od.Init(modelFile);
        }
Example #9
0
        public async Task <string> ProcessSoftwareBitmap(SoftwareBitmap bitmap, SoftwareBitmap originalBitmap, MainPage mainPage)
        {
            string ret = null;

            if (!Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.Media.VideoFrame", "CreateWithSoftwareBitmap"))
            {
                return("hi\n");
            }
            //Convert SoftwareBitmap  into VideoFrame
            using (VideoFrame frame = VideoFrame.CreateWithSoftwareBitmap(bitmap))
            {
                try
                {
                    if (file == null)
                    {
                        file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AIModel/model.onnx"));

                        await objectDetection.Init(file);
                    }

                    var output = await objectDetection.PredictImageAsync(frame);

                    if (output != null)
                    {
                        mainPage.UpdateTextbox("output is not null.\n");
                        ret = await UpdateResult(output, mainPage, bitmap, originalBitmap);
                    }
                    else
                    {
                        mainPage.UpdateTextbox("No result.\n");
                    }
                }
                catch (Exception e)
                {
                    string s = e.Message;
                    mainPage.ShowMessagePopup(e.Message);
                }
            }

            return(ret);
        }
Example #10
0
 private async void InitModel()
 {
     _objectDetection = new ObjectDetection();
     await _objectDetection.Init();
 }
Example #11
0
        async Task setupAi()
        {
            var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///model.onnx"));

            await detection.Init(file);
        }
Example #12
0
        private async Task init_onnx()
        {
            StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AI/model.onnx"));

            await objectDetection.Init(file);
        }