File: Program.cs

package info (click to toggle)
onnxruntime 1.21.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 333,732 kB
  • sloc: cpp: 3,153,079; python: 179,219; ansic: 109,131; asm: 37,791; cs: 34,424; perl: 13,070; java: 11,047; javascript: 6,330; pascal: 4,126; sh: 3,277; xml: 598; objc: 281; makefile: 59
file content (70 lines) | stat: -rw-r--r-- 3,136 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;

namespace ConsoleApp17
{
    class Program
    {
        static void PerformInference(Windows.Media.VideoFrame frame)
        {
            Console.WriteLine("Load squeezenet.onnx.");
            using (var model = Microsoft.AI.MachineLearning.LearningModel.LoadFromFilePath("squeezenet.onnx"))
            {
                Console.WriteLine("Create LearningModelSession.");
                using (var session = new Microsoft.AI.MachineLearning.LearningModelSession(model))
                {
                    Console.WriteLine("Create LearningModelBinding.");
                    var binding = new Microsoft.AI.MachineLearning.LearningModelBinding(session);
                    Console.WriteLine("Bind data_0.");
                    binding.Bind("data_0", frame);
                    Console.WriteLine("Evaluate.");
                    var results = session.Evaluate(binding, "");
                }
                Console.WriteLine("Success!\n");
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Load kitten_224.png as StorageFile.");
            var name = AppDomain.CurrentDomain.BaseDirectory + "kitten_224.png";
            var getFileFromPathTask = Windows.Storage.StorageFile.GetFileFromPathAsync(name);
            getFileFromPathTask.AsTask()
                .ContinueWith<Windows.Storage.Streams.IRandomAccessStreamWithContentType>(
                    (task) =>
                    {
                        var image = task.Result;
                        Console.WriteLine("Load StorageFile into Stream.");
                        var stream_task = image.OpenReadAsync();
                        return stream_task.AsTask().Result;
                    })
                .ContinueWith<Windows.Graphics.Imaging.BitmapDecoder>(
                    (task) =>
                    {
                        using (var stream = task.Result)
                        {
                            Console.WriteLine("Create SoftwareBitmap from decoded Stream.");
                            var decoder_task = Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                            return decoder_task.AsTask().Result;
                        }
                    })
                .ContinueWith<Windows.Graphics.Imaging.SoftwareBitmap>(
                    (task) =>
                    {
                        var decoder = task.Result;
                        var software_bitmap_task = decoder.GetSoftwareBitmapAsync();
                        return software_bitmap_task.AsTask().Result;
                    })
                .ContinueWith(
                    (task) =>
                    {
                        using (var software_bitmap = task.Result)
                        {
                            Console.WriteLine("Create VideoFrame.");
                            var frame = Windows.Media.VideoFrame.CreateWithSoftwareBitmap(software_bitmap);
                            PerformInference(frame);
                        }
                    })
                .Wait();
                    
        }
    }
}