File: main.cpp

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 (58 lines) | stat: -rw-r--r-- 2,046 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
#include "winrt/Windows.Graphics.Imaging.h"
#include "winrt/Windows.Graphics.h"
#include "winrt/Windows.Media.h"
#include "winrt/microsoft.ai.machinelearning.h"
#include "winrt/windows.foundation.collections.h"
#include "winrt/windows.foundation.h"
#include "winrt/windows.storage.h"
#include <stdio.h>
#include <windows.h>

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

using namespace winrt::Microsoft::AI::MachineLearning;
using namespace winrt::Windows::Storage;
using namespace winrt::Windows::Media;
using namespace winrt::Windows::Graphics::Imaging;

std::wstring GetModulePath()
{
    std::wstring val;
    wchar_t modulePath[MAX_PATH] = {0};
    GetModuleFileNameW((HINSTANCE)&__ImageBase, modulePath, _countof(modulePath));
    wchar_t drive[_MAX_DRIVE];
    wchar_t dir[_MAX_DIR];
    wchar_t filename[_MAX_FNAME];
    wchar_t ext[_MAX_EXT];
    _wsplitpath_s(modulePath, drive, _MAX_DRIVE, dir, _MAX_DIR, filename, _MAX_FNAME, ext, _MAX_EXT);

    val = drive;
    val += dir;

    return val;
}

int main()
{
    printf("Load squeezenet.onnx.\n");
    auto model = LearningModel::LoadFromFilePath(L"squeezenet.onnx");
    printf("Load kitten_224.png as StorageFile.\n");
    auto name = GetModulePath() + L"kitten_224.png";
    auto image = StorageFile::GetFileFromPathAsync(name).get();
    printf("Load StorageFile into Stream.\n");
    auto stream = image.OpenAsync(FileAccessMode::Read).get();
    printf("Create SoftwareBitmap from decoded Stream.\n");
    auto softwareBitmap = BitmapDecoder::CreateAsync(stream).get().GetSoftwareBitmapAsync().get();
    printf("Create VideoFrame.\n");
    auto frame = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
    printf("Create LearningModelSession.\n");
    auto session = LearningModelSession(model);
    printf("Create LearningModelBinding.\n");
    auto binding = LearningModelBinding(session);
    printf("Bind data_0.\n");
    binding.Bind(L"data_0", frame);
    printf("Evaluate.\n");
    auto results = session.Evaluate(binding, L"");
    printf("Success!\n");
    return 0;
}