コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: vadimas/events
        private async Task LoadModelAsync()
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      () => StatusBlock.Text = $"Loading {_ourOnnxFileName} ... patience ");

            try
            {
                _stopwatch = Stopwatch.StartNew();

                var modelFile =
                    await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/{_ourOnnxFileName}"));

                _model = await OnnxModel.CreateOnnxModel(modelFile);

                _stopwatch.Stop();
                Debug.WriteLine($"Loaded {_ourOnnxFileName}: Elapsed time: {_stopwatch.ElapsedMilliseconds} ms");
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"error: {ex.Message}");
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                          () => StatusBlock.Text = $"error: {ex.Message}");

                _model = null;
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var model = new OnnxModel("/Users/vladimirlisovoi/desktop/prak1/img");

            model.EventResult += PredictionHandler;
            model.OutputEvent += OutputHandler;
            model.Work();
        }
コード例 #3
0
            public static async Task <OnnxModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
            {
                OnnxModel onnxModel = new OnnxModel();

                onnxModel.learningModel = await LearningModel.LoadFromStreamAsync(stream);

                onnxModel.session = new LearningModelSession(onnxModel.learningModel);
                onnxModel.binding = new LearningModelBinding(onnxModel.session);
                return(onnxModel);
            }
コード例 #4
0
        private void ActiveModel_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int selectedIdx = ActiveModel.SelectedIndex;

            if ((selectedIdx >= 0) && (selectedIdx < onnxFileNames.Count))
            {
                _ourOnnxFileName  = onnxFileNames[selectedIdx].Item1;
                _ourOnnxNumLables = onnxFileNames[selectedIdx].Item2;
                _model            = null; // Will force reloading of model.
            }
        }
コード例 #5
0
ファイル: DataStoreService.cs プロジェクト: chanhe03/SQL
        public void InsertModelFromUrl(string url)
        {
            using var webClient = new WebClient();
            byte[] modelBytes = webClient.DownloadData(url);
            using var dbContext = new DatabaseContext(_sqlConnectionString);
            var query = $"insert into {MODELTABLENAME} ([description], [data]) values ('Onnx Model',?)";
            var model = new OnnxModel {
                Description = "Onnx Model", Data = modelBytes
            };

            dbContext.Add <OnnxModel>(model);
            dbContext.SaveChanges();
        }
コード例 #6
0
        public void TestOnnxModelNotDisposal()
        {
            // Declare the path the tested ONNX model file.
            var modelFile = Path.Combine(Directory.GetCurrentDirectory(), "zipmap", "TestZipMapInt64.onnx");

            // Create ONNX model from the model file.
            var onnxModel = new OnnxModel(modelFile);

            // Check if a temporal file is crated for storing the byte[].
            Assert.True(File.Exists(onnxModel.ModelFile));

            // Don't delete the temporal file!
            onnxModel.Dispose();

            // Make sure the temporal file still exists.
            Assert.True(File.Exists(onnxModel.ModelFile));
        }
コード例 #7
0
        public void TestOnnxModelDisposal()
        {
            // Create a ONNX model as a byte[].
            var modelFile    = Path.Combine(Directory.GetCurrentDirectory(), "zipmap", "TestZipMapInt64.onnx");
            var modelInBytes = File.ReadAllBytes(modelFile);

            // Create ONNX model from the byte[].
            var onnxModel = OnnxModel.CreateFromBytes(modelInBytes, ML);

            // Check if a temporal file is crated for storing the byte[].
            Assert.True(File.Exists(onnxModel.ModelStream.Name));

            // Delete the temporal file.
            onnxModel.Dispose();
            // Make sure the temporal file is deleted.
            Assert.False(File.Exists(onnxModel.ModelStream.Name));
        }
コード例 #8
0
            public static async Task <OnnxModel> CreateOnnxModel(StorageFile file)
            {
                LearningModelPreview learningModel = null;

                try
                {
                    learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);
                }
                catch (Exception e)
                {
                    var exceptionStr = e.ToString();
                    System.Console.WriteLine(exceptionStr);
                    throw e;
                }
                OnnxModel model = new OnnxModel();

                learningModel.InferencingOptions.PreferredDeviceKind          = LearningModelDeviceKindPreview.LearningDeviceGpu;
                learningModel.InferencingOptions.ReclaimMemoryAfterEvaluation = true;
                model.learningModel = learningModel;
                return(model);
            }
コード例 #9
0
        private void StartCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            this.isWorking = true;

            resultcollection.Clear();
            imagecollection.Clear();
            classcollection.Clear();
            ThreadPool.QueueUserWorkItem(new WaitCallback(param =>
            {
                foreach (string path in Directory.GetFiles(selected_dir, "*.jpg"))
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        imagecollection.Add(new Image(path));
                    }));
                }
            }));

            mdl              = new OnnxModel(selected_dir);
            mdl.EventResult += OutputHandler;
            mdl.Work();
        }