onnxruntime/csharp/test/Microsoft.AI.MachineLearning.Tests/main.cpp
Sheil Kumar fdb4a3a2e8
Add cppwinrt and cswinrt tests in windowsai nuget pipeline (#4381)
* build e2e cppwinrt tests

* add use nuget task

* make all referenced to package version prop/target-ified

* remove dupe props/targets reference

* work around project.assets.json error by deleting it

* powershell test invocation

* switch to batch script

* print debug info

* update x86->x64

* stdio.h

* pushd/popd

* add csharp tests

* package.config -> packages.config

* typo

* x86 -> anycpu

* debug is default

* add test path

* update csproj as well

* debug

* really replace all package versions

* debug output

* really use [PackageVersion]

* sleep intead of converting async operation to task and waiting

* dont close software bitmap

* switch to powershell script

* remove binding check

* continue on failure

* continuse on error action

* continueOnError and errorActionPreference

* tabbing

Co-authored-by: Sheil Kumar <sheilk@microsoft.com>
2020-07-07 09:36:42 -07:00

56 lines
No EOL
1.9 KiB
C++

#include <stdio.h>
#include "winrt/microsoft.ai.machinelearning.h"
#include "winrt/windows.storage.h"
#include "winrt/windows.foundation.h"
#include "winrt/windows.foundation.collections.h"
#include "winrt/Windows.Graphics.h"
#include "winrt/Windows.Graphics.Imaging.h"
#include "winrt/Windows.Media.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;
}